mcmire-activemerchant 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +508 -0
- data/CONTRIBUTORS +134 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +136 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +46 -0
- data/lib/active_merchant/billing.rb +9 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +57 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +159 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +163 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +885 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +98 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
- data/lib/active_merchant/billing/gateways/realex.rb +200 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +309 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +25 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
- data/lib/active_merchant/billing/integrations.rb +29 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/helper.rb +93 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/return.rb +35 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/lib/connection.rb +170 -0
- data/lib/active_merchant/lib/country.rb +319 -0
- data/lib/active_merchant/lib/error.rb +4 -0
- data/lib/active_merchant/lib/post_data.rb +22 -0
- data/lib/active_merchant/lib/posts_data.rb +47 -0
- data/lib/active_merchant/lib/requires_parameters.rb +16 -0
- data/lib/active_merchant/lib/utils.rb +18 -0
- data/lib/active_merchant/lib/validateable.rb +76 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- metadata +218 -0
@@ -0,0 +1,885 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# ==== Customer Information Manager (CIM)
|
4
|
+
#
|
5
|
+
# The Authorize.Net Customer Information Manager (CIM) is an optional additional service that allows you to store sensitive payment information on
|
6
|
+
# Authorize.Net's servers, simplifying payments for returning customers and recurring transactions. It can also help with Payment Card Industry (PCI)
|
7
|
+
# Data Security Standard compliance, since customer data is no longer stored locally.
|
8
|
+
#
|
9
|
+
# To use the AuthorizeNetCimGateway CIM must be enabled for your account.
|
10
|
+
#
|
11
|
+
# Information about CIM is available on the {Authorize.Net website}[http://www.authorize.net/solutions/merchantsolutions/merchantservices/cim/].
|
12
|
+
# Information about the CIM API is available at the {Authorize.Net Integration Center}[http://developer.authorize.net/]
|
13
|
+
#
|
14
|
+
# ==== Login and Password
|
15
|
+
#
|
16
|
+
# The login and password are not the username and password you use to
|
17
|
+
# login to the Authorize.Net Merchant Interface. Instead, you will
|
18
|
+
# use the API Login ID as the login and Transaction Key as the
|
19
|
+
# password.
|
20
|
+
#
|
21
|
+
# ==== How to Get Your API Login ID and Transaction Key
|
22
|
+
#
|
23
|
+
# 1. Log into the Merchant Interface
|
24
|
+
# 2. Select Settings from the Main Menu
|
25
|
+
# 3. Click on API Login ID and Transaction Key in the Security section
|
26
|
+
# 4. Type in the answer to the secret question configured on setup
|
27
|
+
# 5. Click Submit
|
28
|
+
class AuthorizeNetCimGateway < Gateway
|
29
|
+
|
30
|
+
class_inheritable_accessor :test_url, :live_url
|
31
|
+
|
32
|
+
self.test_url = 'https://apitest.authorize.net/xml/v1/request.api'
|
33
|
+
self.live_url = 'https://api.authorize.net/xml/v1/request.api'
|
34
|
+
|
35
|
+
AUTHORIZE_NET_CIM_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
|
36
|
+
|
37
|
+
CIM_ACTIONS = {
|
38
|
+
:get_customer_profile_ids => 'getCustomerProfileIds',
|
39
|
+
:create_customer_profile => 'createCustomerProfile',
|
40
|
+
:create_customer_payment_profile => 'createCustomerPaymentProfile',
|
41
|
+
:create_customer_shipping_address => 'createCustomerShippingAddress',
|
42
|
+
:get_customer_profile => 'getCustomerProfile',
|
43
|
+
:get_customer_payment_profile => 'getCustomerPaymentProfile',
|
44
|
+
:get_customer_shipping_address => 'getCustomerShippingAddress',
|
45
|
+
:delete_customer_profile => 'deleteCustomerProfile',
|
46
|
+
:delete_customer_payment_profile => 'deleteCustomerPaymentProfile',
|
47
|
+
:delete_customer_shipping_address => 'deleteCustomerShippingAddress',
|
48
|
+
:update_customer_profile => 'updateCustomerProfile',
|
49
|
+
:update_customer_payment_profile => 'updateCustomerPaymentProfile',
|
50
|
+
:update_customer_shipping_address => 'updateCustomerShippingAddress',
|
51
|
+
:create_customer_profile_transaction => 'createCustomerProfileTransaction',
|
52
|
+
:validate_customer_payment_profile => 'validateCustomerPaymentProfile'
|
53
|
+
}
|
54
|
+
|
55
|
+
CIM_TRANSACTION_TYPES = {
|
56
|
+
:auth_capture => 'profileTransAuthCapture',
|
57
|
+
:auth_only => 'profileTransAuthOnly',
|
58
|
+
:capture_only => 'profileTransCaptureOnly',
|
59
|
+
:prior_auth_capture => 'profileTransPriorAuthCapture',
|
60
|
+
:refund => 'profileTransRefund',
|
61
|
+
:void => 'profileTransVoid'
|
62
|
+
}
|
63
|
+
|
64
|
+
CIM_VALIDATION_MODES = {
|
65
|
+
:none => 'none',
|
66
|
+
:test => 'testMode',
|
67
|
+
:live => 'liveMode'
|
68
|
+
}
|
69
|
+
|
70
|
+
BANK_ACCOUNT_TYPES = {
|
71
|
+
:checking => 'checking',
|
72
|
+
:savings => 'savings',
|
73
|
+
:business_checking => 'businessChecking'
|
74
|
+
}
|
75
|
+
|
76
|
+
ECHECK_TYPES = {
|
77
|
+
:ccd => 'CCD',
|
78
|
+
:ppd => 'PPD'
|
79
|
+
}
|
80
|
+
|
81
|
+
self.homepage_url = 'http://www.authorize.net/'
|
82
|
+
self.display_name = 'Authorize.Net CIM'
|
83
|
+
self.supported_countries = ['US']
|
84
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
85
|
+
|
86
|
+
# Creates a new AuthorizeNetCimGateway
|
87
|
+
#
|
88
|
+
# The gateway requires that a valid API Login ID and Transaction Key be passed
|
89
|
+
# in the +options+ hash.
|
90
|
+
#
|
91
|
+
# ==== Options
|
92
|
+
#
|
93
|
+
# * <tt>:login</tt> -- The Authorize.Net API Login ID (REQUIRED)
|
94
|
+
# * <tt>:password</tt> -- The Authorize.Net Transaction Key. (REQUIRED)
|
95
|
+
# * <tt>:test</tt> -- +true+ or +false+. If true, perform transactions against the test server.
|
96
|
+
# Otherwise, perform transactions against the production server.
|
97
|
+
def initialize(options = {})
|
98
|
+
requires!(options, :login, :password)
|
99
|
+
@options = options
|
100
|
+
super
|
101
|
+
end
|
102
|
+
|
103
|
+
# Retrieves a list of all Customer Profile IDs from the gateway
|
104
|
+
#
|
105
|
+
# The response's params["ids"] contains the list of Customer Profile IDs
|
106
|
+
#
|
107
|
+
# ==== Options - none
|
108
|
+
#
|
109
|
+
def get_customer_profile_ids
|
110
|
+
request = build_request(:get_customer_profile_ids)
|
111
|
+
commit(:get_customer_profile_ids, request)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Creates a new customer profile along with any customer payment profiles and customer shipping addresses
|
115
|
+
# for the customer profile.
|
116
|
+
#
|
117
|
+
# Returns a Response with the Customer Profile ID of the new customer profile in the authorization field.
|
118
|
+
# It is *CRITICAL* that you save this ID. There is no way to retrieve this through the API. You will not
|
119
|
+
# be able to create another Customer Profile with the same information.
|
120
|
+
#
|
121
|
+
# ==== Options
|
122
|
+
#
|
123
|
+
# TODO
|
124
|
+
def create_customer_profile(options)
|
125
|
+
# TODO Add requires
|
126
|
+
request = build_request(:create_customer_profile, options)
|
127
|
+
commit(:create_customer_profile, request)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Creates a new customer payment profile for an existing customer profile.
|
131
|
+
#
|
132
|
+
# ==== Options
|
133
|
+
#
|
134
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)
|
135
|
+
# * <tt>:payment_profile</tt> -- A hash containing the elements of the new payment profile (REQUIRED)
|
136
|
+
#
|
137
|
+
# ==== Payment Profile
|
138
|
+
#
|
139
|
+
# * <tt>:payment</tt> -- A hash containing information on payment. Either :credit_card or :bank_account (REQUIRED)
|
140
|
+
def create_customer_payment_profile(options)
|
141
|
+
requires!(options, :customer_profile_id)
|
142
|
+
requires!(options, :payment_profile)
|
143
|
+
requires!(options[:payment_profile], :payment)
|
144
|
+
|
145
|
+
request = build_request(:create_customer_payment_profile, options)
|
146
|
+
commit(:create_customer_payment_profile, request)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Creates a new customer shipping address for an existing customer profile.
|
150
|
+
#
|
151
|
+
# ==== Options
|
152
|
+
#
|
153
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)
|
154
|
+
# * <tt>:address</tt> -- A hash containing the elements of the shipping address (REQUIRED)
|
155
|
+
def create_customer_shipping_address(options)
|
156
|
+
requires!(options, :customer_profile_id)
|
157
|
+
requires!(options, :address)
|
158
|
+
|
159
|
+
request = build_request(:create_customer_shipping_address, options)
|
160
|
+
commit(:create_customer_shipping_address, request)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Deletes an existing customer profile along with all associated customer payment profiles and customer shipping addresses.
|
164
|
+
#
|
165
|
+
# ==== Options
|
166
|
+
#
|
167
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to be deleted. (REQUIRED)
|
168
|
+
def delete_customer_profile(options)
|
169
|
+
requires!(options, :customer_profile_id)
|
170
|
+
|
171
|
+
request = build_request(:delete_customer_profile, options)
|
172
|
+
commit(:delete_customer_profile, request)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Deletes a customer payment profile from an existing customer profile.
|
176
|
+
#
|
177
|
+
# ==== Options
|
178
|
+
#
|
179
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)
|
180
|
+
# * <tt>:customer_payment_profile_id</tt> -- The Payment Profile ID of the payment profile to be deleted. (REQUIRED)
|
181
|
+
def delete_customer_payment_profile(options)
|
182
|
+
requires!(options, :customer_profile_id)
|
183
|
+
requires!(options, :customer_payment_profile_id)
|
184
|
+
|
185
|
+
request = build_request(:delete_customer_payment_profile, options)
|
186
|
+
commit(:delete_customer_payment_profile, request)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Deletes a customer shipping address from an existing customer profile.
|
190
|
+
#
|
191
|
+
# ==== Options
|
192
|
+
#
|
193
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)
|
194
|
+
# * <tt>:customer_address_id</tt> -- The Shipping Address ID of the shipping address to be deleted. (REQUIRED)
|
195
|
+
def delete_customer_shipping_address(options)
|
196
|
+
requires!(options, :customer_profile_id)
|
197
|
+
requires!(options, :customer_address_id)
|
198
|
+
|
199
|
+
request = build_request(:delete_customer_shipping_address, options)
|
200
|
+
commit(:delete_customer_shipping_address, request)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Retrieves an existing customer profile along with all the associated customer payment profiles and customer shipping addresses.
|
204
|
+
#
|
205
|
+
# Returns a Response whose params hash contains all the profile information.
|
206
|
+
#
|
207
|
+
# ==== Options
|
208
|
+
#
|
209
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to retrieve. (REQUIRED)
|
210
|
+
def get_customer_profile(options)
|
211
|
+
requires!(options, :customer_profile_id)
|
212
|
+
|
213
|
+
request = build_request(:get_customer_profile, options)
|
214
|
+
commit(:get_customer_profile, request)
|
215
|
+
end
|
216
|
+
|
217
|
+
# Retrieve a customer payment profile for an existing customer profile.
|
218
|
+
#
|
219
|
+
# Returns a Response whose params hash contains all the payment profile information. Sensitive information such as credit card
|
220
|
+
# numbers will be masked.
|
221
|
+
#
|
222
|
+
# ==== Options
|
223
|
+
#
|
224
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)
|
225
|
+
# * <tt>:customer_payment_profile_id</tt> -- The Payment Profile ID of the payment profile to be retrieved. (REQUIRED)
|
226
|
+
def get_customer_payment_profile(options)
|
227
|
+
requires!(options, :customer_profile_id)
|
228
|
+
requires!(options, :customer_payment_profile_id)
|
229
|
+
|
230
|
+
request = build_request(:get_customer_payment_profile, options)
|
231
|
+
commit(:get_customer_payment_profile, request)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Retrieve a customer shipping address for an existing customer profile.
|
235
|
+
#
|
236
|
+
# Returns a Response whose params hash contains all the shipping address information.
|
237
|
+
#
|
238
|
+
# ==== Options
|
239
|
+
#
|
240
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)
|
241
|
+
# * <tt>:customer_address_id</tt> -- The Shipping Address ID of the shipping address to be retrieved. (REQUIRED)
|
242
|
+
def get_customer_shipping_address(options)
|
243
|
+
requires!(options, :customer_profile_id)
|
244
|
+
requires!(options, :customer_address_id)
|
245
|
+
|
246
|
+
request = build_request(:get_customer_shipping_address, options)
|
247
|
+
commit(:get_customer_shipping_address, request)
|
248
|
+
end
|
249
|
+
|
250
|
+
# Updates an existing customer profile.
|
251
|
+
#
|
252
|
+
# Warning: if you do not provide a parameter in the <tt>:payment_profile</tt> hash, it is automatically set to nil at
|
253
|
+
# Authorize.Net. You will most likely want to first get the profile hash using get_customer_profile and then only change the
|
254
|
+
# elements you wish to change.
|
255
|
+
#
|
256
|
+
# ==== Options
|
257
|
+
#
|
258
|
+
# * <tt>:profile</tt> -- A hash containing the values the Customer Profile should be updated to. (REQUIRED)
|
259
|
+
#
|
260
|
+
# ==== Profile
|
261
|
+
#
|
262
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer profile to update. (REQUIRED)
|
263
|
+
def update_customer_profile(options)
|
264
|
+
requires!(options, :profile)
|
265
|
+
requires!(options[:profile], :customer_profile_id)
|
266
|
+
|
267
|
+
request = build_request(:update_customer_profile, options)
|
268
|
+
commit(:update_customer_profile, request)
|
269
|
+
end
|
270
|
+
|
271
|
+
# Updates a customer payment profile for an existing customer profile.
|
272
|
+
#
|
273
|
+
# Warning: if you do not provide a parameter in the <tt>:payment_profile</tt> hash, it is automatically set to nil at
|
274
|
+
# Authorize.Net. You will most likely want to first get the profile hash using get_customer_payment_profile and then only
|
275
|
+
# change the elements you wish to change.
|
276
|
+
#
|
277
|
+
# ==== Options
|
278
|
+
#
|
279
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)
|
280
|
+
# * <tt>:payment_profile</tt> -- A hash containing the values the Customer Payment Profile should be updated to. (REQUIRED)
|
281
|
+
#
|
282
|
+
# ==== Payment Profile
|
283
|
+
#
|
284
|
+
# * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to update. (REQUIRED)
|
285
|
+
def update_customer_payment_profile(options)
|
286
|
+
requires!(options, :customer_profile_id, :payment_profile)
|
287
|
+
requires!(options[:payment_profile], :customer_payment_profile_id)
|
288
|
+
|
289
|
+
request = build_request(:update_customer_payment_profile, options)
|
290
|
+
commit(:update_customer_payment_profile, request)
|
291
|
+
end
|
292
|
+
|
293
|
+
# Updates a customer shipping address for an existing customer profile.
|
294
|
+
#
|
295
|
+
# Warning: if you do not provide a parameter in the <tt>:address</tt> hash, it is automatically set to nil at
|
296
|
+
# Authorize.Net. You will most likely want to first get the profile hash using get_customer_shipping_address and then only
|
297
|
+
# change the elements you wish to change.
|
298
|
+
#
|
299
|
+
# ==== Options
|
300
|
+
#
|
301
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)
|
302
|
+
# * <tt>:address</tt> -- A hash containing the values the Customer Shipping Address should be updated to. (REQUIRED)
|
303
|
+
#
|
304
|
+
# ==== Address
|
305
|
+
#
|
306
|
+
# * <tt>:customer_address_id</tt> -- The Customer Address ID of the Customer Payment Profile to update. (REQUIRED)
|
307
|
+
def update_customer_shipping_address(options)
|
308
|
+
requires!(options, :customer_profile_id, :address)
|
309
|
+
requires!(options[:address], :customer_address_id)
|
310
|
+
|
311
|
+
request = build_request(:update_customer_shipping_address, options)
|
312
|
+
commit(:update_customer_shipping_address, request)
|
313
|
+
end
|
314
|
+
|
315
|
+
# Creates a new payment transaction from an existing customer profile
|
316
|
+
#
|
317
|
+
# This is what is used to charge a customer whose information you have stored in a Customer Profile.
|
318
|
+
#
|
319
|
+
# Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
|
320
|
+
#
|
321
|
+
# ==== Options
|
322
|
+
#
|
323
|
+
# * <tt>:transaction</tt> -- A hash containing information on the transaction that is being requested. (REQUIRED)
|
324
|
+
#
|
325
|
+
# ==== Transaction
|
326
|
+
#
|
327
|
+
# * <tt>:type</tt> -- The type of transaction. Can be either <tt>:auth_only</tt>, <tt>:capture_only</tt>, <tt>:auth_capture</tt>, <tt>:prior_auth_capture</tt>, <tt>:refund</tt> or <tt>:void</tt>. (REQUIRED)
|
328
|
+
# * <tt>:amount</tt> -- The amount for the tranaction. Formatted with a decimal. For example "4.95" (CONDITIONAL)
|
329
|
+
# - :type == :void (NOT USED)
|
330
|
+
# - :type == (:refund, :auth_only, :capture_only, :auth_capture, :prior_auth_capture) (REQUIRED)
|
331
|
+
#
|
332
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (CONDITIONAL)
|
333
|
+
# - :type == (:void, :prior_auth_capture) (OPTIONAL)
|
334
|
+
# - :type == :refund (CONDITIONAL - required if masked information is not being submitted [see below])
|
335
|
+
# - :type == (:auth_only, :capture_only, :auth_capture) (REQUIRED)
|
336
|
+
#
|
337
|
+
# * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (CONDITIONAL)
|
338
|
+
# - :type == (:void, :prior_auth_capture) (OPTIONAL)
|
339
|
+
# - :type == :refund (CONDITIONAL - required if masked information is not being submitted [see below])
|
340
|
+
# - :type == (:auth_only, :capture_only, :auth_capture) (REQUIRED)
|
341
|
+
#
|
342
|
+
# * <tt>:trans_id</tt> -- The payment gateway assigned transaction ID of the original transaction (CONDITIONAL):
|
343
|
+
# - :type = (:void, :refund, :prior_auth_capture) (REQUIRED)
|
344
|
+
# - :type = (:auth_only, :capture_only, :auth_capture) (NOT USED)
|
345
|
+
#
|
346
|
+
# * <tt>customer_shipping_address_id</tt> -- Payment gateway assigned ID associated with the customer shipping address (CONDITIONAL)
|
347
|
+
# - :type = (:void, :refund) (OPTIONAL)
|
348
|
+
# - :type = (:auth_only, :capture_only, :auth_capture) (NOT USED)
|
349
|
+
# - :type = (:prior_auth_capture) (OPTIONAL)
|
350
|
+
#
|
351
|
+
# * <tt>:extra_options</tt> -- Extra options may be provided to Authorize.net which are specific to the transaction. See the list of the transaction data fields that can be submitted using the transaction request string at http://www.authorize.net/support/AIM_guide.pdf pages 16-26.
|
352
|
+
#
|
353
|
+
# ==== For :type == :refund only
|
354
|
+
# * <tt>:credit_card_number_masked</tt> -- (CONDITIONAL - requied for credit card refunds is :customer_profile_id AND :customer_payment_profile_id are missing)
|
355
|
+
# * <tt>:bank_routing_number_masked && :bank_account_number_masked</tt> -- (CONDITIONAL - requied for electronic check refunds is :customer_profile_id AND :customer_payment_profile_id are missing) (NOT ABLE TO TEST - I keep getting "ACH transactions are not accepted by this merchant." when trying to make a payment and, until that's possible I can't refund (wiseleyb@gmail.com))
|
356
|
+
def create_customer_profile_transaction(options)
|
357
|
+
requires!(options, :transaction)
|
358
|
+
requires!(options[:transaction], :type)
|
359
|
+
case options[:transaction][:type]
|
360
|
+
when :void
|
361
|
+
requires!(options[:transaction], :trans_id)
|
362
|
+
when :refund
|
363
|
+
requires!(options[:transaction], :trans_id) &&
|
364
|
+
(
|
365
|
+
(options[:transaction][:customer_profile_id] && options[:transaction][:customer_payment_profile_id]) ||
|
366
|
+
options[:transaction][:credit_card_number_masked] ||
|
367
|
+
(options[:transaction][:bank_routing_number_masked] && options[:transaction][:bank_account_number_masked])
|
368
|
+
)
|
369
|
+
when :prior_auth_capture
|
370
|
+
requires!(options[:transaction], :amount, :trans_id)
|
371
|
+
else
|
372
|
+
requires!(options[:transaction], :amount, :customer_profile_id, :customer_payment_profile_id)
|
373
|
+
end
|
374
|
+
request = build_request(:create_customer_profile_transaction, options)
|
375
|
+
commit(:create_customer_profile_transaction, request)
|
376
|
+
end
|
377
|
+
|
378
|
+
# Creates a new payment transaction for refund from an existing customer profile
|
379
|
+
#
|
380
|
+
# This is what is used to refund a transaction you have stored in a Customer Profile.
|
381
|
+
#
|
382
|
+
# Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
|
383
|
+
#
|
384
|
+
# ==== Options
|
385
|
+
#
|
386
|
+
# * <tt>:transaction</tt> -- A hash containing information on the transaction that is being requested. (REQUIRED)
|
387
|
+
#
|
388
|
+
# ==== Transaction
|
389
|
+
#
|
390
|
+
# * <tt>:amount</tt> -- The total amount to be refunded (REQUIRED)
|
391
|
+
#
|
392
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (CONDITIONAL :customer_payment_profile_id must be included if used)
|
393
|
+
# * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (CONDITIONAL :customer_profile_id must be included if used)
|
394
|
+
#
|
395
|
+
# * <tt>:credit_card_number_masked</tt> -- Four Xs follwed by the last four digits of the credit card (CONDITIONAL - used if customer_profile_id and customer_payment_profile_id aren't given)
|
396
|
+
#
|
397
|
+
# * <tt>:bank_routing_number_masked</tt> -- The last four gidits of the routing number to be refunded (CONDITIONAL - must be used with :bank_account_number_masked)
|
398
|
+
# * <tt>:bank_account_number_masked</tt> -- The last four digis of the bank account number to be refunded, Ex. XXXX1234 (CONDITIONAL - must be used with :bank_routing_number_masked)
|
399
|
+
def create_customer_profile_transaction_for_refund(options)
|
400
|
+
requires!(options, :transaction)
|
401
|
+
options[:transaction][:type] = :refund
|
402
|
+
requires!(options[:transaction], :trans_id)
|
403
|
+
requires!(options[:transaction], :amount)
|
404
|
+
request = build_request(:create_customer_profile_transaction, options)
|
405
|
+
commit(:create_customer_profile_transaction, request)
|
406
|
+
end
|
407
|
+
|
408
|
+
# Creates a new payment transaction for void from an existing customer profile
|
409
|
+
#
|
410
|
+
# This is what is used to void a transaction you have stored in a Customer Profile.
|
411
|
+
#
|
412
|
+
# Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
|
413
|
+
#
|
414
|
+
# ==== Options
|
415
|
+
#
|
416
|
+
# * <tt>:transaction</tt> -- A hash containing information on the transaction that is being requested. (REQUIRED)
|
417
|
+
#
|
418
|
+
# ==== Transaction
|
419
|
+
#
|
420
|
+
# * <tt>:trans_id</tt> -- The payment gateway assigned transaction id of the original transaction. (REQUIRED)
|
421
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction.
|
422
|
+
# * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction.
|
423
|
+
# * <tt>:customer_shipping_address_id</tt> -- Payment gateway assigned ID associated with the customer shipping address.
|
424
|
+
def create_customer_profile_transaction_for_void(options)
|
425
|
+
requires!(options, :transaction)
|
426
|
+
options[:transaction][:type] = :void
|
427
|
+
requires!(options[:transaction], :trans_id)
|
428
|
+
request = build_request(:create_customer_profile_transaction, options)
|
429
|
+
commit(:create_customer_profile_transaction, request)
|
430
|
+
end
|
431
|
+
|
432
|
+
# Verifies an existing customer payment profile by generating a test transaction
|
433
|
+
#
|
434
|
+
# Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
|
435
|
+
#
|
436
|
+
# ==== Options
|
437
|
+
#
|
438
|
+
# * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (REQUIRED)
|
439
|
+
# * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to be verified. (REQUIRED)
|
440
|
+
# * <tt>:customer_address_id</tt> -- The Customer Address ID of the Customer Shipping Address to be verified.
|
441
|
+
# * <tt>:validation_mode</tt> -- <tt>:live</tt> or <tt>:test</tt> In Test Mode, only field validation is performed.
|
442
|
+
# In Live Mode, a transaction is generated and submitted to the processor with the amount of $0.01. If successful, the transaction is immediately voided. (REQUIRED)
|
443
|
+
def validate_customer_payment_profile(options)
|
444
|
+
requires!(options, :customer_profile_id, :customer_payment_profile_id, :validation_mode)
|
445
|
+
|
446
|
+
request = build_request(:validate_customer_payment_profile, options)
|
447
|
+
commit(:validate_customer_payment_profile, request)
|
448
|
+
end
|
449
|
+
|
450
|
+
private
|
451
|
+
|
452
|
+
def expdate(credit_card)
|
453
|
+
sprintf('%04d-%02d', credit_card.year, credit_card.month)
|
454
|
+
end
|
455
|
+
|
456
|
+
def build_request(action, options = {})
|
457
|
+
unless CIM_ACTIONS.include?(action)
|
458
|
+
raise StandardError, "Invalid Customer Information Manager Action: #{action}"
|
459
|
+
end
|
460
|
+
|
461
|
+
xml = Builder::XmlMarkup.new(:indent => 2)
|
462
|
+
xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
|
463
|
+
xml.tag!("#{CIM_ACTIONS[action]}Request", :xmlns => AUTHORIZE_NET_CIM_NAMESPACE) do
|
464
|
+
add_merchant_authentication(xml)
|
465
|
+
# Merchant-assigned reference ID for the request
|
466
|
+
xml.tag!('refId', options[:ref_id]) if options[:ref_id]
|
467
|
+
send("build_#{action}_request", xml, options)
|
468
|
+
if options[:extra_options]
|
469
|
+
xml.tag!('extraOptions') do
|
470
|
+
xml.cdata!(options[:extra_options])
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
# Contains the merchant’s payment gateway account authentication information
|
477
|
+
def add_merchant_authentication(xml)
|
478
|
+
xml.tag!('merchantAuthentication') do
|
479
|
+
xml.tag!('name', @options[:login])
|
480
|
+
xml.tag!('transactionKey', @options[:password])
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
# The get customer profile IDs request does not need any additional XML
|
485
|
+
def build_get_customer_profile_ids_request(xml, options) end
|
486
|
+
|
487
|
+
def build_create_customer_profile_request(xml, options)
|
488
|
+
add_profile(xml, options[:profile])
|
489
|
+
|
490
|
+
xml.target!
|
491
|
+
end
|
492
|
+
|
493
|
+
def build_create_customer_payment_profile_request(xml, options)
|
494
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
495
|
+
|
496
|
+
xml.tag!('paymentProfile') do
|
497
|
+
add_payment_profile(xml, options[:payment_profile])
|
498
|
+
end
|
499
|
+
|
500
|
+
xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
|
501
|
+
|
502
|
+
xml.target!
|
503
|
+
end
|
504
|
+
|
505
|
+
def build_create_customer_shipping_address_request(xml, options)
|
506
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
507
|
+
|
508
|
+
xml.tag!('address') do
|
509
|
+
add_address(xml, options[:address])
|
510
|
+
end
|
511
|
+
|
512
|
+
xml.target!
|
513
|
+
end
|
514
|
+
|
515
|
+
def build_delete_customer_profile_request(xml, options)
|
516
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
517
|
+
xml.target!
|
518
|
+
end
|
519
|
+
|
520
|
+
def build_delete_customer_payment_profile_request(xml, options)
|
521
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
522
|
+
xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
|
523
|
+
xml.target!
|
524
|
+
end
|
525
|
+
|
526
|
+
def build_delete_customer_shipping_address_request(xml, options)
|
527
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
528
|
+
xml.tag!('customerAddressId', options[:customer_address_id])
|
529
|
+
xml.target!
|
530
|
+
end
|
531
|
+
|
532
|
+
def build_get_customer_profile_request(xml, options)
|
533
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
534
|
+
xml.target!
|
535
|
+
end
|
536
|
+
|
537
|
+
def build_get_customer_payment_profile_request(xml, options)
|
538
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
539
|
+
xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
|
540
|
+
xml.target!
|
541
|
+
end
|
542
|
+
|
543
|
+
def build_get_customer_shipping_address_request(xml, options)
|
544
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
545
|
+
xml.tag!('customerAddressId', options[:customer_address_id])
|
546
|
+
xml.target!
|
547
|
+
end
|
548
|
+
|
549
|
+
def build_update_customer_profile_request(xml, options)
|
550
|
+
add_profile(xml, options[:profile], true)
|
551
|
+
|
552
|
+
xml.target!
|
553
|
+
end
|
554
|
+
|
555
|
+
def build_update_customer_payment_profile_request(xml, options)
|
556
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
557
|
+
|
558
|
+
xml.tag!('paymentProfile') do
|
559
|
+
add_payment_profile(xml, options[:payment_profile])
|
560
|
+
end
|
561
|
+
|
562
|
+
xml.target!
|
563
|
+
end
|
564
|
+
|
565
|
+
def build_update_customer_shipping_address_request(xml, options)
|
566
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
567
|
+
|
568
|
+
xml.tag!('address') do
|
569
|
+
add_address(xml, options[:address])
|
570
|
+
end
|
571
|
+
|
572
|
+
xml.target!
|
573
|
+
end
|
574
|
+
|
575
|
+
def build_create_customer_profile_transaction_request(xml, options)
|
576
|
+
add_transaction(xml, options[:transaction])
|
577
|
+
xml.tag!('extraOptions', "x_test_request=TRUE") if @options[:test]
|
578
|
+
|
579
|
+
xml.target!
|
580
|
+
end
|
581
|
+
|
582
|
+
def build_validate_customer_payment_profile_request(xml, options)
|
583
|
+
xml.tag!('customerProfileId', options[:customer_profile_id])
|
584
|
+
xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
|
585
|
+
xml.tag!('customerShippingAddressId', options[:customer_address_id]) if options[:customer_address_id]
|
586
|
+
xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
|
587
|
+
|
588
|
+
xml.target!
|
589
|
+
end
|
590
|
+
|
591
|
+
# :merchant_customer_id (Optional)
|
592
|
+
# :description (Optional)
|
593
|
+
# :email (Optional)
|
594
|
+
# :payment_profiles (Optional)
|
595
|
+
def add_profile(xml, profile, update = false)
|
596
|
+
xml.tag!('profile') do
|
597
|
+
# Merchant assigned ID for the customer. Up to 20 characters. (optional)
|
598
|
+
xml.tag!('merchantCustomerId', profile[:merchant_customer_id]) if profile[:merchant_customer_id]
|
599
|
+
# Description of the customer. Up to 255 Characters (optional)
|
600
|
+
xml.tag!('description', profile[:description]) if profile[:description]
|
601
|
+
# Email Address for the customer. Up to 255 Characters (optional)
|
602
|
+
xml.tag!('email', profile[:email]) if profile[:email]
|
603
|
+
|
604
|
+
if update
|
605
|
+
xml.tag!('customerProfileId', profile[:customer_profile_id])
|
606
|
+
else
|
607
|
+
add_payment_profiles(xml, profile[:payment_profiles]) if profile[:payment_profiles]
|
608
|
+
add_ship_to_list(xml, profile[:ship_to_list]) if profile[:ship_to_list]
|
609
|
+
end
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
def add_transaction(xml, transaction)
|
614
|
+
unless CIM_TRANSACTION_TYPES.include?(transaction[:type])
|
615
|
+
raise StandardError, "Invalid Customer Information Manager Transaction Type: #{transaction[:type]}"
|
616
|
+
end
|
617
|
+
|
618
|
+
xml.tag!('transaction') do
|
619
|
+
xml.tag!(CIM_TRANSACTION_TYPES[transaction[:type]]) do
|
620
|
+
# The amount to be billed to the customer
|
621
|
+
case transaction[:type]
|
622
|
+
when :void
|
623
|
+
tag_unless_blank(xml,'customerProfileId', transaction[:customer_profile_id])
|
624
|
+
tag_unless_blank(xml,'customerPaymentProfileId', transaction[:customer_payment_profile_id])
|
625
|
+
tag_unless_blank(xml,'customerShippingAddressId', transaction[:customer_shipping_address_id])
|
626
|
+
xml.tag!('transId', transaction[:trans_id])
|
627
|
+
when :refund
|
628
|
+
#TODO - add support for all the other options fields
|
629
|
+
xml.tag!('amount', transaction[:amount])
|
630
|
+
tag_unless_blank(xml, 'customerProfileId', transaction[:customer_profile_id])
|
631
|
+
tag_unless_blank(xml, 'customerPaymentProfileId', transaction[:customer_payment_profile_id])
|
632
|
+
tag_unless_blank(xml, 'customerShippingAddressId', transaction[:customer_shipping_address_id])
|
633
|
+
tag_unless_blank(xml, 'creditCardNumberMasked', transaction[:credit_card_number_masked])
|
634
|
+
tag_unless_blank(xml, 'bankRoutingNumberMasked', transaction[:bank_routing_number_masked])
|
635
|
+
tag_unless_blank(xml, 'bankAccountNumberMasked', transaction[:bank_account_number_masked])
|
636
|
+
xml.tag!('transId', transaction[:trans_id])
|
637
|
+
when :prior_auth_capture
|
638
|
+
xml.tag!('amount', transaction[:amount])
|
639
|
+
xml.tag!('transId', transaction[:trans_id])
|
640
|
+
else
|
641
|
+
xml.tag!('amount', transaction[:amount])
|
642
|
+
xml.tag!('customerProfileId', transaction[:customer_profile_id])
|
643
|
+
xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
|
644
|
+
xml.tag!('approvalCode', transaction[:approval_code]) if transaction[:type] == :capture_only
|
645
|
+
end
|
646
|
+
add_order(xml, transaction[:order]) if transaction[:order]
|
647
|
+
end
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
def add_order(xml, order)
|
652
|
+
xml.tag!('order') do
|
653
|
+
xml.tag!('invoiceNumber', order[:invoice_number]) if order[:invoice_number]
|
654
|
+
xml.tag!('description', order[:description]) if order[:description]
|
655
|
+
xml.tag!('purchaseOrderNumber', order[:purchase_order_number]) if order[:purchase_order_number]
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
def add_payment_profiles(xml, payment_profiles)
|
660
|
+
xml.tag!('paymentProfiles') do
|
661
|
+
add_payment_profile(xml, payment_profiles)
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
# :customer_type => 'individual or business', # Optional
|
666
|
+
# :bill_to => @address,
|
667
|
+
# :payment => @payment
|
668
|
+
def add_payment_profile(xml, payment_profile)
|
669
|
+
# 'individual' or 'business' (optional)
|
670
|
+
xml.tag!('customerType', payment_profile[:customer_type]) if payment_profile[:customer_type]
|
671
|
+
|
672
|
+
if payment_profile[:bill_to]
|
673
|
+
xml.tag!('billTo') do
|
674
|
+
add_address(xml, payment_profile[:bill_to])
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
678
|
+
if payment_profile[:payment]
|
679
|
+
xml.tag!('payment') do
|
680
|
+
add_credit_card(xml, payment_profile[:payment][:credit_card]) if payment_profile[:payment].has_key?(:credit_card)
|
681
|
+
add_bank_account(xml, payment_profile[:payment][:bank_account]) if payment_profile[:payment].has_key?(:bank_account)
|
682
|
+
add_drivers_license(xml, payment_profile[:payment][:drivers_license]) if payment_profile[:payment].has_key?(:drivers_license)
|
683
|
+
# This element is only required for Wells Fargo SecureSource eCheck.Net merchants
|
684
|
+
# The customer's Social Security Number or Tax ID
|
685
|
+
xml.tag!('taxId', payment_profile[:payment]) if payment_profile[:payment].has_key?(:tax_id)
|
686
|
+
end
|
687
|
+
end
|
688
|
+
|
689
|
+
xml.tag!('customerPaymentProfileId', payment_profile[:customer_payment_profile_id]) if payment_profile[:customer_payment_profile_id]
|
690
|
+
end
|
691
|
+
|
692
|
+
def add_ship_to_list(xml, ship_to_list)
|
693
|
+
xml.tag!('shipToList') do
|
694
|
+
add_address(xml, ship_to_list)
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
def add_address(xml, address)
|
699
|
+
xml.tag!('firstName', address[:first_name])
|
700
|
+
xml.tag!('lastName', address[:last_name])
|
701
|
+
xml.tag!('company', address[:company])
|
702
|
+
xml.tag!('address', address[:address1]) if address[:address1]
|
703
|
+
xml.tag!('address', address[:address]) if address[:address]
|
704
|
+
xml.tag!('city', address[:city])
|
705
|
+
xml.tag!('state', address[:state])
|
706
|
+
xml.tag!('zip', address[:zip])
|
707
|
+
xml.tag!('country', address[:country])
|
708
|
+
xml.tag!('phoneNumber', address[:phone_number]) if address[:phone_number]
|
709
|
+
xml.tag!('faxNumber', address[:fax_number]) if address[:fax_number]
|
710
|
+
|
711
|
+
xml.tag!('customerAddressId', address[:customer_address_id]) if address[:customer_address_id]
|
712
|
+
end
|
713
|
+
|
714
|
+
# Adds customer’s credit card information
|
715
|
+
# Note: This element should only be included
|
716
|
+
# when the payment method is credit card.
|
717
|
+
def add_credit_card(xml, credit_card)
|
718
|
+
return unless credit_card
|
719
|
+
xml.tag!('creditCard') do
|
720
|
+
# The credit card number used for payment of the subscription
|
721
|
+
xml.tag!('cardNumber', credit_card.number)
|
722
|
+
# The expiration date of the credit card used for the subscription
|
723
|
+
xml.tag!('expirationDate', expdate(credit_card))
|
724
|
+
xml.tag!('cardCode', credit_card.verification_value) if credit_card.verification_value?
|
725
|
+
end
|
726
|
+
end
|
727
|
+
|
728
|
+
# Adds customer’s bank account information
|
729
|
+
# Note: This element should only be included
|
730
|
+
# when the payment method is bank account.
|
731
|
+
def add_bank_account(xml, bank_account)
|
732
|
+
raise StandardError, "Invalid Bank Account Type: #{bank_account[:account_type]}" unless BANK_ACCOUNT_TYPES.include?(bank_account[:account_type])
|
733
|
+
raise StandardError, "Invalid eCheck Type: #{bank_account[:echeck_type]}" unless ECHECK_TYPES.include?(bank_account[:echeck_type])
|
734
|
+
|
735
|
+
xml.tag!('bankAccount') do
|
736
|
+
# The type of bank account
|
737
|
+
xml.tag!('accountType', BANK_ACCOUNT_TYPES[bank_account[:account_type]])
|
738
|
+
# The routing number of the customer’s bank
|
739
|
+
xml.tag!('routingNumber', bank_account[:routing_number])
|
740
|
+
# The bank account number
|
741
|
+
xml.tag!('accountNumber', bank_account[:account_number])
|
742
|
+
# The full name of the individual associated
|
743
|
+
# with the bank account number
|
744
|
+
xml.tag!('nameOnAccount', bank_account[:name_on_account])
|
745
|
+
# The type of electronic check transaction
|
746
|
+
xml.tag!('echeckType', ECHECK_TYPES[bank_account[:echeck_type]])
|
747
|
+
# The full name of the individual associated
|
748
|
+
# with the bank account number (optional)
|
749
|
+
xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
# Adds customer’s driver's license information
|
754
|
+
# Note: This element is only required for
|
755
|
+
# Wells Fargo SecureSource eCheck.Net merchants
|
756
|
+
def add_drivers_license(xml, drivers_license)
|
757
|
+
xml.tag!('driversLicense') do
|
758
|
+
# The state of the customer's driver's license
|
759
|
+
# A valid two character state code
|
760
|
+
xml.tag!('state', drivers_license[:state])
|
761
|
+
# The customer’s driver's license number
|
762
|
+
xml.tag!('number', drivers_license[:number])
|
763
|
+
# The date of birth listed on the customer's driver's license
|
764
|
+
# YYYY-MM-DD
|
765
|
+
xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
|
766
|
+
end
|
767
|
+
end
|
768
|
+
|
769
|
+
def commit(action, request)
|
770
|
+
url = test? ? test_url : live_url
|
771
|
+
xml = ssl_post(url, request, "Content-Type" => "text/xml")
|
772
|
+
|
773
|
+
response_params = parse(action, xml)
|
774
|
+
|
775
|
+
message = response_params['messages']['message']['text']
|
776
|
+
test_mode = test? || message =~ /Test Mode/
|
777
|
+
success = response_params['messages']['result_code'] == 'Ok'
|
778
|
+
|
779
|
+
auth = nil
|
780
|
+
direct_response = response_params['direct_response'] ? parse_direct_response(response_params) : nil
|
781
|
+
if action == :create_customer_profile_transaction
|
782
|
+
auth = direct_response['transaction_id'] if direct_response
|
783
|
+
else
|
784
|
+
auth = response_params['customer_profile_id'] || (response_params['profile'] ? response_params['profile']['customer_profile_id'] : nil)
|
785
|
+
end
|
786
|
+
|
787
|
+
response = Response.new(success, message, response_params,
|
788
|
+
:test => test_mode,
|
789
|
+
:authorization => auth
|
790
|
+
)
|
791
|
+
|
792
|
+
response.params['direct_response'] = direct_response
|
793
|
+
response
|
794
|
+
end
|
795
|
+
|
796
|
+
def tag_unless_blank(xml, tag_name, data)
|
797
|
+
xml.tag!(tag_name, data) unless data.blank? || data.nil?
|
798
|
+
end
|
799
|
+
|
800
|
+
def parse_direct_response(params)
|
801
|
+
direct_response = {'raw' => params['direct_response']}
|
802
|
+
direct_response_fields = params['direct_response'].split(',')
|
803
|
+
|
804
|
+
direct_response.merge(
|
805
|
+
{
|
806
|
+
'response_code' => direct_response_fields[0],
|
807
|
+
'response_subcode' => direct_response_fields[1],
|
808
|
+
'response_reason_code' => direct_response_fields[2],
|
809
|
+
'message' => direct_response_fields[3],
|
810
|
+
'approval_code' => direct_response_fields[4],
|
811
|
+
'avs_response' => direct_response_fields[5],
|
812
|
+
'transaction_id' => direct_response_fields[6],
|
813
|
+
'invoice_number' => direct_response_fields[7],
|
814
|
+
'order_description' => direct_response_fields[8],
|
815
|
+
'amount' => direct_response_fields[9],
|
816
|
+
'method' => direct_response_fields[10],
|
817
|
+
'transaction_type' => direct_response_fields[11],
|
818
|
+
'customer_id' => direct_response_fields[12],
|
819
|
+
'first_name' => direct_response_fields[13],
|
820
|
+
'last_name' => direct_response_fields[14],
|
821
|
+
'company' => direct_response_fields[15],
|
822
|
+
'address' => direct_response_fields[16],
|
823
|
+
'city' => direct_response_fields[17],
|
824
|
+
'state' => direct_response_fields[18],
|
825
|
+
'zip_code' => direct_response_fields[19],
|
826
|
+
'country' => direct_response_fields[20],
|
827
|
+
'phone' => direct_response_fields[21],
|
828
|
+
'fax' => direct_response_fields[22],
|
829
|
+
'email_address' => direct_response_fields[23],
|
830
|
+
'ship_to_first_name' => direct_response_fields[24],
|
831
|
+
'ship_to_last_name' => direct_response_fields[25],
|
832
|
+
'ship_to_company' => direct_response_fields[26],
|
833
|
+
'ship_to_address' => direct_response_fields[27],
|
834
|
+
'ship_to_city' => direct_response_fields[28],
|
835
|
+
'ship_to_state' => direct_response_fields[29],
|
836
|
+
'ship_to_zip_code' => direct_response_fields[30],
|
837
|
+
'ship_to_country' => direct_response_fields[31],
|
838
|
+
'tax' => direct_response_fields[32],
|
839
|
+
'duty' => direct_response_fields[33],
|
840
|
+
'freight' => direct_response_fields[34],
|
841
|
+
'tax_exempt' => direct_response_fields[35],
|
842
|
+
'purchase_order_number' => direct_response_fields[36],
|
843
|
+
'md5_hash' => direct_response_fields[37],
|
844
|
+
'card_code' => direct_response_fields[38],
|
845
|
+
'cardholder_authentication_verification_response' => direct_response_fields[39]
|
846
|
+
}
|
847
|
+
)
|
848
|
+
end
|
849
|
+
|
850
|
+
def parse(action, xml)
|
851
|
+
xml = REXML::Document.new(xml)
|
852
|
+
root = REXML::XPath.first(xml, "//#{CIM_ACTIONS[action]}Response") ||
|
853
|
+
REXML::XPath.first(xml, "//ErrorResponse")
|
854
|
+
if root
|
855
|
+
response = parse_element(root)
|
856
|
+
end
|
857
|
+
|
858
|
+
response
|
859
|
+
end
|
860
|
+
|
861
|
+
def parse_element(node)
|
862
|
+
if node.has_elements?
|
863
|
+
response = {}
|
864
|
+
node.elements.each{ |e|
|
865
|
+
key = e.name.underscore
|
866
|
+
value = parse_element(e)
|
867
|
+
if response.has_key?(key)
|
868
|
+
if response[key].is_a?(Array)
|
869
|
+
response[key].push(value)
|
870
|
+
else
|
871
|
+
response[key] = [response[key], value]
|
872
|
+
end
|
873
|
+
else
|
874
|
+
response[key] = parse_element(e)
|
875
|
+
end
|
876
|
+
}
|
877
|
+
else
|
878
|
+
response = node.text
|
879
|
+
end
|
880
|
+
|
881
|
+
response
|
882
|
+
end
|
883
|
+
end
|
884
|
+
end
|
885
|
+
end
|