Class: Gemgento::API::SOAP::Authnetcim::Payment
- Inherits:
-
Object
- Object
- Gemgento::API::SOAP::Authnetcim::Payment
- Defined in:
- lib/gemgento/api/soap/authnetcim/payment.rb
Class Method Summary collapse
-
.create(saved_credit_card) ⇒ Gemgento::MagentoResponse
Create a new saved payment method for a customer.
-
.destroy(customer_id, payment_profile_id) ⇒ Gemgento::MagentoResponse
Destroy a saved payment method for a customer.
-
.fetch(user) ⇒ Void
Fetch and sync all user saved credit cards.
-
.list(customer_id) ⇒ Gemgento::MagentoResponse
Get a list of saved payment methods for customer.
Class Method Details
.create(saved_credit_card) ⇒ Gemgento::MagentoResponse
Create a new saved payment method for a customer
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gemgento/api/soap/authnetcim/payment.rb', line 32 def self.create(saved_credit_card) = { customer_id: saved_credit_card.user.magento_id, payment: { firstname: saved_credit_card.address.first_name, lastname: saved_credit_card.address.last_name, address1: saved_credit_card.address.street, city: saved_credit_card.address.city, state: saved_credit_card.address.region.magento_id, zip: saved_credit_card.address.postcode, country: saved_credit_card.address.country.iso2_code, 'cc_type' => saved_credit_card.cc_type, 'cc_number' => saved_credit_card.cc_number, 'cc_exp_month' => saved_credit_card.exp_month, 'cc_exp_year' => saved_credit_card.exp_year } } MagentoApi.create_call(:authnetcim_payment_create, ) end |
.destroy(customer_id, payment_profile_id) ⇒ Gemgento::MagentoResponse
Destroy a saved payment method for a customer.
58 59 60 61 62 63 64 |
# File 'lib/gemgento/api/soap/authnetcim/payment.rb', line 58 def self.destroy(customer_id, payment_profile_id) = { customer_id: customer_id, payment_profile_id: payment_profile_id } MagentoApi.create_call(:authnetcim_payment_destroy, ) end |
.fetch(user) ⇒ Void
Fetch and sync all user saved credit cards.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gemgento/api/soap/authnetcim/payment.rb', line 70 def self.fetch(user) saved_cards = [] response = list(user.magento_id) if response.success? response.body[:response][:item].each do |saved_card| saved_cards << sync_magento_to_local(user, saved_card) end end SavedCreditCard.skip_callback(:destroy, :before, :magento_destroy) user.saved_credit_cards.reload user.saved_credit_cards.where.not(id: saved_cards.map(&:id)).destroy_all SavedCreditCard.set_callback(:destroy, :before, :magento_destroy) end |
.list(customer_id) ⇒ Gemgento::MagentoResponse
Get a list of saved payment methods for customer.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gemgento/api/soap/authnetcim/payment.rb', line 11 def self.list(customer_id) response = MagentoApi.create_call(:authnetcim_payment_list, { customer_id: customer_id }) # filter and enforce the array of cards on success if response.success? if response.body[:response].nil? response.body[:response] = {item: []} elsif response.body[:response][:item].nil? response.body[:response][:item] = [] elsif !response.body[:response][:item].is_a? Array response.body[:response][:item] = [response.body[:response][:item]] end end return response end |