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,58 @@
1
+ require 'active_merchant/billing/gateways/beanstream/beanstream_core'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class BeanstreamInteracResponse < Response
6
+ def redirect
7
+ params['pageContents']
8
+ end
9
+ end
10
+
11
+ class BeanstreamInteracGateway < Gateway
12
+ include BeanstreamCore
13
+
14
+ # Confirm a transaction posted back from the bank to Beanstream.
15
+ # Confirming a transaction does not require any credentials,
16
+ # and in an application with many merchants sharing a funded
17
+ # URL the application may not yet know which merchant the
18
+ # post back is for until the response of the confirmation is
19
+ # received, which contains the order number.
20
+ def self.confirm(transaction)
21
+ gateway = new(:login => '')
22
+ gateway.confirm(transaction)
23
+ end
24
+
25
+ def purchase(money, options = {})
26
+ post = {}
27
+ add_amount(post, money)
28
+ add_invoice(post, options)
29
+ add_address(post, options)
30
+ add_interac_details(post, options)
31
+ add_transaction_type(post, :purchase)
32
+ commit(post)
33
+ end
34
+
35
+ def success?(response)
36
+ response[:responseType] == 'R' || response[:trnApproved] == '1' || response[:responseCode] == '1'
37
+ end
38
+
39
+ # Confirm a transaction posted back from the bank to Beanstream.
40
+ def confirm(transaction)
41
+ post(transaction)
42
+ end
43
+
44
+ private
45
+
46
+ def add_interac_details(post, options)
47
+ address = options[:billing_address] || options[:address] || {}
48
+ post[:trnCardOwner] = address[:name]
49
+ post[:paymentMethod] = 'IO'
50
+ end
51
+
52
+ def build_response(*args)
53
+ BeanstreamInteracResponse.new(*args)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,506 @@
1
+ require 'digest/md5'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class BluePayGateway < Gateway
6
+ class_attribute :rebilling_url, :ignore_http_status
7
+
8
+ self.live_url = 'https://secure.bluepay.com/interfaces/bp20post'
9
+ self.rebilling_url = 'https://secure.bluepay.com/interfaces/bp20rebadmin'
10
+
11
+ self.ignore_http_status = true
12
+
13
+ CARD_CODE_ERRORS = %w( N S )
14
+ AVS_ERRORS = %w( A E N R W Z )
15
+ AVS_REASON_CODES = %w(27 45)
16
+
17
+ FIELD_MAP = {
18
+ 'TRANS_ID' => :transaction_id,
19
+ 'STATUS' => :response_code,
20
+ 'AVS' => :avs_result_code,
21
+ 'CVV2'=> :card_code,
22
+ 'AUTH_CODE' => :authorization,
23
+ 'MESSAGE' => :message,
24
+ 'REBID' => :rebid,
25
+ 'TRANS_TYPE' => :trans_type,
26
+ 'PAYMENT_ACCOUNT_MASK' => :acct_mask,
27
+ 'CARD_TYPE' => :card_type,
28
+ }
29
+
30
+ REBILL_FIELD_MAP = {
31
+ 'REBILL_ID' => :rebill_id,
32
+ 'ACCOUNT_ID'=> :account_id,
33
+ 'USER_ID' => :user_id,
34
+ 'TEMPLATE_ID' => :template_id,
35
+ 'STATUS' => :status,
36
+ 'CREATION_DATE' => :creation_date,
37
+ 'NEXT_DATE' => :next_date,
38
+ 'LAST_DATE' => :last_date,
39
+ 'SCHED_EXPR' => :schedule,
40
+ 'CYCLES_REMAIN' => :cycles_remain,
41
+ 'REB_AMOUNT' => :rebill_amount,
42
+ 'NEXT_AMOUNT' => :next_amount,
43
+ 'USUAL_DATE' => :undoc_usual_date, # Not found in the bp20rebadmin API doc.
44
+ }
45
+
46
+ self.supported_countries = ['US']
47
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
48
+ self.homepage_url = 'http://www.bluepay.com/'
49
+ self.display_name = 'BluePay'
50
+ self.money_format = :dollars
51
+
52
+ # Creates a new BluepayGateway
53
+ #
54
+ # The gateway requires that a valid Account ID and Secret Key be passed
55
+ # in the +options+ hash.
56
+ #
57
+ # ==== Options
58
+ #
59
+ # * <tt>:account_id</tt> -- The BluePay gateway Account ID (REQUIRED)
60
+ # * <tt>:secret_key</tt> -- The BluePay gateway Secret Key (REQUIRED)
61
+ # * <tt>:test</tt> -- set to true for TEST mode or false for LIVE mode
62
+ def initialize(options = {})
63
+ requires!(options, :login, :password)
64
+ super
65
+ end
66
+
67
+ # Performs an authorization, which reserves the funds on the customer's credit card. This does not actually take funds from the customer
68
+ # This is referred to an AUTH transaction in BluePay
69
+ #
70
+ # ==== Parameters
71
+ #
72
+ # * <tt>money</tt> -- The amount to be authorized as an Integer value in cents.
73
+ # * <tt>payment_object</tt> -- This can either be one of three things:
74
+ # A CreditCard object,
75
+ # A Check object,
76
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
77
+ # * <tt>options</tt> -- A hash of optional parameters.
78
+ def authorize(money, payment_object, options = {})
79
+ post = {}
80
+ add_payment_method(post, payment_object)
81
+ add_invoice(post, options)
82
+ add_address(post, options)
83
+ add_customer_data(post, options)
84
+ add_rebill(post, options) if options[:rebill]
85
+ add_duplicate_override(post, options)
86
+ post[:TRANS_TYPE] = 'AUTH'
87
+ commit('AUTH_ONLY', money, post)
88
+ end
89
+
90
+ # Perform a purchase, which is essentially an authorization and capture in a single operation.
91
+ # This is referred to a SALE transaction in BluePay
92
+ #
93
+ # ==== Parameters
94
+ #
95
+ # * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
96
+ # * <tt>payment_object</tt> -- This can either be one of three things:
97
+ # A CreditCard object,
98
+ # A Check object,
99
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
100
+ # * <tt>options</tt> -- A hash of optional parameters.,
101
+ def purchase(money, payment_object, options = {})
102
+ post = {}
103
+ add_payment_method(post, payment_object)
104
+ add_invoice(post, options)
105
+ add_address(post, options)
106
+ add_customer_data(post, options)
107
+ add_rebill(post, options) if options[:rebill]
108
+ add_duplicate_override(post, options)
109
+ post[:TRANS_TYPE] = 'SALE'
110
+ commit('AUTH_CAPTURE', money, post)
111
+ end
112
+
113
+ # Captures the funds from an authorize transaction.
114
+ # This is referred to a CAPTURE transaction in BluePay
115
+ #
116
+ # ==== Parameters
117
+ #
118
+ # * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
119
+ # * <tt>identification</tt> -- The Master ID, or token, returned from the previous authorize transaction.
120
+ def capture(money, identification, options = {})
121
+ post = {}
122
+ add_address(post, options)
123
+ add_customer_data(post, options)
124
+ post[:MASTER_ID] = identification
125
+ post[:TRANS_TYPE] = 'CAPTURE'
126
+ commit('PRIOR_AUTH_CAPTURE', money, post)
127
+ end
128
+
129
+ # Void a previous transaction
130
+ # This is referred to a VOID transaction in BluePay
131
+ #
132
+ # ==== Parameters
133
+ #
134
+ # * <tt>identification</tt> - The Master ID, or token, returned from a previous authorize transaction.
135
+ def void(identification, options = {})
136
+ post = {}
137
+ post[:MASTER_ID] = identification
138
+ post[:TRANS_TYPE] = 'VOID'
139
+ commit('VOID', nil, post)
140
+ end
141
+
142
+ # Performs a credit.
143
+ #
144
+ # This transaction indicates that money should flow from the merchant to the customer.
145
+ #
146
+ # ==== Parameters
147
+ #
148
+ # * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
149
+ # * <tt>payment_object</tt> -- This can either be one of three things:
150
+ # A CreditCard object,
151
+ # A Check object,
152
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
153
+ # If the payment_object is a token, then the transaction type will reverse a previous capture or purchase transaction, returning the funds to the customer. If the amount is nil, a full credit will be processed. This is referred to a REFUND transaction in BluePay.
154
+ # If the payment_object is either a CreditCard or Check object, then the transaction type will be an unmatched credit placing funds in the specified account. This is referred to a CREDIT transaction in BluePay.
155
+ # * <tt>options</tt> -- A hash of parameters.
156
+ def refund(money, identification, options = {})
157
+ if(identification && !identification.kind_of?(String))
158
+ ActiveMerchant.deprecated "refund should only be used to refund a referenced transaction"
159
+ return credit(money, identification, options)
160
+ end
161
+
162
+ post = {}
163
+ post[:PAYMENT_ACCOUNT] = ''
164
+ post[:MASTER_ID] = identification
165
+ post[:TRANS_TYPE] = 'REFUND'
166
+ post[:NAME1] = (options[:first_name] ? options[:first_name] : "")
167
+ post[:NAME2] = options[:last_name] if options[:last_name]
168
+ post[:ZIP] = options[:zip] if options[:zip]
169
+ add_invoice(post, options)
170
+ add_address(post, options)
171
+ add_customer_data(post, options)
172
+ commit('CREDIT', money, post)
173
+ end
174
+
175
+ def credit(money, payment_object, options = {})
176
+ if(payment_object && payment_object.kind_of?(String))
177
+ ActiveMerchant.deprecated "credit should only be used to credit a payment method"
178
+ return refund(money, payment_object, options)
179
+ end
180
+
181
+ post = {}
182
+ post[:PAYMENT_ACCOUNT] = ''
183
+ add_payment_method(post, payment_object)
184
+ post[:TRANS_TYPE] = 'CREDIT'
185
+
186
+ post[:NAME1] = (options[:first_name] ? options[:first_name] : "")
187
+ post[:NAME2] = options[:last_name] if options[:last_name]
188
+ post[:ZIP] = options[:zip] if options[:zip]
189
+ add_invoice(post, options)
190
+ add_address(post, options)
191
+ add_customer_data(post, options)
192
+ commit('CREDIT', money, post)
193
+ end
194
+
195
+ # Create a new recurring payment.
196
+ #
197
+ # ==== Parameters
198
+ #
199
+ # * <tt>money</tt> -- The amount to charge the customer at the time of the recurring payment setup, in cents. Set to zero if you do not want the customer to be charged at this time.
200
+ # * <tt>payment_object</tt> -- This can either be one of three things:
201
+ # A CreditCard object,
202
+ # A Check object,
203
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
204
+ # * <tt>options</tt> -- A hash of optional parameters.,
205
+
206
+ # ==== Options
207
+ #
208
+ # * <tt>:rebill_start_date</tt> is a string that tells the gateway when to start the rebill. (REQUIRED)
209
+ # Has two valid formats:
210
+ # "YYYY-MM-DD HH:MM:SS" Hours, minutes, and seconds are optional.
211
+ # "XX UNITS" Relative date as explained below. Marked from the time of the
212
+ # transaction (i.e.: 10 DAYS, 1 MONTH, 1 YEAR)
213
+ # * <tt>:rebill_expression</tt> is the period of time in-between rebillings. (REQUIRED)
214
+ # It uses the same "XX UNITS" format as rebill_start_date, explained above.
215
+ # Optional parameters include:
216
+ # * <tt>rebill_cycles</tt>: Number of times to rebill. Don't send or set to nil for infinite rebillings (or
217
+ # until canceled).
218
+ # * <tt>rebill_amount</tt>: Amount to rebill. Defaults to amount of transaction for rebillings.
219
+ #
220
+ # For example, to charge the customer $19.95 now and then charge $39.95 in 60 days every 3 months for 5 times, the options hash would be as follows:
221
+ # :rebill_start_date => '60 DAYS',
222
+ # :rebill_expression => '3 MONTHS',
223
+ # :rebill_cycles => '5',
224
+ # :rebill_amount => '39.95'
225
+ # A money object of 1995 cents would be passed into the 'money' parameter.
226
+ def recurring(money, payment_object, options = {})
227
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
228
+
229
+ requires!(options, :rebill_start_date, :rebill_expression)
230
+ options[:rebill] = true
231
+ if money
232
+ purchase(money, payment_object, options)
233
+ else
234
+ authorize(money, payment_object, options)
235
+ end
236
+ end
237
+
238
+ # View a recurring payment
239
+ #
240
+ # This will pull data associated with a current recurring billing
241
+ #
242
+ # ==== Parameters
243
+ #
244
+ # * <tt>rebill_id</tt> -- A string containing the rebill_id of the recurring billing that is already active (REQUIRED)
245
+ def status_recurring(rebill_id)
246
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
247
+
248
+ post = {}
249
+ requires!(rebill_id)
250
+ post[:REBILL_ID] = rebill_id
251
+ post[:TRANS_TYPE] = 'GET'
252
+ commit('rebill', 'nil', post)
253
+ end
254
+
255
+ # Update a recurring payment's details.
256
+ #
257
+ # This transaction updates an existing recurring billing
258
+ #
259
+ # ==== Options
260
+ #
261
+ # * <tt>:rebill_id</tt> -- The 12 digit rebill ID used to update a particular rebilling cycle. (REQUIRED)
262
+ # * <tt>:rebill_amount</tt> -- A string containing the new rebilling amount.
263
+ # * <tt>:rebill_next_date</tt> -- A string containing the new rebilling next date.
264
+ # * <tt>:rebill_expression</tt> -- A string containing the new rebilling expression.
265
+ # * <tt>:rebill_cycles</tt> -- A string containing the new rebilling cycles.
266
+ # * <tt>:rebill_next_amount</tt> -- A string containing the next rebilling amount to charge the customer. This ONLY affects the next scheduled charge; all other rebillings will continue at the regular (rebill_amount) amount.
267
+ # Take a look above at the recurring_payment method for similar examples on how to use.
268
+ def update_recurring(options = {})
269
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
270
+
271
+ post = {}
272
+ requires!(options, :rebill_id)
273
+ post[:REBILL_ID] = options[:rebill_id]
274
+ post[:TRANS_TYPE] = 'SET'
275
+ post[:REB_AMOUNT] = amount(options[:rebill_amount]) if options[:rebill_amount]
276
+ post[:NEXT_DATE] = options[:rebill_next_date]
277
+ post[:REB_EXPR] = options[:rebill_expression]
278
+ post[:REB_CYCLES] = options[:rebill_cycles]
279
+ post[:NEXT_AMOUNT] = options[:rebill_next_amount]
280
+ commit('rebill', 'nil', post)
281
+ end
282
+
283
+ # Cancel a recurring payment.
284
+ #
285
+ # This transaction cancels an existing recurring billing.
286
+ #
287
+ # ==== Parameters
288
+ #
289
+ # * <tt>rebill_id</tt> -- A string containing the rebill_id of the recurring billing that you wish to cancel/stop (REQUIRED)
290
+ def cancel_recurring(rebill_id)
291
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
292
+
293
+ post = {}
294
+ requires!(rebill_id)
295
+ post[:REBILL_ID] = rebill_id
296
+ post[:TRANS_TYPE] = 'SET'
297
+ post[:STATUS] = 'stopped'
298
+ commit('rebill', 'nil', post)
299
+ end
300
+
301
+ private
302
+
303
+ def commit(action, money, fields)
304
+ fields[:AMOUNT] = amount(money) unless(fields[:TRANS_TYPE] == 'VOID' || action == 'rebill')
305
+ fields[:MODE] = (test? ? 'TEST' : 'LIVE')
306
+ fields[:ACCOUNT_ID] = @options[:login]
307
+
308
+ if action == 'rebill'
309
+ url = rebilling_url
310
+ fields[:TAMPER_PROOF_SEAL] = calc_rebill_tps(fields)
311
+ else
312
+ url = live_url
313
+ fields[:TAMPER_PROOF_SEAL] = calc_tps(amount(money), fields)
314
+ end
315
+ parse(ssl_post(url, post_data(action, fields)))
316
+ end
317
+
318
+ def parse_recurring(response_fields, opts={}) # expected status?
319
+ parsed = {}
320
+ response_fields.each do |k,v|
321
+ mapped_key = REBILL_FIELD_MAP.include?(k) ? REBILL_FIELD_MAP[k] : k
322
+ parsed[mapped_key] = v
323
+ end
324
+
325
+ success = parsed[:status] != 'error'
326
+ message = parsed[:status]
327
+
328
+ Response.new(success, message, parsed,
329
+ :test => test?,
330
+ :authorization => parsed[:rebill_id])
331
+ end
332
+
333
+ def parse(body)
334
+ # The bp20api has max one value per form field.
335
+ response_fields = Hash[CGI::parse(body).map{|k,v| [k.upcase,v.first]}]
336
+
337
+ if response_fields.include? "REBILL_ID"
338
+ return parse_recurring(response_fields)
339
+ end
340
+
341
+ parsed = {}
342
+ response_fields.each do |k,v|
343
+ mapped_key = FIELD_MAP.include?(k) ? FIELD_MAP[k] : k
344
+ parsed[mapped_key] = v
345
+ end
346
+
347
+ # normalize message
348
+ message = message_from(parsed)
349
+ success = parsed[:response_code] == '1'
350
+ Response.new(success, message, parsed,
351
+ :test => test?,
352
+ :authorization => (parsed[:rebid] && parsed[:rebid] != '' ? parsed[:rebid] : parsed[:transaction_id]),
353
+ :avs_result => { :code => parsed[:avs_result_code] },
354
+ :cvv_result => parsed[:card_code]
355
+ )
356
+ end
357
+
358
+ def message_from(parsed)
359
+ message = parsed[:message]
360
+ if(parsed[:response_code].to_i == 2)
361
+ if CARD_CODE_ERRORS.include?(parsed[:card_code])
362
+ message = CVVResult.messages[parsed[:card_code]]
363
+ elsif AVS_ERRORS.include?(parsed[:avs_result_code])
364
+ message = AVSResult.messages[ parsed[:avs_result_code] ]
365
+ else
366
+ message = message.chomp('.')
367
+ end
368
+ elsif message == "Missing ACCOUNT_ID"
369
+ message = "The merchant login ID or password is invalid"
370
+ elsif message =~ /Approved/
371
+ message = "This transaction has been approved"
372
+ elsif message =~ /Expired/
373
+ message = "The credit card has expired"
374
+ end
375
+ message
376
+ end
377
+
378
+ def add_invoice(post, options)
379
+ post[:ORDER_ID] = options[:order_id]
380
+ post[:INVOICE_ID] = options[:invoice]
381
+ post[:invoice_num] = options[:order_id]
382
+ post[:MEMO] = options[:description]
383
+ post[:description] = options[:description]
384
+ end
385
+
386
+ def add_payment_method(post, payment_object)
387
+ post[:MASTER_ID] = ''
388
+ case payment_object
389
+ when String
390
+ post[:MASTER_ID] = payment_object
391
+ when Check
392
+ add_check(post, payment_object)
393
+ else
394
+ add_creditcard(post, payment_object)
395
+ end
396
+ end
397
+
398
+ def add_creditcard(post, creditcard)
399
+ post[:PAYMENT_TYPE] = 'CREDIT'
400
+ post[:PAYMENT_ACCOUNT] = creditcard.number
401
+ post[:CARD_CVV2] = creditcard.verification_value
402
+ post[:CARD_EXPIRE] = expdate(creditcard)
403
+ post[:NAME1] = creditcard.first_name
404
+ post[:NAME2] = creditcard.last_name
405
+ end
406
+
407
+ CHECK_ACCOUNT_TYPES = {
408
+ "checking" => "C",
409
+ "savings" => "S"
410
+ }
411
+
412
+ def add_check(post, check)
413
+ post[:PAYMENT_TYPE] = 'ACH'
414
+ post[:PAYMENT_ACCOUNT] = [CHECK_ACCOUNT_TYPES[check.account_type], check.routing_number, check.account_number].join(":")
415
+ post[:NAME1] = check.first_name
416
+ post[:NAME2] = check.last_name
417
+ end
418
+
419
+ def add_customer_data(post, options)
420
+ post[:EMAIL] = options[:email]
421
+ post[:CUSTOM_ID] = options[:customer]
422
+ end
423
+
424
+ def add_duplicate_override(post, options)
425
+ post[:DUPLICATE_OVERRIDE] = options[:duplicate_override]
426
+ end
427
+
428
+ def add_address(post, options)
429
+ if address = (options[:shipping_address] || options[:billing_address] || options[:address])
430
+ post[:ADDR1] = address[:address1]
431
+ post[:ADDR2] = address[:address2]
432
+ post[:COMPANY_NAME] = address[:company]
433
+ post[:PHONE] = address[:phone]
434
+ post[:CITY] = address[:city]
435
+ post[:STATE] = (address[:state].blank? ? 'n/a' : address[:state])
436
+ post[:ZIP] = address[:zip]
437
+ post[:COUNTRY] = address[:country]
438
+ end
439
+ end
440
+
441
+ def add_rebill(post, options)
442
+ post[:DO_REBILL] = '1'
443
+ post[:REB_AMOUNT] = amount(options[:rebill_amount])
444
+ post[:REB_FIRST_DATE] = options[:rebill_start_date]
445
+ post[:REB_EXPR] = options[:rebill_expression]
446
+ post[:REB_CYCLES] = options[:rebill_cycles]
447
+ end
448
+
449
+ def post_data(action, parameters = {})
450
+ post = {}
451
+ post[:version] = '1'
452
+ post[:login] = ''
453
+ post[:tran_key] = ''
454
+ post[:relay_response] = "FALSE"
455
+ post[:type] = action
456
+ post[:delim_data] = "TRUE"
457
+ post[:delim_char] = ","
458
+ post[:encap_char] = "$"
459
+ post[:card_num] = '4111111111111111'
460
+ post[:exp_date] = '1212'
461
+ post[:solution_ID] = application_id if(application_id && application_id != "ActiveMerchant")
462
+ post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
463
+ end
464
+
465
+ def expdate(creditcard)
466
+ year = format(creditcard.year, :two_digits)
467
+ month = format(creditcard.month, :two_digits)
468
+
469
+ "#{month}#{year}"
470
+ end
471
+
472
+ def calc_tps(amount, post)
473
+ post[:NAME1] ||= ''
474
+ Digest::MD5.hexdigest(
475
+ [
476
+ @options[:password],
477
+ @options[:login],
478
+ post[:TRANS_TYPE],
479
+ amount,
480
+ post[:MASTER_ID],
481
+ post[:NAME1],
482
+ post[:PAYMENT_ACCOUNT]
483
+ ].join("")
484
+ )
485
+ end
486
+
487
+ def calc_rebill_tps(post)
488
+ Digest::MD5.hexdigest(
489
+ [
490
+ @options[:password],
491
+ @options[:login],
492
+ post[:TRANS_TYPE],
493
+ post[:REBILL_ID]
494
+ ].join("")
495
+ )
496
+ end
497
+
498
+ def handle_response(response)
499
+ if ignore_http_status || (200...300).include?(response.code.to_i)
500
+ return response.body
501
+ end
502
+ raise ResponseError.new(response)
503
+ end
504
+ end
505
+ end
506
+ end