start_activemerchant 1.50.0

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