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,47 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class OrbitalSoftDescriptors < Model
4
+ PHONE_FORMAT_1 = /\A\d{3}-\d{3}-\d{4}\z/
5
+ PHONE_FORMAT_2 = /\A\d{3}-\w{7}\z/
6
+
7
+ # ==== Tampa PNS Soft Descriptors
8
+ # The support for Soft Descriptors via the PNS Host is only for customers processing through Chase
9
+ # Paymentech Canada.
10
+
11
+ # Unlike Salem, the only value that gets passed on the cardholder statement is the Merchant Name field.
12
+ # And for these customers, it is a maximum of 25 bytes of data.
13
+ #
14
+ # All other Soft Descriptor fields can optionally be sent, but will not be submitted to the settlement host
15
+ # and will not display on the cardholder statement.
16
+
17
+ attr_accessor :merchant_name, :product_description, :merchant_city, :merchant_phone, :merchant_url, :merchant_email
18
+
19
+ def initialize(options = {})
20
+ self.merchant_name = options[:merchant_name]
21
+ self.merchant_city = options[:merchant_city]
22
+ self.merchant_phone = options[:merchant_phone]
23
+ self.merchant_url = options[:merchant_url]
24
+ self.merchant_email = options[:merchant_email]
25
+ end
26
+
27
+ def validate
28
+ errors = []
29
+
30
+ errors << [:merchant_name, "is required"] if self.merchant_name.blank?
31
+ errors << [:merchant_name, "is required to be 25 bytes or less"] if self.merchant_name.bytesize > 25
32
+
33
+ if(!empty?(self.merchant_phone) && !self.merchant_phone.match(PHONE_FORMAT_1) && !self.merchant_phone.match(PHONE_FORMAT_2))
34
+ errors << [:merchant_phone, "is required to follow \"NNN-NNN-NNNN\" or \"NNN-AAAAAAA\" format"]
35
+ end
36
+
37
+ [:merchant_email, :merchant_url].each do |attr|
38
+ unless self.send(attr).blank?
39
+ errors << [attr, "is required to be 13 bytes or less"] if(self.send(attr).bytesize > 13)
40
+ end
41
+ end
42
+
43
+ errors_hash(errors)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,207 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PacNetRavenGateway < Gateway
4
+
5
+ AVS_ADDRESS_CODES = {
6
+ 'avs_address_unavailable' => 'X',
7
+ 'avs_address_not_checked' => 'X',
8
+ 'avs_address_matched' => 'Y',
9
+ 'avs_address_not_matched' => 'N',
10
+ 'avs_address_partial_match' => 'N'
11
+ }
12
+
13
+ AVS_POSTAL_CODES = {
14
+ 'avs_postal_unavailable' => 'X',
15
+ 'avs_postal_not_checked' => 'X',
16
+ 'avs_postal_matched' => 'Y',
17
+ 'avs_postal_not_matched' => 'N',
18
+ 'avs_postal_partial_match' => 'N'
19
+ }
20
+
21
+ CVV2_CODES = {
22
+ 'cvv2_matched' => 'Y',
23
+ 'cvv2_not_matched' => 'N',
24
+ 'cvv2_unavailable' => 'X',
25
+ 'cvv2_not_checked' => 'X'
26
+ }
27
+
28
+ self.test_url = 'https://demo.deepcovelabs.com/realtime/'
29
+ self.live_url = 'https://raven.pacnetservices.com/realtime/'
30
+
31
+ self.supported_countries = ['US']
32
+ self.supported_cardtypes = [:visa, :master]
33
+ self.money_format = :cents
34
+ self.default_currency = 'USD'
35
+ self.homepage_url = 'http://www.pacnetservices.com/'
36
+ self.display_name = 'Raven PacNet'
37
+
38
+ def initialize(options = {})
39
+ requires!(options, :user, :secret, :prn)
40
+ super
41
+ end
42
+
43
+ def authorize(money, creditcard, options = {})
44
+ post = {}
45
+ add_creditcard(post, creditcard)
46
+ add_currency_code(post, money, options)
47
+ add_address(post, options)
48
+ post['PRN'] = @options[:prn]
49
+
50
+ commit('cc_preauth', money, post)
51
+ end
52
+
53
+ def purchase(money, creditcard, options = {})
54
+ post = {}
55
+ add_currency_code(post, money, options)
56
+ add_creditcard(post, creditcard)
57
+ add_address(post, options)
58
+ post['PRN'] = @options[:prn]
59
+
60
+ commit('cc_debit', money, post)
61
+ end
62
+
63
+ def void(authorization, options = {})
64
+ post = {}
65
+ post['TrackingNumber'] = authorization
66
+ post['PymtType'] = options[:pymt_type] || 'cc_debit'
67
+
68
+ commit('void', nil, post)
69
+ end
70
+
71
+ def capture(money, authorization, options = {})
72
+ post = {}
73
+ post['PreauthNumber'] = authorization
74
+ post['PRN'] = @options[:prn]
75
+ add_currency_code(post, money, options)
76
+
77
+ commit('cc_settle', money, post)
78
+ end
79
+
80
+ def refund(money, template_number, options = {})
81
+ post = {}
82
+ post['PRN'] = @options[:prn]
83
+ post['TemplateNumber'] = template_number
84
+ add_currency_code(post, money, options)
85
+
86
+ commit('cc_refund', money, post)
87
+ end
88
+
89
+ private
90
+
91
+ def add_creditcard(post, creditcard)
92
+ post['CardNumber'] = creditcard.number
93
+ post['Expiry'] = expdate(creditcard)
94
+ post['CVV2'] = creditcard.verification_value if creditcard.verification_value
95
+ end
96
+
97
+ def add_currency_code(post, money, options)
98
+ post['Currency'] = options[:currency] || currency(money)
99
+ end
100
+
101
+ def add_address(post, options)
102
+ if address = options[:billing_address] || options[:address]
103
+ post['BillingStreetAddressLineOne'] = address[:address1].to_s
104
+ post['BillingStreetAddressLineFour'] = address[:address2].to_s
105
+ post['BillingPostalCode'] = address[:zip].to_s
106
+ end
107
+ end
108
+
109
+ def parse(body)
110
+ Hash[body.split('&').map{|x| x.split('=').map{|y| CGI.unescape(y)}}]
111
+ end
112
+
113
+ def commit(action, money, parameters)
114
+ parameters['Amount'] = amount(money) unless action == 'void'
115
+
116
+ data = ssl_post url(action), post_data(action, parameters)
117
+
118
+ response = parse(data)
119
+ response[:action] = action
120
+
121
+ message = message_from(response)
122
+
123
+ test_mode = test? || message =~ /TESTMODE/
124
+
125
+ Response.new(success?(response), message, response,
126
+ :test => test_mode,
127
+ :authorization => response['TrackingNumber'],
128
+ :fraud_review => fraud_review?(response),
129
+ :avs_result => {
130
+ :postal_match => AVS_POSTAL_CODES[response['AVSPostalResponseCode']],
131
+ :street_match => AVS_ADDRESS_CODES[response['AVSAddressResponseCode']]
132
+ },
133
+ :cvv_result => CVV2_CODES[response['CVV2ResponseCode']]
134
+ )
135
+ end
136
+
137
+ def url(action)
138
+ (test? ? self.test_url : self.live_url) + endpoint(action)
139
+ end
140
+
141
+ def endpoint(action)
142
+ return 'void' if action == 'void'
143
+ 'submit'
144
+ end
145
+
146
+ def fraud_review?(response)
147
+ false
148
+ end
149
+
150
+ def success?(response)
151
+ if %w(cc_settle cc_debit cc_preauth cc_refund).include?(response[:action])
152
+ !response['ApprovalCode'].nil? and response['ErrorCode'].nil? and response['Status'] == 'Approved'
153
+ elsif response[:action] = 'void'
154
+ !response['ApprovalCode'].nil? and response['ErrorCode'].nil? and response['Status'] == 'Voided'
155
+ end
156
+ end
157
+
158
+ def message_from(response)
159
+ return response['Message'] if response['Message']
160
+
161
+ if response['Status'] == 'Approved'
162
+ "This transaction has been approved"
163
+ elsif response['Status'] == 'Declined'
164
+ "This transaction has been declined"
165
+ elsif response['Status'] == 'Voided'
166
+ "This transaction has been voided"
167
+ else
168
+ response['Status']
169
+ end
170
+ end
171
+
172
+ def post_data(action, parameters = {})
173
+ post = {}
174
+
175
+ post['PymtType'] = action
176
+ post['RAPIVersion'] = '2'
177
+ post['UserName'] = @options[:user]
178
+ post['Timestamp'] = timestamp
179
+ post['RequestID'] = request_id
180
+ post['Signature'] = signature(action, post, parameters)
181
+
182
+ request = post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
183
+ request
184
+ end
185
+
186
+ def timestamp
187
+ Time.now.strftime("%Y-%m-%dT%H:%M:%S.Z")
188
+ end
189
+
190
+ def request_id
191
+ SecureRandom.uuid
192
+ end
193
+
194
+ def signature(action, post, parameters = {})
195
+ string = if %w(cc_settle cc_debit cc_preauth cc_refund).include?(action)
196
+ post['UserName'] + post['Timestamp'] + post['RequestID'] + post['PymtType'] + parameters['Amount'].to_s + parameters['Currency']
197
+ elsif action == 'void'
198
+ post['UserName'] + post['Timestamp'] + post['RequestID'] + parameters['TrackingNumber']
199
+ else
200
+ post['UserName']
201
+ end
202
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new(@options[:secret]), @options[:secret], string)
203
+ end
204
+ end
205
+ end
206
+ end
207
+
@@ -0,0 +1,122 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PagoFacilGateway < Gateway
4
+ self.test_url = 'https://www.pagofacil.net/st/public/Wsrtransaccion/index/format/json?'
5
+ self.live_url = 'https://www.pagofacil.net/ws/public/Wsrtransaccion/index/format/json?'
6
+
7
+ self.supported_countries = ['MX']
8
+ self.default_currency = 'MXN'
9
+ self.supported_cardtypes = [:visa, :master, :american_express, :jcb]
10
+
11
+ self.homepage_url = 'http://www.pagofacil.net/'
12
+ self.display_name = 'PagoFacil'
13
+
14
+ def initialize(options={})
15
+ requires!(options, :branch_id, :merchant_id, :service_id)
16
+ super
17
+ end
18
+
19
+ def purchase(money, credit_card, options={})
20
+ post = {}
21
+ add_invoice(post, money, options)
22
+ add_payment(post, credit_card)
23
+ add_address(post, options)
24
+ add_customer_data(post, options)
25
+ add_merchant_data(post)
26
+
27
+ commit(post)
28
+ end
29
+
30
+ private
31
+
32
+ def add_customer_data(post, options)
33
+ post[:email] = options[:email]
34
+ post[:celular] = options[:cellphone]
35
+ end
36
+
37
+ def add_address(post, options)
38
+ address = options.fetch(:billing_address, {})
39
+ post[:calleyNumero] = address[:address1]
40
+ post[:colonia] = address[:address2]
41
+ post[:municipio] = address[:city]
42
+ post[:estado] = address[:state]
43
+ post[:pais] = address[:country]
44
+ post[:telefono] = address[:phone]
45
+ post[:cp] = address[:zip]
46
+ end
47
+
48
+ def add_invoice(post, money, options)
49
+ post[:monto] = amount(money)
50
+ post[:idPedido] = options[:order_id]
51
+ add_currency(post, money, options)
52
+ end
53
+
54
+ def add_currency(post, money, options)
55
+ currency = options.fetch(:currency, currency(money))
56
+ unless currency == self.class.default_currency
57
+ post[:divisa] = currency
58
+ end
59
+ end
60
+
61
+ def add_payment(post, credit_card)
62
+ post[:nombre] = credit_card.first_name
63
+ post[:apellidos] = credit_card.last_name
64
+ post[:numeroTarjeta] = credit_card.number
65
+ post[:cvt] = credit_card.verification_value
66
+ post[:mesExpiracion] = sprintf("%02d", credit_card.month)
67
+ post[:anyoExpiracion] = credit_card.year.to_s.slice(-2, 2)
68
+ end
69
+
70
+ def add_merchant_data(post)
71
+ post[:idSucursal] = options.fetch(:branch_id)
72
+ post[:idUsuario] = options.fetch(:merchant_id)
73
+ post[:idServicio] = options.fetch(:service_id)
74
+ end
75
+
76
+ def parse(body)
77
+ JSON.parse(body)["WebServices_Transacciones"]["transaccion"]
78
+ rescue JSON::ParserError
79
+ json_error(body)
80
+ end
81
+
82
+ def commit(parameters)
83
+ url = (test? ? test_url : live_url)
84
+ response = parse(ssl_post(url, post_data(parameters)))
85
+ Response.new(
86
+ success_from(response),
87
+ message_from(response),
88
+ response,
89
+ authorization: authorization_from(response),
90
+ test: test?
91
+ )
92
+ end
93
+
94
+ def success_from(response)
95
+ response["autorizado"] == "1" ||
96
+ response["autorizado"] == true
97
+ end
98
+
99
+ def message_from(response)
100
+ response["texto"]
101
+ end
102
+
103
+ def authorization_from(response)
104
+ response["autorizacion"]
105
+ end
106
+
107
+ def post_data(parameters = {})
108
+ {
109
+ method: 'transaccion',
110
+ data: parameters
111
+ }.to_query
112
+ end
113
+
114
+ def json_error(response)
115
+ {
116
+ "texto" => 'Invalid response received from the PagoFacil API.',
117
+ "raw_response" => response
118
+ }
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,246 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PayConexGateway < Gateway
4
+ include Empty
5
+
6
+ self.test_url = "https://cert.payconex.net/api/qsapi/3.8/"
7
+ self.live_url = "https://secure.payconex.net/api/qsapi/3.8/"
8
+
9
+ self.supported_countries = %w(US CA)
10
+ self.default_currency = "USD"
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
12
+
13
+ self.homepage_url = "http://www.bluefincommerce.com/"
14
+ self.display_name = "PayConex"
15
+
16
+ def initialize(options={})
17
+ requires!(options, :account_id, :api_accesskey)
18
+ super
19
+ end
20
+
21
+ def purchase(money, payment_method, options={})
22
+ post = {}
23
+ add_auth_purchase_params(post, money, payment_method, options)
24
+ commit("SALE", post)
25
+ end
26
+
27
+ def authorize(money, payment_method, options={})
28
+ post = {}
29
+ add_auth_purchase_params(post, money, payment_method, options)
30
+ commit("AUTHORIZATION", post)
31
+ end
32
+
33
+ def capture(money, authorization, options={})
34
+ post = {}
35
+ add_reference_params(post, authorization, options)
36
+ add_amount(post, money, options)
37
+ commit("CAPTURE", post)
38
+ end
39
+
40
+ def refund(money, authorization, options={})
41
+ post = {}
42
+ add_reference_params(post, authorization, options)
43
+ add_amount(post, money, options)
44
+ commit("REFUND", post)
45
+ end
46
+
47
+ def void(authorization, options = {})
48
+ post = {}
49
+ add_reference_params(post, authorization, options)
50
+ commit("REVERSAL", post)
51
+ end
52
+
53
+ def credit(money, payment_method, options={})
54
+ if payment_method.is_a?(String)
55
+ raise ArgumentError, "Reference credits are not supported. Please supply the original credit card or use the #refund method."
56
+ end
57
+
58
+ post = {}
59
+ add_auth_purchase_params(post, money, payment_method, options)
60
+ commit("CREDIT", post)
61
+ end
62
+
63
+ def verify(payment_method, options={})
64
+ authorize(0, payment_method, options)
65
+ end
66
+
67
+ def store(payment_method, options={})
68
+ post = {}
69
+ add_credentials(post)
70
+ add_payment_method(post, payment_method)
71
+ add_address(post, options)
72
+ add_common_options(post, options)
73
+ commit("STORE", post)
74
+ end
75
+
76
+ def supports_scrubbing?
77
+ true
78
+ end
79
+
80
+ def scrub(transcript)
81
+ force_utf8(transcript).
82
+ gsub(%r((api_accesskey=)\w+), '\1[FILTERED]').
83
+ gsub(%r((card_number=)\w+), '\1[FILTERED]').
84
+ gsub(%r((card_verification=)\w+), '\1[FILTERED]')
85
+ end
86
+
87
+ private
88
+
89
+ def force_utf8(string)
90
+ return nil unless string
91
+ binary = string.encode("BINARY", invalid: :replace, undef: :replace, replace: "?") # Needed for Ruby 2.0 since #encode is a no-op if the string is already UTF-8. It's not needed for Ruby 2.1 and up since it's not a no-op there.
92
+ binary.encode("UTF-8", invalid: :replace, undef: :replace, replace: "?")
93
+ end
94
+
95
+ def add_credentials(post)
96
+ post[:account_id] = @options[:account_id]
97
+ post[:api_accesskey] = @options[:api_accesskey]
98
+ end
99
+
100
+ def add_auth_purchase_params(post, money, payment_method, options)
101
+ add_credentials(post)
102
+ add_payment_method(post, payment_method)
103
+ add_address(post, options)
104
+ add_common_options(post, options)
105
+ add_amount(post, money, options)
106
+ add_if_present(post, :email, options[:email])
107
+ end
108
+
109
+ def add_reference_params(post, authorization, options)
110
+ add_credentials(post)
111
+ add_common_options(post, options)
112
+ add_token_id(post, authorization)
113
+ end
114
+
115
+ def add_amount(post, money, options)
116
+ post[:transaction_amount] = amount(money)
117
+ currency_code = (options[:currency] || currency(money))
118
+ add_if_present(post, :currency, currency_code)
119
+ end
120
+
121
+ def add_payment_method(post, payment_method)
122
+ case payment_method
123
+ when String
124
+ add_token_payment_method(post, payment_method)
125
+ when Check
126
+ add_check(post, payment_method)
127
+ else
128
+ if payment_method.respond_to?(:track_data) && payment_method.track_data.present?
129
+ add_card_present_payment_method(post, payment_method)
130
+ else
131
+ add_credit_card(post, payment_method)
132
+ end
133
+ end
134
+ end
135
+
136
+ def add_credit_card(post, payment_method)
137
+ post[:tender_type] = "CARD"
138
+ post[:card_number] = payment_method.number
139
+ post[:card_expiration] = expdate(payment_method)
140
+ post[:card_verification] = payment_method.verification_value
141
+ post[:first_name] = payment_method.first_name
142
+ post[:last_name] = payment_method.last_name
143
+ end
144
+
145
+ def add_token_payment_method(post, payment_method)
146
+ post[:tender_type] = "CARD"
147
+ post[:token_id] = payment_method
148
+ post[:reissue] = true
149
+ end
150
+
151
+ def add_card_present_payment_method(post, payment_method)
152
+ post[:tender_type] = "CARD"
153
+ post[:card_tracks] = payment_method.track_data
154
+ end
155
+
156
+ def add_check(post, payment_method)
157
+ post[:tender_type] = "ACH"
158
+ post[:first_name] = payment_method.first_name
159
+ post[:last_name] = payment_method.last_name
160
+ post[:bank_account_number] = payment_method.account_number
161
+ post[:bank_routing_number] = payment_method.routing_number
162
+ post[:check_number] = payment_method.number
163
+ add_if_present(post, :ach_account_type, payment_method.account_type)
164
+ end
165
+
166
+ def add_address(post, options)
167
+ address = options[:billing_address]
168
+ return unless address
169
+
170
+ add_if_present(post, :street_address1, address[:address1])
171
+ add_if_present(post, :street_address2, address[:address2])
172
+ add_if_present(post, :city, address[:city])
173
+ add_if_present(post, :state, address[:state])
174
+ add_if_present(post, :zip, address[:zip])
175
+ add_if_present(post, :country, address[:country])
176
+ add_if_present(post, :phone, address[:phone])
177
+ end
178
+
179
+ def add_common_options(post, options)
180
+ add_if_present(post, :transaction_description, options[:description])
181
+ add_if_present(post, :custom_id, options[:custom_id])
182
+ add_if_present(post, :custom_data, options[:custom_data])
183
+ add_if_present(post, :ip_address, options[:ip])
184
+ add_if_present(post, :payment_type, options[:payment_type])
185
+ add_if_present(post, :cashier, options[:cashier])
186
+
187
+ post[:disable_cvv] = options[:disable_cvv] unless options[:disable_cvv].nil?
188
+ post[:response_format] = 'JSON'
189
+ end
190
+
191
+ def add_if_present(post, key, value)
192
+ post[key] = value unless empty?(value)
193
+ end
194
+
195
+ def add_token_id(post, authorization)
196
+ post[:token_id] = authorization
197
+ end
198
+
199
+ def parse(body)
200
+ JSON.parse(body)
201
+ end
202
+
203
+ def commit(action, params)
204
+ raw_response = ssl_post(url, post_data(action, params))
205
+ response = parse(raw_response)
206
+
207
+ Response.new(
208
+ success_from(response),
209
+ message_from(response),
210
+ response,
211
+ authorization: response["transaction_id"],
212
+ :avs_result => AVSResult.new(code: response["avs_response"]),
213
+ :cvv_result => CVVResult.new(response["cvv2_response"]),
214
+ test: test?
215
+ )
216
+
217
+ rescue JSON::ParserError
218
+ unparsable_response(raw_response)
219
+ end
220
+
221
+ def url
222
+ test? ? test_url : live_url
223
+ end
224
+
225
+ def success_from(response)
226
+ response["transaction_approved"] || !response["error"]
227
+ end
228
+
229
+ def message_from(response)
230
+ success_from(response) ? response["authorization_message"] : response["error_message"]
231
+ end
232
+
233
+ def post_data(action, params)
234
+ params[:transaction_type] = action
235
+ params.map {|k, v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
236
+ end
237
+
238
+ def unparsable_response(raw_response)
239
+ message = "Invalid JSON response received from PayConex. Please contact PayConex if you continue to receive this message."
240
+ message += " (The raw response returned by the API was #{raw_response.inspect})"
241
+ return Response.new(false, message)
242
+ end
243
+
244
+ end
245
+ end
246
+ end