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,192 @@
1
+ require 'active_merchant/billing/gateways/beanstream/beanstream_core'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # This class implements the Canadian {Beanstream}[http://www.beanstream.com] payment gateway.
6
+ # It is also named TD Canada Trust Online Mart payment gateway.
7
+ # To learn more about the specification of Beanstream gateway, please read the OM_Direct_Interface_API.pdf,
8
+ # which you can get from your Beanstream account or get from me by email.
9
+ #
10
+ # == Supported transaction types by Beanstream:
11
+ # * +P+ - Purchase
12
+ # * +PA+ - Pre Authorization
13
+ # * +PAC+ - Pre Authorization Completion
14
+ #
15
+ # == Secure Payment Profiles:
16
+ # BeanStream supports payment profiles (vaults). This allows you to store cc information with BeanStream and process subsequent transactions with a customer id.
17
+ # Secure Payment Profiles must be enabled on your account (must be done over the phone).
18
+ # Your API Access Passcode must be set in Administration => account settings => order settings.
19
+ # To learn more about storing credit cards with the Beanstream gateway, documentation can be found at http://developer.beanstream.com/documentation/classic-apis
20
+ #
21
+ # To store a credit card using Beanstream's Legato Javascript Library (http://developer.beanstream.com/documentation/legato) you must pass the singleUseToken in
22
+ # the store method's option parameter. Example: @gateway.store("gt6-0c78c25b-3637-4ba0-90e2-26105287f198")
23
+ #
24
+ # == Notes
25
+ # * Adding of order products information is not implemented.
26
+ # * Ensure that country and province data is provided as a code such as "CA", "US", "QC".
27
+ # * login is the Beanstream merchant ID, username and password should be enabled in your Beanstream account and passed in using the <tt>:user</tt> and <tt>:password</tt> options.
28
+ # * Test your app with your true merchant id and test credit card information provided in the api pdf document.
29
+ # * Beanstream does not allow Payment Profiles to be deleted with their API. The accounts are 'closed', but have to be deleted manually.
30
+ #
31
+ # Example authorization (Beanstream PA transaction type):
32
+ #
33
+ # twenty = 2000
34
+ # gateway = BeanstreamGateway.new(
35
+ # :login => '100200000',
36
+ # :user => 'xiaobozz',
37
+ # :password => 'password'
38
+ # )
39
+ #
40
+ # credit_card = CreditCard.new(
41
+ # :number => '4030000010001234',
42
+ # :month => 8,
43
+ # :year => 2011,
44
+ # :first_name => 'xiaobo',
45
+ # :last_name => 'zzz',
46
+ # :verification_value => 137
47
+ # )
48
+ # response = gateway.authorize(twenty, credit_card,
49
+ # :order_id => '1234',
50
+ # :billing_address => {
51
+ # :name => 'xiaobo zzz',
52
+ # :phone => '555-555-5555',
53
+ # :address1 => '1234 Levesque St.',
54
+ # :address2 => 'Apt B',
55
+ # :city => 'Montreal',
56
+ # :state => 'QC',
57
+ # :country => 'CA',
58
+ # :zip => 'H2C1X8'
59
+ # },
60
+ # :email => 'xiaobozzz@example.com',
61
+ # :subtotal => 800,
62
+ # :shipping => 100,
63
+ # :tax1 => 100,
64
+ # :tax2 => 100,
65
+ # :custom => 'reference one'
66
+ # )
67
+ class BeanstreamGateway < Gateway
68
+ include BeanstreamCore
69
+
70
+ def authorize(money, source, options = {})
71
+ post = {}
72
+ add_amount(post, money)
73
+ add_invoice(post, options)
74
+ add_source(post, source)
75
+ add_address(post, options)
76
+ add_transaction_type(post, :authorization)
77
+ add_customer_ip(post, options)
78
+ commit(post)
79
+ end
80
+
81
+ def purchase(money, source, options = {})
82
+ post = {}
83
+ add_amount(post, money)
84
+ add_invoice(post, options)
85
+ add_source(post, source)
86
+ add_address(post, options)
87
+ add_transaction_type(post, purchase_action(source))
88
+ add_customer_ip(post, options)
89
+ commit(post)
90
+ end
91
+
92
+ def void(authorization, options = {})
93
+ reference, amount, type = split_auth(authorization)
94
+
95
+ post = {}
96
+ add_reference(post, reference)
97
+ add_original_amount(post, amount)
98
+ add_transaction_type(post, void_action(type))
99
+ commit(post)
100
+ end
101
+
102
+ def success?(response)
103
+ response[:trnApproved] == '1' || response[:responseCode] == '1'
104
+ end
105
+
106
+ def recurring(money, source, options = {})
107
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
108
+
109
+ post = {}
110
+ add_amount(post, money)
111
+ add_invoice(post, options)
112
+ add_credit_card(post, source)
113
+ add_address(post, options)
114
+ add_transaction_type(post, purchase_action(source))
115
+ add_recurring_type(post, options)
116
+ commit(post)
117
+ end
118
+
119
+ def update_recurring(amount, source, options = {})
120
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
121
+
122
+ post = {}
123
+ add_recurring_amount(post, amount)
124
+ add_recurring_invoice(post, options)
125
+ add_credit_card(post, source)
126
+ add_address(post, options)
127
+ add_recurring_operation_type(post, :update)
128
+ add_recurring_service(post, options)
129
+ recurring_commit(post)
130
+ end
131
+
132
+ def cancel_recurring(options = {})
133
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
134
+
135
+ post = {}
136
+ add_recurring_operation_type(post, :cancel)
137
+ add_recurring_service(post, options)
138
+ recurring_commit(post)
139
+ end
140
+
141
+ def interac
142
+ @interac ||= BeanstreamInteracGateway.new(@options)
143
+ end
144
+
145
+ # To match the other stored-value gateways, like TrustCommerce,
146
+ # store and unstore need to be defined
147
+ def store(payment_method, options = {})
148
+ post = {}
149
+ add_address(post, options)
150
+
151
+ if payment_method.respond_to?(:number)
152
+ add_credit_card(post, payment_method)
153
+ else
154
+ post[:singleUseToken] = payment_method
155
+ end
156
+ add_secure_profile_variables(post, options)
157
+
158
+ commit(post, true)
159
+ end
160
+
161
+ #can't actually delete a secure profile with the supplicated API. This function sets the status of the profile to closed (C).
162
+ #Closed profiles will have to removed manually.
163
+ def delete(vault_id)
164
+ update(vault_id, false, {:status => "C"})
165
+ end
166
+
167
+ alias_method :unstore, :delete
168
+
169
+ # Update the values (such as CC expiration) stored at
170
+ # the gateway. The CC number must be supplied in the
171
+ # CreditCard object.
172
+ def update(vault_id, payment_method, options = {})
173
+ post = {}
174
+ add_address(post, options)
175
+ if payment_method.respond_to?(:number)
176
+ add_credit_card(post, payment_method)
177
+ else
178
+ post[:singleUseToken] = payment_method
179
+ end
180
+ options.merge!({:vault_id => vault_id, :operation => secure_profile_action(:modify)})
181
+ add_secure_profile_variables(post,options)
182
+ commit(post, true)
183
+ end
184
+
185
+ private
186
+ def build_response(*args)
187
+ Response.new(*args)
188
+ end
189
+ end
190
+ end
191
+ end
192
+
@@ -0,0 +1,389 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module BeanstreamCore
4
+ RECURRING_URL = 'https://www.beanstream.com/scripts/recurring_billing.asp'
5
+ SECURE_PROFILE_URL = 'https://www.beanstream.com/scripts/payment_profile.asp'
6
+
7
+ SP_SERVICE_VERSION = '1.1'
8
+
9
+ TRANSACTIONS = {
10
+ :authorization => 'PA',
11
+ :purchase => 'P',
12
+ :capture => 'PAC',
13
+ :refund => 'R',
14
+ :void => 'VP',
15
+ :check_purchase => 'D',
16
+ :check_refund => 'C',
17
+ :void_purchase => 'VP',
18
+ :void_refund => 'VR'
19
+ }
20
+
21
+ PROFILE_OPERATIONS = {
22
+ :new => 'N',
23
+ :modify => 'M'
24
+ }
25
+
26
+ CVD_CODES = {
27
+ '1' => 'M',
28
+ '2' => 'N',
29
+ '3' => 'I',
30
+ '4' => 'S',
31
+ '5' => 'U',
32
+ '6' => 'P'
33
+ }
34
+
35
+ AVS_CODES = {
36
+ '0' => 'R',
37
+ '5' => 'I',
38
+ '9' => 'I'
39
+ }
40
+
41
+ PERIODS = {
42
+ :days => 'D',
43
+ :weeks => 'W',
44
+ :months => 'M',
45
+ :years => 'Y'
46
+ }
47
+
48
+ PERIODICITIES = {
49
+ :daily => [:days, 1],
50
+ :weekly => [:weeks, 1],
51
+ :biweekly => [:weeks, 2],
52
+ :monthly => [:months, 1],
53
+ :bimonthly => [:months, 2],
54
+ :yearly => [:years, 1]
55
+ }
56
+
57
+ RECURRING_OPERATION = {
58
+ :update => 'M',
59
+ :cancel => 'C'
60
+ }
61
+
62
+ def self.included(base)
63
+ base.default_currency = 'CAD'
64
+
65
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
66
+ base.supported_countries = ['CA', 'US']
67
+
68
+ # The card types supported by the payment gateway
69
+ base.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
70
+
71
+ # The homepage URL of the gateway
72
+ base.homepage_url = 'http://www.beanstream.com/'
73
+ base.live_url = 'https://www.beanstream.com/scripts/process_transaction.asp'
74
+
75
+ # The name of the gateway
76
+ base.display_name = 'Beanstream.com'
77
+ end
78
+
79
+ # Only <tt>:login</tt> is required by default,
80
+ # which is the merchant's merchant ID. If you'd like to perform void,
81
+ # capture or refund transactions then you'll also need to add a username
82
+ # and password to your account under administration -> account settings ->
83
+ # order settings -> Use username/password validation
84
+ def initialize(options = {})
85
+ requires!(options, :login)
86
+ super
87
+ end
88
+
89
+ def capture(money, authorization, options = {})
90
+ reference, _, _ = split_auth(authorization)
91
+
92
+ post = {}
93
+ add_amount(post, money)
94
+ add_reference(post, reference)
95
+ add_transaction_type(post, :capture)
96
+ commit(post)
97
+ end
98
+
99
+ def refund(money, source, options = {})
100
+ post = {}
101
+ reference, _, type = split_auth(source)
102
+ add_reference(post, reference)
103
+ add_transaction_type(post, refund_action(type))
104
+ add_amount(post, money)
105
+ commit(post)
106
+ end
107
+
108
+ def credit(money, source, options = {})
109
+ ActiveMerchant.deprecated Gateway::CREDIT_DEPRECATION_MESSAGE
110
+ refund(money, source, options)
111
+ end
112
+
113
+ private
114
+ def purchase_action(source)
115
+ if source.is_a?(Check)
116
+ :check_purchase
117
+ else
118
+ :purchase
119
+ end
120
+ end
121
+
122
+ def add_customer_ip(post, options)
123
+ post[:customerIP] = options[:ip] if options[:ip]
124
+ end
125
+
126
+ def void_action(original_transaction_type)
127
+ (original_transaction_type == TRANSACTIONS[:refund]) ? :void_refund : :void_purchase
128
+ end
129
+
130
+ def refund_action(type)
131
+ (type == TRANSACTIONS[:check_purchase]) ? :check_refund : :refund
132
+ end
133
+
134
+ def secure_profile_action(type)
135
+ PROFILE_OPERATIONS[type] || PROFILE_OPERATIONS[:new]
136
+ end
137
+
138
+ def split_auth(string)
139
+ string.split(";")
140
+ end
141
+
142
+ def add_amount(post, money)
143
+ post[:trnAmount] = amount(money)
144
+ end
145
+
146
+ def add_original_amount(post, amount)
147
+ post[:trnAmount] = amount
148
+ end
149
+
150
+ def add_reference(post, reference)
151
+ post[:adjId] = reference
152
+ end
153
+
154
+ def add_address(post, options)
155
+ prepare_address_for_non_american_countries(options)
156
+
157
+ if billing_address = options[:billing_address] || options[:address]
158
+ post[:ordName] = billing_address[:name]
159
+ post[:ordEmailAddress] = options[:email]
160
+ post[:ordPhoneNumber] = billing_address[:phone]
161
+ post[:ordAddress1] = billing_address[:address1]
162
+ post[:ordAddress2] = billing_address[:address2]
163
+ post[:ordCity] = billing_address[:city]
164
+ post[:ordProvince] = billing_address[:state]
165
+ post[:ordPostalCode] = billing_address[:zip]
166
+ post[:ordCountry] = billing_address[:country]
167
+ end
168
+ if shipping_address = options[:shipping_address]
169
+ post[:shipName] = shipping_address[:name]
170
+ post[:shipEmailAddress] = options[:email]
171
+ post[:shipPhoneNumber] = shipping_address[:phone]
172
+ post[:shipAddress1] = shipping_address[:address1]
173
+ post[:shipAddress2] = shipping_address[:address2]
174
+ post[:shipCity] = shipping_address[:city]
175
+ post[:shipProvince] = shipping_address[:state]
176
+ post[:shipPostalCode] = shipping_address[:zip]
177
+ post[:shipCountry] = shipping_address[:country]
178
+ post[:shippingMethod] = shipping_address[:shipping_method]
179
+ post[:deliveryEstimate] = shipping_address[:delivery_estimate]
180
+ end
181
+ end
182
+
183
+ def prepare_address_for_non_american_countries(options)
184
+ [ options[:billing_address], options[:shipping_address] ].compact.each do |address|
185
+ unless ['US', 'CA'].include?(address[:country])
186
+ address[:state] = '--'
187
+ address[:zip] = '000000' unless address[:zip]
188
+ end
189
+ end
190
+ end
191
+
192
+ def add_invoice(post, options)
193
+ post[:trnOrderNumber] = options[:order_id]
194
+ post[:trnComments] = options[:description]
195
+ post[:ordItemPrice] = amount(options[:subtotal])
196
+ post[:ordShippingPrice] = amount(options[:shipping])
197
+ post[:ordTax1Price] = amount(options[:tax1] || options[:tax])
198
+ post[:ordTax2Price] = amount(options[:tax2])
199
+ post[:ref1] = options[:custom]
200
+ end
201
+
202
+ def add_credit_card(post, credit_card)
203
+ if credit_card
204
+ post[:trnCardOwner] = credit_card.name
205
+ post[:trnCardNumber] = credit_card.number
206
+ post[:trnExpMonth] = format(credit_card.month, :two_digits)
207
+ post[:trnExpYear] = format(credit_card.year, :two_digits)
208
+ post[:trnCardCvd] = credit_card.verification_value
209
+ end
210
+ end
211
+
212
+ def add_check(post, check)
213
+ # The institution number of the consumer’s financial institution. Required for Canadian dollar EFT transactions.
214
+ post[:institutionNumber] = check.institution_number
215
+
216
+ # The bank transit number of the consumer’s bank account. Required for Canadian dollar EFT transactions.
217
+ post[:transitNumber] = check.transit_number
218
+
219
+ # The routing number of the consumer’s bank account. Required for US dollar EFT transactions.
220
+ post[:routingNumber] = check.routing_number
221
+
222
+ # The account number of the consumer’s bank account. Required for both Canadian and US dollar EFT transactions.
223
+ post[:accountNumber] = check.account_number
224
+ end
225
+
226
+ def add_secure_profile_variables(post, options = {})
227
+ post[:serviceVersion] = SP_SERVICE_VERSION
228
+ post[:responseFormat] = 'QS'
229
+ post[:cardValidation] = (options[:cardValidation].to_i == 1) || '0'
230
+
231
+ post[:operationType] = options[:operationType] || options[:operation] || secure_profile_action(:new)
232
+ post[:customerCode] = options[:billing_id] || options[:vault_id] || false
233
+ post[:status] = options[:status]
234
+ end
235
+
236
+ def add_recurring_amount(post, money)
237
+ post[:amount] = amount(money)
238
+ end
239
+
240
+ def add_recurring_invoice(post, options)
241
+ post[:rbApplyTax1] = options[:apply_tax1]
242
+ post[:rbApplyTax2] = options[:apply_tax2]
243
+ end
244
+
245
+ def add_recurring_operation_type(post, operation)
246
+ post[:operationType] = RECURRING_OPERATION[operation]
247
+ end
248
+
249
+ def add_recurring_service(post, options)
250
+ post[:serviceVersion] = '1.0'
251
+ post[:merchantId] = @options[:login]
252
+ post[:passCode] = @options[:recurring_api_key]
253
+ post[:rbAccountId] = options[:account_id]
254
+ end
255
+
256
+ def add_recurring_type(post, options)
257
+ # XXX requires!
258
+ post[:trnRecurring] = 1
259
+ period, increment = interval(options)
260
+ post[:rbBillingPeriod] = PERIODS[period]
261
+ post[:rbBillingIncrement] = increment
262
+
263
+ if options.include? :start_date
264
+ post[:rbCharge] = 0
265
+ post[:rbFirstBilling] = options[:start_date].strftime('%m%d%Y')
266
+ end
267
+
268
+ if count = options[:occurrences] || options[:payments]
269
+ post[:rbExpiry] = (options[:start_date] || Date.current).advance(period => count).strftime('%m%d%Y')
270
+ end
271
+ end
272
+
273
+ def interval(options)
274
+ if options.include? :periodicity
275
+ requires!(options, [:periodicity, *PERIODICITIES.keys])
276
+ PERIODICITIES[options[:periodicity]]
277
+ elsif options.include? :interval
278
+ interval = options[:interval]
279
+ if interval.respond_to? :parts
280
+ parts = interval.parts
281
+ raise ArgumentError.new("Cannot recur with mixed interval (#{interval}). Use only one of: days, weeks, months or years") if parts.length > 1
282
+ parts.first
283
+ elsif interval.kind_of? Hash
284
+ requires!(interval, :unit)
285
+ unit, length = interval.values_at(:unit, :length)
286
+ length ||= 1
287
+ [unit, length]
288
+ end
289
+ end
290
+ end
291
+
292
+ def parse(body)
293
+ results = {}
294
+ if !body.nil?
295
+ body.split(/&/).each do |pair|
296
+ key, val = pair.split(/\=/)
297
+ results[key.to_sym] = val.nil? ? nil : CGI.unescape(val)
298
+ end
299
+ end
300
+
301
+ # Clean up the message text if there is any
302
+ if results[:messageText]
303
+ results[:messageText].gsub!(/<LI>/, "")
304
+ results[:messageText].gsub!(/(\.)?<br>/, ". ")
305
+ results[:messageText].strip!
306
+ end
307
+
308
+ results
309
+ end
310
+
311
+ def recurring_parse(data)
312
+ REXML::Document.new(data).root.elements.to_a.inject({}) do |response, element|
313
+ response[element.name.to_sym] = element.text
314
+ response
315
+ end
316
+ end
317
+
318
+ def commit(params, use_profile_api = false)
319
+ post(post_data(params,use_profile_api),use_profile_api)
320
+ end
321
+
322
+ def recurring_commit(params)
323
+ recurring_post(post_data(params, false))
324
+ end
325
+
326
+ def post(data, use_profile_api=nil)
327
+ response = parse(ssl_post((use_profile_api ? SECURE_PROFILE_URL : self.live_url), data))
328
+ response[:customer_vault_id] = response[:customerCode] if response[:customerCode]
329
+ build_response(success?(response), message_from(response), response,
330
+ :test => test? || response[:authCode] == "TEST",
331
+ :authorization => authorization_from(response),
332
+ :cvv_result => CVD_CODES[response[:cvdId]],
333
+ :avs_result => { :code => (AVS_CODES.include? response[:avsId]) ? AVS_CODES[response[:avsId]] : response[:avsId] }
334
+ )
335
+ end
336
+
337
+ def recurring_post(data)
338
+ response = recurring_parse(ssl_post(RECURRING_URL, data))
339
+ build_response(recurring_success?(response), recurring_message_from(response), response)
340
+ end
341
+
342
+ def authorization_from(response)
343
+ "#{response[:trnId]};#{response[:trnAmount]};#{response[:trnType]}"
344
+ end
345
+
346
+ def message_from(response)
347
+ response[:messageText] || response[:responseMessage]
348
+ end
349
+
350
+ def recurring_message_from(response)
351
+ response[:message]
352
+ end
353
+
354
+ def recurring_success?(response)
355
+ response[:code] == '1'
356
+ end
357
+
358
+ def add_source(post, source)
359
+ if source.is_a?(String) or source.is_a?(Integer)
360
+ post[:customerCode] = source
361
+ else
362
+ card_brand(source) == "check" ? add_check(post, source) : add_credit_card(post, source)
363
+ end
364
+ end
365
+
366
+ def add_transaction_type(post, action)
367
+ post[:trnType] = TRANSACTIONS[action]
368
+ end
369
+
370
+ def post_data(params, use_profile_api)
371
+ params[:requestType] = 'BACKEND'
372
+ if use_profile_api
373
+ params[:merchantId] = @options[:login]
374
+ params[:passCode] = @options[:secure_profile_api_key]
375
+ else
376
+ params[:username] = @options[:user] if @options[:user]
377
+ params[:password] = @options[:password] if @options[:password]
378
+ params[:merchant_id] = @options[:login]
379
+ end
380
+ params[:vbvEnabled] = '0'
381
+ params[:scEnabled] = '0'
382
+
383
+ params.reject{|k, v| v.blank?}.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
384
+ end
385
+
386
+ end
387
+ end
388
+ end
389
+