aktivemerchant 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1596 -0
  3. data/CONTRIBUTORS +511 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +18 -0
  6. data/lib/active_merchant.rb +108 -0
  7. data/lib/active_merchant/billing.rb +13 -0
  8. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  9. data/lib/active_merchant/billing/avs_result.rb +98 -0
  10. data/lib/active_merchant/billing/base.rb +72 -0
  11. data/lib/active_merchant/billing/check.rb +76 -0
  12. data/lib/active_merchant/billing/compatibility.rb +120 -0
  13. data/lib/active_merchant/billing/credit_card.rb +352 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +160 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +268 -0
  18. data/lib/active_merchant/billing/gateways.rb +17 -0
  19. data/lib/active_merchant/billing/gateways/adyen.rb +209 -0
  20. data/lib/active_merchant/billing/gateways/alfabank.rb +117 -0
  21. data/lib/active_merchant/billing/gateways/app55.rb +176 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net.rb +419 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  24. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
  25. data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +105 -0
  28. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +314 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream.rb +188 -0
  32. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +393 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +506 -0
  35. data/lib/active_merchant/billing/gateways/bogus.rb +140 -0
  36. data/lib/active_merchant/billing/gateways/borgun.rb +210 -0
  37. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  38. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +515 -0
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
  42. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  43. data/lib/active_merchant/billing/gateways/card_stream.rb +220 -0
  44. data/lib/active_merchant/billing/gateways/cashnet.rb +191 -0
  45. data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
  46. data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
  47. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  48. data/lib/active_merchant/billing/gateways/checkout.rb +213 -0
  49. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  50. data/lib/active_merchant/billing/gateways/conekta.rb +209 -0
  51. data/lib/active_merchant/billing/gateways/cyber_source.rb +709 -0
  52. data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
  53. data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
  54. data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
  55. data/lib/active_merchant/billing/gateways/epay.rb +275 -0
  56. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  57. data/lib/active_merchant/billing/gateways/eway.rb +214 -0
  58. data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
  59. data/lib/active_merchant/billing/gateways/eway_rapid.rb +524 -0
  60. data/lib/active_merchant/billing/gateways/exact.rb +218 -0
  61. data/lib/active_merchant/billing/gateways/fat_zebra.rb +173 -0
  62. data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
  63. data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
  64. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  65. data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
  66. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +355 -0
  67. data/lib/active_merchant/billing/gateways/garanti.rb +257 -0
  68. data/lib/active_merchant/billing/gateways/global_transport.rb +183 -0
  69. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  70. data/lib/active_merchant/billing/gateways/hps.rb +288 -0
  71. data/lib/active_merchant/billing/gateways/iats_payments.rb +251 -0
  72. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
  73. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  74. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  75. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
  76. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  77. data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
  78. data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
  79. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  80. data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
  81. data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
  82. data/lib/active_merchant/billing/gateways/litle.rb +346 -0
  83. data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
  84. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
  85. data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
  86. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  87. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
  88. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
  89. data/lib/active_merchant/billing/gateways/mercury.rb +333 -0
  90. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  91. data/lib/active_merchant/billing/gateways/migs.rb +265 -0
  92. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  93. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  94. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
  95. data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
  96. data/lib/active_merchant/billing/gateways/moneris_us.rb +291 -0
  97. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  98. data/lib/active_merchant/billing/gateways/nab_transact.rb +280 -0
  99. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  100. data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
  101. data/lib/active_merchant/billing/gateways/netbilling.rb +190 -0
  102. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  103. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  104. data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
  105. data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
  106. data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
  107. data/lib/active_merchant/billing/gateways/optimal_payment.rb +313 -0
  108. data/lib/active_merchant/billing/gateways/orbital.rb +803 -0
  109. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  110. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  111. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  112. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +261 -0
  113. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  114. data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
  115. data/lib/active_merchant/billing/gateways/pay_u_latam.rb +462 -0
  116. data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
  117. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  118. data/lib/active_merchant/billing/gateways/payflow.rb +304 -0
  119. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +209 -0
  120. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  121. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  122. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  123. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  124. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  125. data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
  126. data/lib/active_merchant/billing/gateways/paymill.rb +281 -0
  127. data/lib/active_merchant/billing/gateways/paypal.rb +117 -0
  128. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +670 -0
  129. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  130. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  131. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  132. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  133. data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
  134. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  135. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  136. data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
  137. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  138. data/lib/active_merchant/billing/gateways/pin.rb +197 -0
  139. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  140. data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
  141. data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
  142. data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
  143. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  144. data/lib/active_merchant/billing/gateways/quickpay.rb +367 -0
  145. data/lib/active_merchant/billing/gateways/realex.rb +298 -0
  146. data/lib/active_merchant/billing/gateways/redsys.rb +391 -0
  147. data/lib/active_merchant/billing/gateways/sage.rb +175 -0
  148. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +87 -0
  149. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +114 -0
  150. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
  151. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +102 -0
  152. data/lib/active_merchant/billing/gateways/sage_pay.rb +398 -0
  153. data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
  154. data/lib/active_merchant/billing/gateways/secure_net.rb +252 -0
  155. data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
  156. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  157. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
  158. data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
  159. data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
  160. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  161. data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
  162. data/lib/active_merchant/billing/gateways/stripe.rb +411 -0
  163. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
  164. data/lib/active_merchant/billing/gateways/tns.rb +227 -0
  165. data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
  166. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  167. data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
  168. data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
  169. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  170. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
  171. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +254 -0
  172. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  173. data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
  174. data/lib/active_merchant/billing/gateways/vindicia.rb +385 -0
  175. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  176. data/lib/active_merchant/billing/gateways/wepay.rb +189 -0
  177. data/lib/active_merchant/billing/gateways/wirecard.rb +421 -0
  178. data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
  179. data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
  180. data/lib/active_merchant/billing/model.rb +30 -0
  181. data/lib/active_merchant/billing/payment_token.rb +21 -0
  182. data/lib/active_merchant/billing/rails.rb +3 -0
  183. data/lib/active_merchant/billing/response.rb +91 -0
  184. data/lib/active_merchant/country.rb +332 -0
  185. data/lib/active_merchant/empty.rb +20 -0
  186. data/lib/active_merchant/errors.rb +29 -0
  187. data/lib/active_merchant/offsite_payments_shim.rb +19 -0
  188. data/lib/active_merchant/version.rb +3 -0
  189. data/lib/activemerchant.rb +1 -0
  190. data/lib/support/gateway_support.rb +71 -0
  191. data/lib/support/outbound_hosts.rb +25 -0
  192. data/lib/support/ssl_verify.rb +93 -0
  193. metadata +400 -0
@@ -0,0 +1,524 @@
1
+ require 'json'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class EwayRapidGateway < Gateway
6
+ self.test_url = "https://api.sandbox.ewaypayments.com/"
7
+ self.live_url = "https://api.ewaypayments.com/"
8
+
9
+ self.money_format = :cents
10
+ self.supported_countries = ['AU', 'NZ', 'GB']
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
12
+ self.homepage_url = "http://www.eway.com.au/"
13
+ self.display_name = "eWAY Rapid 3.1"
14
+ self.default_currency = "AUD"
15
+
16
+ class_attribute :partner_id
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :login, :password)
20
+ super
21
+ end
22
+
23
+ # Public: Run a purchase transaction.
24
+ #
25
+ # amount - The monetary amount of the transaction in cents.
26
+ # payment_method - The payment method or authorization token returned from store.
27
+ # options - A standard ActiveMerchant options hash:
28
+ # :transaction_type - One of: Purchase (default), MOTO
29
+ # or Recurring. For stored card payments (aka - TokenPayments),
30
+ # this must be either MOTO or Recurring.
31
+ # :order_id - A merchant-supplied identifier for the
32
+ # transaction (optional).
33
+ # :description - A merchant-supplied description of the
34
+ # transaction (optional).
35
+ # :currency - Three letter currency code for the
36
+ # transaction (default: "AUD")
37
+ # :billing_address - Standard ActiveMerchant address hash
38
+ # (optional).
39
+ # :shipping_address - Standard ActiveMerchant address hash
40
+ # (optional).
41
+ # :ip - The ip of the consumer initiating the
42
+ # transaction (optional).
43
+ # :application_id - A string identifying the application
44
+ # submitting the transaction
45
+ # (default: "https://github.com/Shopify/active_merchant")
46
+ #
47
+ # Returns an ActiveMerchant::Billing::Response object where authorization is the Transaction ID on success
48
+ def purchase(amount, payment_method, options={})
49
+ params = {}
50
+ add_metadata(params, options)
51
+ add_invoice(params, amount, options)
52
+ add_customer_data(params, options)
53
+ add_credit_card(params, payment_method, options)
54
+ params['Method'] = payment_method.respond_to?(:number) ? 'ProcessPayment' : 'TokenPayment'
55
+ commit(url_for('Transaction'), params)
56
+ end
57
+
58
+ def authorize(amount, payment_method, options={})
59
+ params = {}
60
+ add_metadata(params, options)
61
+ add_invoice(params, amount, options)
62
+ add_customer_data(params, options)
63
+ add_credit_card(params, payment_method, options)
64
+ params['Method'] = 'Authorise'
65
+ commit(url_for('Authorisation'), params)
66
+ end
67
+
68
+ def capture(amount, identification, options = {})
69
+ params = {}
70
+ add_metadata(params, options)
71
+ add_invoice(params, amount, options)
72
+ add_reference(params, identification)
73
+ commit(url_for("CapturePayment"), params)
74
+ end
75
+
76
+ def void(identification, options = {})
77
+ params = {}
78
+ add_reference(params, identification)
79
+ commit(url_for("CancelAuthorisation"), params)
80
+ end
81
+
82
+ # Public: Refund a transaction.
83
+ #
84
+ # amount - The monetary amount of the transaction in cents
85
+ # identification - The transaction id which is returned in the
86
+ # authorization of the successful purchase transaction
87
+ # options - A standard ActiveMerchant options hash:
88
+ # :order_id - A merchant-supplied identifier for the
89
+ # transaction (optional).
90
+ # :description - A merchant-supplied description of the
91
+ # transaction (optional).
92
+ # :currency - Three letter currency code for the
93
+ # transaction (default: "AUD")
94
+ # :billing_address - Standard ActiveMerchant address hash
95
+ # (optional).
96
+ # :shipping_address - Standard ActiveMerchant address hash
97
+ # (optional).
98
+ # :ip - The ip of the consumer initiating the
99
+ # transaction (optional).
100
+ # :application_id - A string identifying the application
101
+ # submitting the transaction
102
+ # (default: "https://github.com/Shopify/active_merchant")
103
+ #
104
+ # Returns an ActiveMerchant::Billing::Response object
105
+ def refund(amount, identification, options = {})
106
+ params = {}
107
+ add_metadata(params, options)
108
+ add_invoice(params, amount, options, "Refund")
109
+ add_reference(params["Refund"], identification)
110
+ add_customer_data(params, options)
111
+ commit(url_for("Transaction/#{identification}/Refund"), params)
112
+ end
113
+
114
+ # Public: Store card details and return a valid token
115
+ #
116
+ # payment_method - The payment method or nil if :customer_token is provided
117
+ # options - A supplemented ActiveMerchant options hash:
118
+ # :order_id - A merchant-supplied identifier for the
119
+ # transaction (optional).
120
+ # :description - A merchant-supplied description of the
121
+ # transaction (optional).
122
+ # :billing_address - Standard ActiveMerchant address hash
123
+ # (required).
124
+ # :ip - The ip of the consumer initiating the
125
+ # transaction (optional).
126
+ # :application_id - A string identifying the application
127
+ # submitting the transaction
128
+ # (default: "https://github.com/Shopify/active_merchant")
129
+ #
130
+ # Returns an ActiveMerchant::Billing::Response object where the authorization is the customer_token on success
131
+ def store(payment_method, options = {})
132
+ requires!(options, :billing_address)
133
+ params = {}
134
+ add_metadata(params, options)
135
+ add_invoice(params, 0, options)
136
+ add_customer_data(params, options)
137
+ add_credit_card(params, payment_method, options)
138
+ params['Method'] = 'CreateTokenCustomer'
139
+ commit(url_for("Transaction"), params)
140
+ end
141
+
142
+ # Public: Update a customer's data
143
+ #
144
+ # customer_token - The customer token returned in the authorization of
145
+ # a successful store transaction.
146
+ # payment_method - The payment method or nil if :customer_token is provided
147
+ # options - A supplemented ActiveMerchant options hash:
148
+ # :order_id - A merchant-supplied identifier for the
149
+ # transaction (optional).
150
+ # :description - A merchant-supplied description of the
151
+ # transaction (optional).
152
+ # :billing_address - Standard ActiveMerchant address hash
153
+ # (optional).
154
+ # :ip - The ip of the consumer initiating the
155
+ # transaction (optional).
156
+ # :application_id - A string identifying the application
157
+ # submitting the transaction
158
+ # (default: "https://github.com/Shopify/active_merchant")
159
+ #
160
+ # Returns an ActiveMerchant::Billing::Response object where the authorization is the customer_token on success
161
+ def update(customer_token, payment_method, options = {})
162
+ params = {}
163
+ add_metadata(params, options)
164
+ add_invoice(params, 0, options)
165
+ add_customer_data(params, options)
166
+ add_credit_card(params, payment_method, options)
167
+ add_customer_token(params, customer_token)
168
+ params['Method'] = 'UpdateTokenCustomer'
169
+ commit(url_for("Transaction"), params)
170
+ end
171
+
172
+ private
173
+
174
+ def add_metadata(params, options)
175
+ params['RedirectUrl'] = options[:redirect_url] || 'http://example.com'
176
+ params['CustomerIP'] = options[:ip] if options[:ip]
177
+ params['TransactionType'] = options[:transaction_type] || 'Purchase'
178
+ params['DeviceID'] = options[:application_id] || application_id
179
+ if partner = options[:partner_id] || partner_id
180
+ params['PartnerID'] = truncate(partner, 50)
181
+ end
182
+ params
183
+ end
184
+
185
+ def add_invoice(params, money, options, key = "Payment")
186
+ currency_code = options[:currency] || currency(money)
187
+ params[key] = {
188
+ 'TotalAmount' => localized_amount(money, currency_code),
189
+ 'InvoiceReference' => truncate(options[:order_id]),
190
+ 'InvoiceDescription' => truncate(options[:description], 64),
191
+ 'CurrencyCode' => currency_code,
192
+ }
193
+ end
194
+
195
+ def add_reference(params, reference)
196
+ params['TransactionID'] = reference
197
+ end
198
+
199
+ def add_customer_data(params, options)
200
+ params['Customer'] ||= {}
201
+ add_address(params['Customer'], (options[:billing_address] || options[:address]), {:email => options[:email]})
202
+ params['ShippingAddress'] = {}
203
+ add_address(params['ShippingAddress'], options[:shipping_address], {:skip_company => true})
204
+ end
205
+
206
+ def add_address(params, address, options={})
207
+ return unless address
208
+
209
+ if address[:name]
210
+ parts = address[:name].split(/\s+/)
211
+ params['FirstName'] = parts.shift if parts.size > 1
212
+ params['LastName'] = parts.join(" ")
213
+ end
214
+ params['Title'] = address[:title]
215
+ params['CompanyName'] = address[:company] unless options[:skip_company]
216
+ params['Street1'] = truncate(address[:address1])
217
+ params['Street2'] = truncate(address[:address2])
218
+ params['City'] = truncate(address[:city])
219
+ params['State'] = address[:state]
220
+ params['PostalCode'] = address[:zip]
221
+ params['Country'] = address[:country].to_s.downcase
222
+ params['Phone'] = address[:phone]
223
+ params['Fax'] = address[:fax]
224
+ params['Email'] = options[:email]
225
+ end
226
+
227
+ def add_credit_card(params, credit_card, options)
228
+ return unless credit_card
229
+ params['Customer'] ||= {}
230
+ if credit_card.respond_to? :number
231
+ card_details = params['Customer']['CardDetails'] = {}
232
+ card_details['Name'] = truncate(credit_card.name)
233
+ card_details['Number'] = credit_card.number
234
+ card_details['ExpiryMonth'] = "%02d" % (credit_card.month || 0)
235
+ card_details['ExpiryYear'] = "%02d" % (credit_card.year || 0)
236
+ card_details['CVN'] = credit_card.verification_value
237
+ else
238
+ add_customer_token(params, credit_card)
239
+ end
240
+ end
241
+
242
+ def add_customer_token(params, token)
243
+ params['Customer'] ||= {}
244
+ params['Customer']['TokenCustomerID'] = token
245
+ end
246
+
247
+ def url_for(action)
248
+ (test? ? test_url : live_url) + action
249
+ end
250
+
251
+ def commit(url, params)
252
+ headers = {
253
+ "Authorization" => ("Basic " + Base64.strict_encode64(@options[:login].to_s + ":" + @options[:password].to_s).chomp),
254
+ "Content-Type" => "application/json"
255
+ }
256
+ request = params.to_json
257
+ raw = parse(ssl_post(url, request, headers))
258
+
259
+ succeeded = success?(raw)
260
+ ActiveMerchant::Billing::Response.new(
261
+ succeeded,
262
+ message_from(succeeded, raw),
263
+ raw,
264
+ :authorization => authorization_from(raw),
265
+ :test => test?,
266
+ :avs_result => avs_result_from(raw),
267
+ :cvv_result => cvv_result_from(raw)
268
+ )
269
+ rescue ActiveMerchant::ResponseError => e
270
+ return ActiveMerchant::Billing::Response.new(false, e.response.message, {:status_code => e.response.code}, :test => test?)
271
+ end
272
+
273
+ def parse(data)
274
+ JSON.parse(data)
275
+ end
276
+
277
+ def success?(response)
278
+ if response['ResponseCode'] == "00"
279
+ true
280
+ elsif response['TransactionStatus']
281
+ (response['TransactionStatus'] == true)
282
+ elsif response["Succeeded"]
283
+ (response["Succeeded"] == true)
284
+ else
285
+ false
286
+ end
287
+ end
288
+
289
+ def parse_errors(message)
290
+ errors = message.split(',').collect{|code| MESSAGES[code.strip]}.flatten.join(',')
291
+ errors.presence || message
292
+ end
293
+
294
+ def message_from(succeeded, response)
295
+ if response['Errors']
296
+ parse_errors(response['Errors'])
297
+ elsif response['ResponseMessage']
298
+ parse_errors(response['ResponseMessage'])
299
+ elsif response['ResponseCode']
300
+ ActiveMerchant::Billing::EwayGateway::MESSAGES[response['ResponseCode']]
301
+ elsif succeeded
302
+ "Succeeded"
303
+ else
304
+ "Failed"
305
+ end
306
+ end
307
+
308
+ def authorization_from(response)
309
+ # Note: TransactionID is always null for store requests, but TokenCustomerID is also sent back for purchase from
310
+ # stored card transactions so we give precendence to TransactionID
311
+ response['TransactionID'] || response['Customer']['TokenCustomerID']
312
+ end
313
+
314
+ def avs_result_from(response)
315
+ verification = response['Verification'] || {}
316
+ code = case verification['Address']
317
+ when "Valid"
318
+ "M"
319
+ when "Invalid"
320
+ "N"
321
+ else
322
+ "I"
323
+ end
324
+ {:code => code}
325
+ end
326
+
327
+ def cvv_result_from(response)
328
+ verification = response['Verification'] || {}
329
+ case verification['CVN']
330
+ when "Valid"
331
+ "M"
332
+ when "Invalid"
333
+ "N"
334
+ else
335
+ "P"
336
+ end
337
+ end
338
+
339
+ def truncate(value, max_size = 50)
340
+ return nil unless value
341
+ value.to_s[0, max_size]
342
+ end
343
+
344
+ MESSAGES = {
345
+ 'A2000' => 'Transaction Approved Successful',
346
+ 'A2008' => 'Honour With Identification Successful',
347
+ 'A2010' => 'Approved For Partial Amount Successful',
348
+ 'A2011' => 'Approved, VIP Successful',
349
+ 'A2016' => 'Approved, Update Track 3 Successful',
350
+ 'D4401' => 'Refer to Issuer Failed',
351
+ 'D4402' => 'Refer to Issuer, special Failed',
352
+ 'D4403' => 'No Merchant Failed',
353
+ 'D4404' => 'Pick Up Card Failed',
354
+ 'D4405' => 'Do Not Honour Failed',
355
+ 'D4406' => 'Error Failed',
356
+ 'D4407' => 'Pick Up Card, Special Failed',
357
+ 'D4409' => 'Request In Progress Failed',
358
+ 'D4412' => 'Invalid Transaction Failed',
359
+ 'D4413' => 'Invalid Amount Failed',
360
+ 'D4414' => 'Invalid Card Number Failed',
361
+ 'D4415' => 'No Issuer Failed',
362
+ 'D4419' => 'Re-enter Last Transaction Failed',
363
+ 'D4421' => 'No Action Taken Failed',
364
+ 'D4422' => 'Suspected Malfunction Failed',
365
+ 'D4423' => 'Unacceptable Transaction Fee Failed',
366
+ 'D4425' => 'Unable to Locate Record On File Failed',
367
+ 'D4430' => 'Format Error Failed ',
368
+ 'D4431' => 'Bank Not Supported By Switch Failed',
369
+ 'D4433' => 'Expired Card, Capture Failed ',
370
+ 'D4434' => 'Suspected Fraud, Retain Card Failed',
371
+ 'D4435' => 'Card Acceptor, Contact Acquirer, Retain Card Failed',
372
+ 'D4436' => 'Restricted Card, Retain Card Failed',
373
+ 'D4437' => 'Contact Acquirer Security Department, Retain Card Failed',
374
+ 'D4438' => 'PIN Tries Exceeded, Capture Failed',
375
+ 'D4439' => 'No Credit Account Failed',
376
+ 'D4440' => 'Function Not Supported Failed',
377
+ 'D4441' => 'Lost Card Failed',
378
+ 'D4442' => 'No Universal Account Failed',
379
+ 'D4443' => 'Stolen Card Failed',
380
+ 'D4444' => 'No Investment Account Failed',
381
+ 'D4451' => 'Insufficient Funds Failed',
382
+ 'D4452' => 'No Cheque Account Failed',
383
+ 'D4453' => 'No Savings Account Failed',
384
+ 'D4454' => 'Expired Card Failed',
385
+ 'D4455' => 'Incorrect PIN Failed',
386
+ 'D4456' => 'No Card Record Failed',
387
+ 'D4457' => 'Function Not Permitted to Cardholder Failed',
388
+ 'D4458' => 'Function Not Permitted to Terminal Failed',
389
+ 'D4459' => 'Suspected Fraud Failed',
390
+ 'D4460' => 'Acceptor Contact Acquirer Failed',
391
+ 'D4461' => 'Exceeds Withdrawal Limit Failed',
392
+ 'D4462' => 'Restricted Card Failed',
393
+ 'D4463' => 'Security Violation Failed',
394
+ 'D4464' => 'Original Amount Incorrect Failed',
395
+ 'D4466' => 'Acceptor Contact Acquirer, Security Failed',
396
+ 'D4467' => 'Capture Card Failed',
397
+ 'D4475' => 'PIN Tries Exceeded Failed',
398
+ 'D4482' => 'CVV Validation Error Failed',
399
+ 'D4490' => 'Cut off In Progress Failed',
400
+ 'D4491' => 'Card Issuer Unavailable Failed',
401
+ 'D4492' => 'Unable To Route Transaction Failed',
402
+ 'D4493' => 'Cannot Complete, Violation Of The Law Failed',
403
+ 'D4494' => 'Duplicate Transaction Failed',
404
+ 'D4496' => 'System Error Failed',
405
+ 'D4497' => 'MasterPass Error Failed',
406
+ 'D4498' => 'PayPal Create Transaction Error Failed',
407
+ 'D4499' => 'Invalid Transaction for Auth/Void Failed',
408
+ 'S5000' => 'System Error',
409
+ 'S5085' => 'Started 3dSecure',
410
+ 'S5086' => 'Routed 3dSecure',
411
+ 'S5087' => 'Completed 3dSecure',
412
+ 'S5088' => 'PayPal Transaction Created',
413
+ 'S5099' => 'Incomplete (Access Code in progress/incomplete)',
414
+ 'S5010' => 'Unknown error returned by gateway',
415
+ 'V6000' => 'Validation error',
416
+ 'V6001' => 'Invalid CustomerIP',
417
+ 'V6002' => 'Invalid DeviceID',
418
+ 'V6003' => 'Invalid Request PartnerID',
419
+ 'V6004' => 'Invalid Request Method',
420
+ 'V6010' => 'Invalid TransactionType, account not certified for eCome only MOTO or Recurring available',
421
+ 'V6011' => 'Invalid Payment TotalAmount',
422
+ 'V6012' => 'Invalid Payment InvoiceDescription',
423
+ 'V6013' => 'Invalid Payment InvoiceNumber',
424
+ 'V6014' => 'Invalid Payment InvoiceReference',
425
+ 'V6015' => 'Invalid Payment CurrencyCode',
426
+ 'V6016' => 'Payment Required',
427
+ 'V6017' => 'Payment CurrencyCode Required',
428
+ 'V6018' => 'Unknown Payment CurrencyCode',
429
+ 'V6021' => 'EWAY_CARDHOLDERNAME Required',
430
+ 'V6022' => 'EWAY_CARDNUMBER Required',
431
+ 'V6023' => 'EWAY_CARDCVN Required',
432
+ 'V6033' => 'Invalid Expiry Date',
433
+ 'V6034' => 'Invalid Issue Number',
434
+ 'V6035' => 'Invalid Valid From Date',
435
+ 'V6040' => 'Invalid TokenCustomerID',
436
+ 'V6041' => 'Customer Required',
437
+ 'V6042' => 'Customer FirstName Required',
438
+ 'V6043' => 'Customer LastName Required',
439
+ 'V6044' => 'Customer CountryCode Required',
440
+ 'V6045' => 'Customer Title Required ',
441
+ 'V6046' => 'TokenCustomerID Required',
442
+ 'V6047' => 'RedirectURL Required',
443
+ 'V6048' => 'Invalid Checkout URL',
444
+ 'V6051' => 'Invalid Customer FirstName',
445
+ 'V6052' => 'Invalid Customer LastName',
446
+ 'V6053' => 'Invalid Customer CountryCode',
447
+ 'V6058' => 'Invalid Customer Title ',
448
+ 'V6059' => 'Invalid RedirectURL',
449
+ 'V6060' => 'Invalid TokenCustomerID',
450
+ 'V6061' => 'Invalid Customer Reference',
451
+ 'V6062' => 'Invalid Customer CompanyName',
452
+ 'V6063' => 'Invalid Customer JobDescription',
453
+ 'V6064' => 'Invalid Customer Street1',
454
+ 'V6065' => 'Invalid Customer Street2',
455
+ 'V6066' => 'Invalid Customer City',
456
+ 'V6067' => 'Invalid Customer State',
457
+ 'V6068' => 'Invalid Customer PostalCode',
458
+ 'V6069' => 'Invalid Customer Email ',
459
+ 'V6070' => 'Invalid Customer Phone',
460
+ 'V6071' => 'Invalid Customer Mobile',
461
+ 'V6072' => 'Invalid Customer Comments',
462
+ 'V6073' => 'Invalid Customer Fax',
463
+ 'V6074' => 'Invalid Customer URL',
464
+ 'V6075' => 'Invalid ShippingAddress FirstName',
465
+ 'V6076' => 'Invalid ShippingAddress LastName',
466
+ 'V6077' => 'Invalid ShippingAddress Street1',
467
+ 'V6078' => 'Invalid ShippingAddress Street2',
468
+ 'V6079' => 'Invalid ShippingAddress City',
469
+ 'V6080' => 'Invalid ShippingAddress State',
470
+ 'V6081' => 'Invalid ShippingAddress PostalCode',
471
+ 'V6082' => 'Invalid ShippingAddress Email',
472
+ 'V6083' => 'Invalid ShippingAddress Phone',
473
+ 'V6084' => 'Invalid ShippingAddress Country',
474
+ 'V6085' => 'Invalid ShippingAddress ShippingMethod',
475
+ 'V6086' => 'Invalid ShippingAddress Fax',
476
+ 'V6091' => 'Unknown Customer CountryCode',
477
+ 'V6092' => 'Unknown ShippingAddress CountryCode',
478
+ 'V6100' => 'Invalid EWAY_CARDNAME',
479
+ 'V6101' => 'Invalid EWAY_CARDEXPIRYMONTH',
480
+ 'V6102' => 'Invalid EWAY_CARDEXPIRYYEAR ',
481
+ 'V6103' => 'Invalid EWAY_CARDSTARTMONTH',
482
+ 'V6104' => 'Invalid EWAY_CARDSTARTYEAR',
483
+ 'V6105' => 'Invalid EWAY_CARDISSUENUMBER ',
484
+ 'V6106' => 'Invalid EWAY_CARDCVN',
485
+ 'V6107' => 'Invalid EWAY_ACCESSCODE',
486
+ 'V6108' => 'Invalid CustomerHostAddress',
487
+ 'V6109' => 'Invalid UserAgent',
488
+ 'V6110' => 'Invalid EWAY_CARDNUMBER',
489
+ 'V6111' => 'Unauthorised API Access, Account Not PCI Certified',
490
+ 'V6112' => 'Redundant card details other than expiry year and month',
491
+ 'V6113' => 'Invalid transaction for refund',
492
+ 'V6114' => 'Gateway validation error',
493
+ 'V6115' => 'Invalid DirectRefundRequest, Transaction ID',
494
+ 'V6116' => 'Invalid card data on original TransactionID',
495
+ 'V6117' => 'Invalid CreateAccessCodeSharedRequest, FooterText',
496
+ 'V6118' => 'Invalid CreateAccessCodeSharedRequest, HeaderText',
497
+ 'V6119' => 'Invalid CreateAccessCodeSharedRequest, Language',
498
+ 'V6120' => 'Invalid CreateAccessCodeSharedRequest, LogoUrl ',
499
+ 'V6121' => 'Invalid TransactionSearch, Filter Match Type',
500
+ 'V6122' => 'Invalid TransactionSearch, Non numeric Transaction ID',
501
+ 'V6123' => 'Invalid TransactionSearch,no TransactionID or AccessCode specified',
502
+ 'V6124' => 'Invalid Line Items. The line items have been provided however the totals do not match the TotalAmount field',
503
+ 'V6125' => 'Selected Payment Type not enabled',
504
+ 'V6126' => 'Invalid encrypted card number, decryption failed',
505
+ 'V6127' => 'Invalid encrypted cvn, decryption failed',
506
+ 'V6128' => 'Invalid Method for Payment Type',
507
+ 'V6129' => 'Transaction has not been authorised for Capture/Cancellation',
508
+ 'V6130' => 'Generic customer information error ',
509
+ 'V6131' => 'Generic shipping information error',
510
+ 'V6132' => 'Transaction has already been completed or voided, operation not permitted',
511
+ 'V6133' => 'Checkout not available for Payment Type',
512
+ 'V6134' => 'Invalid Auth Transaction ID for Capture/Void',
513
+ 'V6135' => 'PayPal Error Processing Refund',
514
+ 'V6140' => 'Merchant account is suspended',
515
+ 'V6141' => 'Invalid PayPal account details or API signature',
516
+ 'V6142' => 'Authorise not available for Bank/Branch',
517
+ 'V6150' => 'Invalid Refund Amount',
518
+ 'V6151' => 'Refund amount greater than original transaction',
519
+ 'V6152' => 'Original transaction already refunded for total amount',
520
+ 'V6153' => 'Card type not support by merchant',
521
+ }
522
+ end
523
+ end
524
+ end