Class: VaultedBilling::Gateways::NmiCustomerVault
- Inherits:
-
Object
- Object
- VaultedBilling::Gateways::NmiCustomerVault
- Includes:
- VaultedBilling::Gateway
- Defined in:
- lib/vaulted_billing/gateways/nmi_customer_vault.rb
Overview
An interface to the NMI Customer Vault.
Currently, the Customer Vault is setup to be one-to-one with a customer to a credit card. Unlike Authorize.net’s CIM, a single customer cannot carry multiple credit cards. Therefore most of the individual customer manipulation methods are simply stubbed to always be successful. The meat of the library is in the credit card methods and transactions.
Instance Attribute Summary collapse
-
#use_test_uri ⇒ Object
Returns the value of attribute use_test_uri.
Instance Method Summary collapse
-
#add_customer(customer) ⇒ Object
A stub, since the vault requires both customer information and credit card information.
- #add_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
- #authorize(customer, credit_card, amount, options = {}) ⇒ Object
- #capture(transaction_id, amount, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ NmiCustomerVault
constructor
A new instance of NmiCustomerVault.
- #purchase(customer, credit_card, amount, options = {}) ⇒ Object
- #refund(transaction_id, amount, options = {}) ⇒ Object
-
#remove_customer(customer) ⇒ Object
A stub, since the vault requires both customer information and credit card information.
- #remove_customer_credit_card(customer, credit_card) ⇒ Object
-
#update_customer(customer) ⇒ Object
A stub, since the vault requires both customer information and credit card information.
- #update_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
- #uri ⇒ Object
- #void(transaction_id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ NmiCustomerVault
Returns a new instance of NmiCustomerVault.
18 19 20 21 22 23 24 25 26 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 18 def initialize( = {}) @live_uri = "https://secure.nmi.com/api/transact.php" = HashWithIndifferentAccess.new() @username = [:username] || VaultedBilling.config.nmi_customer_vault.username @password = [:password] || VaultedBilling.config.nmi_customer_vault.password @raw_options = [:raw_options] || VaultedBilling.config.nmi_customer_vault. @use_test_uri = .has_key?(:test) ? [:test] : (VaultedBilling.config.nmi_customer_vault.test_mode || VaultedBilling.config.test_mode) end |
Instance Attribute Details
#use_test_uri ⇒ Object
Returns the value of attribute use_test_uri.
16 17 18 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 16 def use_test_uri @use_test_uri end |
Instance Method Details
#add_customer(customer) ⇒ Object
A stub, since the vault requires both customer information and credit card information. Actual additions are handled via the add_customer_credit_card method.
33 34 35 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 33 def add_customer(customer) respond_with customer.to_vaulted_billing end |
#add_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 55 def add_customer_credit_card(customer, credit_card, = {}) data = storage_data('add_customer', customer.to_vaulted_billing, credit_card.to_vaulted_billing) response = http.post(data) respond_with(credit_card, response, :success => response.success?) do |c| c.vault_id = response.body['customer_vault_id'] end end |
#authorize(customer, credit_card, amount, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 89 def (customer, credit_card, amount, = {}) data = transaction_data('auth', { :customer_vault_id => credit_card.to_vaulted_billing.vault_id, :amount => amount }) response = http.post(data) respond_with(new_transaction_from_response(response.body), response, :success => response.success?) end |
#capture(transaction_id, amount, options = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 100 def capture(transaction_id, amount, = {}) data = transaction_data('capture', { :transactionid => transaction_id, :amount => amount }) response = http.post(data) respond_with(new_transaction_from_response(response.body), response, :success => response.success?) end |
#purchase(customer, credit_card, amount, options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 78 def purchase(customer, credit_card, amount, = {}) data = transaction_data('sale', { :customer_vault_id => credit_card.to_vaulted_billing.vault_id, :amount => amount }) response = http.post(data) respond_with(new_transaction_from_response(response.body), response, :success => response.success?) end |
#refund(transaction_id, amount, options = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 111 def refund(transaction_id, amount, = {}) data = transaction_data('refund', { :transactionid => transaction_id, :amount => amount }) response = http.post(data) respond_with(new_transaction_from_response(response.body), response, :success => response.success?) end |
#remove_customer(customer) ⇒ Object
A stub, since the vault requires both customer information and credit card information. Actual removals are handled via the remove_customer_credit_card method.
51 52 53 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 51 def remove_customer(customer) respond_with customer.to_vaulted_billing end |
#remove_customer_credit_card(customer, credit_card) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 69 def remove_customer_credit_card(customer, credit_card) data = core_data.merge({ :customer_vault => 'delete_customer', :customer_vault_id => credit_card.to_vaulted_billing.vault_id }).to_querystring response = http.post(data) respond_with(credit_card, response, :success => response.success?) end |
#update_customer(customer) ⇒ Object
A stub, since the vault requires both customer information and credit card information. Actual modifications are handled via the update_customer_credit_card method.
42 43 44 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 42 def update_customer(customer) respond_with customer.to_vaulted_billing end |
#update_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
63 64 65 66 67 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 63 def update_customer_credit_card(customer, credit_card, = {}) data = storage_data('update_customer', customer.to_vaulted_billing, credit_card.to_vaulted_billing) response = http.post(data) respond_with(credit_card, response, :success => response.success?) end |
#uri ⇒ Object
132 133 134 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 132 def uri @live_uri end |
#void(transaction_id, options = {}) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/vaulted_billing/gateways/nmi_customer_vault.rb', line 122 def void(transaction_id, = {}) data = transaction_data('void', { :transactionid => transaction_id }) response = http.post(data) respond_with(new_transaction_from_response(response.body), response, :success => response.success?) end |