jelaniharris-activemerchant 1.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGELOG +893 -0
  2. data/CONTRIBUTORS +307 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +196 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +170 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +946 -0
  20. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  25. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  26. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  28. data/lib/active_merchant/billing/gateways/braintree_blue.rb +335 -0
  29. data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
  30. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  31. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  32. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  33. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  34. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  35. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  36. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  37. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  38. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  40. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  41. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  42. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  43. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  47. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  48. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  49. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  50. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  51. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  52. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  53. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  54. data/lib/active_merchant/billing/gateways/litle.rb +275 -0
  55. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  56. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  57. data/lib/active_merchant/billing/gateways/migs.rb +259 -0
  58. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  59. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  60. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  61. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  62. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  63. data/lib/active_merchant/billing/gateways/nab_transact.rb +255 -0
  64. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  65. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  66. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  67. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  68. data/lib/active_merchant/billing/gateways/ogone.rb +422 -0
  69. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  70. data/lib/active_merchant/billing/gateways/orbital.rb +353 -0
  71. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  72. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  73. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  74. data/lib/active_merchant/billing/gateways/paybox_direct.rb +199 -0
  75. data/lib/active_merchant/billing/gateways/payflow.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +211 -0
  77. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  78. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  80. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  81. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  82. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  83. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  84. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +640 -0
  85. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  86. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  87. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  88. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  89. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  90. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  91. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  92. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  93. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  94. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  95. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  96. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  97. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  98. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  99. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  100. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  101. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  102. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  103. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  104. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  105. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  106. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  107. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  108. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  109. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  110. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  111. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  112. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  113. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  114. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  115. data/lib/active_merchant/billing/gateways/trust_commerce.rb +437 -0
  116. data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
  117. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  118. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +202 -0
  119. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  120. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  121. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  122. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  123. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  124. data/lib/active_merchant/billing/integrations.rb +17 -0
  125. data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
  126. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  127. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  128. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  129. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  130. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  131. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  132. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  133. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  134. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  135. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  136. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  137. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  138. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  139. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  140. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  141. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  142. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  143. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  144. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  145. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  146. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  147. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  148. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  149. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  150. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  151. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  152. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  153. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  154. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  155. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  156. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  157. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  158. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  159. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  160. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  161. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  162. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  163. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  164. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  165. data/lib/active_merchant/billing/integrations/helper.rb +113 -0
  166. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  167. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  168. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  169. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  170. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  171. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  172. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  173. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  174. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  175. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  176. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  178. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  179. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  180. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  181. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  182. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  183. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  184. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  185. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  186. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  187. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  188. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  189. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  190. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  191. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  192. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  193. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  194. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  195. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  196. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  197. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  198. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  199. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  200. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  201. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  202. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  203. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  204. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  205. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  206. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  207. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  208. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  209. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  210. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  211. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  212. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  213. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  214. data/lib/active_merchant/billing/response.rb +32 -0
  215. data/lib/active_merchant/version.rb +3 -0
  216. data/lib/activemerchant.rb +1 -0
  217. data/lib/support/gateway_support.rb +58 -0
  218. data/lib/support/outbound_hosts.rb +25 -0
  219. metadata +447 -0
@@ -0,0 +1,259 @@
1
+ require File.dirname(__FILE__) + '/migs/migs_codes'
2
+
3
+ require 'digest/md5' # Used in add_secure_hash
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ class MigsGateway < Gateway
8
+ include MigsCodes
9
+
10
+ API_VERSION = 1
11
+
12
+ SERVER_HOSTED_URL = 'https://migs.mastercard.com.au/vpcpay'
13
+ MERCHANT_HOSTED_URL = 'https://migs.mastercard.com.au/vpcdps'
14
+
15
+ # MiGS is supported throughout Asia Pacific, Middle East and Africa
16
+ # MiGS is used in Australia (AU) by ANZ (eGate), CBA (CommWeb) and more
17
+ # Source of Country List: http://www.scribd.com/doc/17811923
18
+ self.supported_countries = %w(AU AE BD BN EG HK ID IN JO KW LB LK MU MV MY NZ OM PH QA SA SG TT VN)
19
+
20
+ # The card types supported by the payment gateway
21
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
22
+
23
+ self.money_format = :cents
24
+
25
+ # The homepage URL of the gateway
26
+ self.homepage_url = 'http://mastercard.com/mastercardsps'
27
+
28
+ # The name of the gateway
29
+ self.display_name = 'MasterCard Internet Gateway Service (MiGS)'
30
+
31
+ # Creates a new MigsGateway
32
+ # The advanced_login/advanced_password fields are needed for
33
+ # advanced methods such as the capture, refund and status methods
34
+ #
35
+ # ==== Options
36
+ #
37
+ # * <tt>:login</tt> -- The MiGS Merchant ID (REQUIRED)
38
+ # * <tt>:password</tt> -- The MiGS Access Code (REQUIRED)
39
+ # * <tt>:secure_hash</tt> -- The MiGS Secure Hash
40
+ # (Required for Server Hosted payments)
41
+ # * <tt>:advanced_login</tt> -- The MiGS AMA User
42
+ # * <tt>:advanced_password</tt> -- The MiGS AMA User's password
43
+ def initialize(options = {})
44
+ requires!(options, :login, :password)
45
+ @test = options[:login].start_with?('TEST')
46
+ @options = options
47
+ super
48
+ end
49
+
50
+ # ==== Options
51
+ #
52
+ # * <tt>:order_id</tt> -- A reference for tracking the order (REQUIRED)
53
+ # * <tt>:unique_id</tt> -- A unique id for this request (Max 40 chars).
54
+ # If not supplied one will be generated.
55
+ def purchase(money, creditcard, options = {})
56
+ requires!(options, :order_id)
57
+
58
+ post = {}
59
+ post[:Amount] = amount(money)
60
+ add_invoice(post, options)
61
+ add_creditcard(post, creditcard)
62
+ add_standard_parameters('pay', post, options[:unique_id])
63
+
64
+ commit(post)
65
+ end
66
+
67
+ # MiGS works by merchants being either purchase only or authorize/capture
68
+ # So authorize is the same as purchase when in authorize mode
69
+ alias_method :authorize, :purchase
70
+
71
+ # ==== Options
72
+ #
73
+ # * <tt>:unique_id</tt> -- A unique id for this request (Max 40 chars).
74
+ # If not supplied one will be generated.
75
+ def capture(money, authorization, options = {})
76
+ requires!(@options, :advanced_login, :advanced_password)
77
+
78
+ post = options.merge(:TransNo => authorization)
79
+ post[:Amount] = amount(money)
80
+ add_advanced_user(post)
81
+ add_standard_parameters('capture', post, options[:unique_id])
82
+
83
+ commit(post)
84
+ end
85
+
86
+ # ==== Options
87
+ #
88
+ # * <tt>:unique_id</tt> -- A unique id for this request (Max 40 chars).
89
+ # If not supplied one will be generated.
90
+ def refund(money, authorization, options = {})
91
+ requires!(@options, :advanced_login, :advanced_password)
92
+
93
+ post = options.merge(:TransNo => authorization)
94
+ post[:Amount] = amount(money)
95
+ add_advanced_user(post)
96
+ add_standard_parameters('refund', post, options[:unique_id])
97
+
98
+ commit(post)
99
+ end
100
+
101
+ def credit(money, authorization, options = {})
102
+ deprecated CREDIT_DEPRECATION_MESSAGE
103
+ refund(money, authorization, options)
104
+ end
105
+
106
+ # Checks the status of a previous transaction
107
+ # This can be useful when a response is not received due to network issues
108
+ #
109
+ # ==== Parameters
110
+ #
111
+ # * <tt>unique_id</tt> -- Unique id of transaction to find.
112
+ # This is the value of the option supplied in other methods or
113
+ # if not supplied is returned with key :MerchTxnRef
114
+ def status(unique_id)
115
+ requires!(@options, :advanced_login, :advanced_password)
116
+
117
+ post = {}
118
+ add_advanced_user(post)
119
+ add_standard_parameters('queryDR', post, unique_id)
120
+
121
+ commit(post)
122
+ end
123
+
124
+ # Generates a URL to redirect user to MiGS to process payment
125
+ # Once user is finished MiGS will redirect back to specified URL
126
+ # With a response hash which can be turned into a Response object
127
+ # with purchase_offsite_response
128
+ #
129
+ # ==== Options
130
+ #
131
+ # * <tt>:order_id</tt> -- A reference for tracking the order (REQUIRED)
132
+ # * <tt>:locale</tt> -- Change the language of the redirected page
133
+ # Values are 2 digit locale, e.g. en, es
134
+ # * <tt>:return_url</tt> -- the URL to return to once the payment is complete
135
+ # * <tt>:card_type</tt> -- Providing this skips the card type step.
136
+ # Values are ActiveMerchant formats: e.g. master, visa, american_express, diners_club
137
+ # * <tt>:unique_id</tt> -- Unique id of transaction to find.
138
+ # If not supplied one will be generated.
139
+ def purchase_offsite_url(money, options = {})
140
+ requires!(options, :order_id, :return_url)
141
+ requires!(@options, :secure_hash)
142
+
143
+ post = {}
144
+ post[:Amount] = amount(money)
145
+ add_invoice(post, options)
146
+ add_creditcard_type(post, options[:card_type]) if options[:card_type]
147
+
148
+ post.merge!(
149
+ :Locale => options[:locale] || 'en',
150
+ :ReturnURL => options[:return_url]
151
+ )
152
+
153
+ add_standard_parameters('pay', post, options[:unique_id])
154
+
155
+ add_secure_hash(post)
156
+
157
+ SERVER_HOSTED_URL + '?' + post_data(post)
158
+ end
159
+
160
+ # Parses a response from purchase_offsite_url once user is redirected back
161
+ #
162
+ # ==== Parameters
163
+ #
164
+ # * <tt>data</tt> -- All params when offsite payment returns
165
+ # e.g. returns to http://company.com/return?a=1&b=2, then input "a=1&b=2"
166
+ def purchase_offsite_response(data)
167
+ requires!(@options, :secure_hash)
168
+
169
+ response_hash = parse(data)
170
+
171
+ expected_secure_hash = calculate_secure_hash(response_hash.reject{|k, v| k == :SecureHash}, @options[:secure_hash])
172
+ unless response_hash[:SecureHash] == expected_secure_hash
173
+ raise SecurityError, "Secure Hash mismatch, response may be tampered with"
174
+ end
175
+
176
+ response_object(response_hash)
177
+ end
178
+
179
+ private
180
+
181
+ def add_advanced_user(post)
182
+ post[:User] = @options[:advanced_login]
183
+ post[:Password] = @options[:advanced_password]
184
+ end
185
+
186
+ def add_invoice(post, options)
187
+ post[:OrderInfo] = options[:order_id]
188
+ end
189
+
190
+ def add_creditcard(post, creditcard)
191
+ post[:CardNum] = creditcard.number
192
+ post[:CardSecurityCode] = creditcard.verification_value if creditcard.verification_value?
193
+ post[:CardExp] = format(creditcard.year, :two_digits) + format(creditcard.month, :two_digits)
194
+ end
195
+
196
+ def add_creditcard_type(post, card_type)
197
+ post[:Gateway] = 'ssl'
198
+ post[:card] = CARD_TYPES.detect{|ct| ct.am_code == card_type}.migs_long_code
199
+ end
200
+
201
+ def parse(body)
202
+ params = CGI::parse(body)
203
+ hash = {}
204
+ params.each do |key, value|
205
+ hash[key.gsub('vpc_', '').to_sym] = value[0]
206
+ end
207
+ hash
208
+ end
209
+
210
+ def commit(post)
211
+ data = ssl_post MERCHANT_HOSTED_URL, post_data(post)
212
+ response_hash = parse(data)
213
+ response_object(response_hash)
214
+ end
215
+
216
+ def response_object(response)
217
+ Response.new(success?(response), response[:Message], response,
218
+ :test => @test,
219
+ :authorization => response[:TransactionNo],
220
+ :fraud_review => fraud_review?(response),
221
+ :avs_result => { :code => response[:AVSResultCode] },
222
+ :cvv_result => response[:CSCResultCode]
223
+ )
224
+ end
225
+
226
+ def success?(response)
227
+ response[:TxnResponseCode] == '0'
228
+ end
229
+
230
+ def fraud_review?(response)
231
+ ISSUER_RESPONSE_CODES[response[:AcqResponseCode]] == 'Suspected Fraud'
232
+ end
233
+
234
+ def add_standard_parameters(action, post, unique_id = nil)
235
+ post.merge!(
236
+ :Version => API_VERSION,
237
+ :Merchant => @options[:login],
238
+ :AccessCode => @options[:password],
239
+ :Command => action,
240
+ :MerchTxnRef => unique_id || generate_unique_id.slice(0, 40)
241
+ )
242
+ end
243
+
244
+ def post_data(post)
245
+ post.collect { |key, value| "vpc_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
246
+ end
247
+
248
+ def add_secure_hash(post)
249
+ post[:SecureHash] = calculate_secure_hash(post, @options[:secure_hash])
250
+ end
251
+
252
+ def calculate_secure_hash(post, secure_hash)
253
+ sorted_values = post.sort_by(&:to_s).map(&:last)
254
+ input = secure_hash + sorted_values.join
255
+ Digest::MD5.hexdigest(input).upcase
256
+ end
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,100 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ module MigsCodes
4
+ TXN_RESPONSE_CODES = {
5
+ '?' => 'Response Unknown',
6
+ '0' => 'Transaction Successful',
7
+ '1' => 'Transaction Declined - Bank Error',
8
+ '2' => 'Bank Declined Transaction',
9
+ '3' => 'Transaction Declined - No Reply from Bank',
10
+ '4' => 'Transaction Declined - Expired Card',
11
+ '5' => 'Transaction Declined - Insufficient funds',
12
+ '6' => 'Transaction Declined - Error Communicating with Bank',
13
+ '7' => 'Payment Server Processing Error - Typically caused by invalid input data such as an invalid credit card number. Processing errors can also occur',
14
+ '8' => 'Transaction Declined - Transaction Type Not Supported',
15
+ '9' => 'Bank Declined Transaction (Do not contact Bank)',
16
+ 'A' => 'Transaction Aborted',
17
+ 'C' => 'Transaction Cancelled',
18
+ 'D' => 'Deferred Transaction',
19
+ 'E' => 'Issuer Returned a Referral Response',
20
+ 'F' => '3D Secure Authentication Failed',
21
+ 'I' => 'Card Security Code Failed',
22
+ 'L' => 'Shopping Transaction Locked (This indicates that there is another transaction taking place using the same shopping transaction number)',
23
+ 'N' => 'Cardholder is not enrolled in 3D Secure (Authentication Only)',
24
+ 'P' => 'Transaction is Pending',
25
+ 'R' => 'Retry Limits Exceeded, Transaction Not Processed',
26
+ 'S' => 'Duplicate OrderInfo used. (This is only relevant for Payment Servers that enforce the uniqueness of this field)',
27
+ 'U' => 'Card Security Code Failed'
28
+ }
29
+
30
+ ISSUER_RESPONSE_CODES = {
31
+ '00' => 'Approved',
32
+ '01' => 'Refer to Card Issuer',
33
+ '02' => 'Refer to Card Issuer',
34
+ '03' => 'Invalid Merchant',
35
+ '04' => 'Pick Up Card',
36
+ '05' => 'Do Not Honor',
37
+ '07' => 'Pick Up Card',
38
+ '12' => 'Invalid Transaction',
39
+ '14' => 'Invalid Card Number (No such Number)',
40
+ '15' => 'No Such Issuer',
41
+ '33' => 'Expired Card',
42
+ '34' => 'Suspected Fraud',
43
+ '36' => 'Restricted Card',
44
+ '39' => 'No Credit Account',
45
+ '41' => 'Card Reported Lost',
46
+ '43' => 'Stolen Card',
47
+ '51' => 'Insufficient Funds',
48
+ '54' => 'Expired Card',
49
+ '57' => 'Transaction Not Permitted',
50
+ '59' => 'Suspected Fraud',
51
+ '62' => 'Restricted Card',
52
+ '65' => 'Exceeds withdrawal frequency limit',
53
+ '91' => 'Cannot Contact Issuer'
54
+ }
55
+
56
+ VERIFIED_3D_CODES = {
57
+ 'Y' => 'The cardholder was successfully authenticated.',
58
+ 'E' => 'The cardholder is not enrolled.',
59
+ 'N' => 'The cardholder was not verified.',
60
+ 'U' => 'The cardholder\'s Issuer was unable to authenticate due to a system error at the Issuer.',
61
+ 'F' => 'An error exists in the format of the request from the merchant. For example, the request did not contain all required fields, or the format of some fields was invalid.',
62
+ 'A' => 'Authentication of your Merchant ID and Password to the Directory Server Failed (see "What does a Payment Authentication Status of "A" mean?" on page 85).',
63
+ 'D' => 'Error communicating with the Directory Server, for example, the Payment Server could not connect to the directory server or there was a versioning mismatch.',
64
+ 'C' => 'The card type is not supported for authentication.',
65
+ 'M' => 'This indicates that attempts processing was used. Verification is marked with status M - ACS attempts processing used. Payment is performed with authentication. Attempts is when a cardholder has successfully passed the directory server but decides not to continue with the authentication process and cancels.',
66
+ 'S' => 'The signature on the response received from the Issuer could not be validated. This should be considered a failure.',
67
+ 'T' => 'ACS timed out. The Issuer\'s ACS did not respond to the Authentication request within the time out period.',
68
+ 'P' => 'Error parsing input from Issuer.',
69
+ 'I' => 'Internal Payment Server system error. This could be caused by a temporary DB failure or an error in the security module or by some error in an internal system.'
70
+ }
71
+
72
+ class CreditCardType
73
+ attr_accessor :am_code, :migs_code, :migs_long_code, :name
74
+ def initialize(am_code, migs_code, migs_long_code, name)
75
+ @am_code = am_code
76
+ @migs_code = migs_code
77
+ @migs_long_code = migs_long_code
78
+ @name = name
79
+ end
80
+ end
81
+
82
+ CARD_TYPES = [
83
+ # The following are 4 different representations of credit card types
84
+ # am_code: The active merchant code
85
+ # migs_code: Used in response for purchase/authorize/status
86
+ # migs_long_code: Used to pre-select card for server_purchase_url
87
+ # name: The nice display name
88
+ %w(american_express AE Amex American\ Express),
89
+ %w(diners_club DC Dinersclub Diners\ Club),
90
+ %w(jcb JC JCB JCB\ Card),
91
+ %w(maestro MS Maestro Maestro\ Card),
92
+ %w(master MC Mastercard MasterCard),
93
+ %w(na PL PrivateLabelCard Private\ Label\ Card),
94
+ %w(visa VC Visa Visa\ Card')
95
+ ].map do |am_code, migs_code, migs_long_code, name|
96
+ CreditCardType.new(am_code, migs_code, migs_long_code, name)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/modern_payments_cim'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class ModernPaymentsGateway < Gateway
6
+ self.supported_countries = ModernPaymentsCimGateway.supported_countries
7
+ self.supported_cardtypes = ModernPaymentsCimGateway.supported_cardtypes
8
+ self.homepage_url = ModernPaymentsCimGateway.homepage_url
9
+ self.display_name = ModernPaymentsCimGateway.display_name
10
+
11
+ def initialize(options = {})
12
+ requires!(options, :login, :password)
13
+ @options = options
14
+ super
15
+ end
16
+
17
+ def purchase(money, credit_card, options = {})
18
+ customer_response = cim.create_customer(options)
19
+ return customer_response unless customer_response.success?
20
+
21
+ customer_id = customer_response.params["create_customer_result"]
22
+
23
+ card_response = cim.modify_customer_credit_card(customer_id, credit_card)
24
+ return card_response unless card_response.success?
25
+
26
+ cim.authorize_credit_card_payment(customer_id, money)
27
+ end
28
+
29
+ private
30
+ def cim
31
+ @cim ||= ModernPaymentsCimGateway.new(@options)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,220 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class ModernPaymentsCimGateway < Gateway #:nodoc:
4
+ TEST_URL = "https://secure.modpay.com/netservices/test/ModpayTest.asmx"
5
+ LIVE_URL = 'https://secure.modpay.com/ws/modpay.asmx'
6
+
7
+ LIVE_XMLNS = "https://secure.modpay.com/ws/"
8
+ TEST_XMLNS = "https://secure.modpay.com/netservices/test/"
9
+
10
+ self.supported_countries = ['US']
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
12
+ self.homepage_url = 'http://www.modpay.com'
13
+ self.display_name = 'Modern Payments'
14
+
15
+ SUCCESS_MESSAGE = "Transaction accepted"
16
+ FAILURE_MESSAGE = "Transaction failed"
17
+ ERROR_MESSAGE = "Transaction error"
18
+
19
+ PAYMENT_METHOD = {
20
+ :check => 1,
21
+ :credit_card => 2
22
+ }
23
+
24
+ def initialize(options = {})
25
+ requires!(options, :login, :password)
26
+ @options = options
27
+ super
28
+ end
29
+
30
+ def create_customer(options = {})
31
+ post = {}
32
+ add_customer_data(post, options)
33
+ add_address(post, options)
34
+
35
+ commit('CreateCustomer', post)
36
+ end
37
+
38
+ def modify_customer_credit_card(customer_id, credit_card)
39
+ raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
40
+
41
+ post = {}
42
+ add_customer_id(post, customer_id)
43
+ add_credit_card(post, credit_card)
44
+
45
+ commit('ModifyCustomerCreditCard', post)
46
+ end
47
+
48
+ def authorize_credit_card_payment(customer_id, amount)
49
+ raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
50
+
51
+ post = {}
52
+ add_customer_id(post, customer_id)
53
+ add_amount(post, amount)
54
+
55
+ commit('AuthorizeCreditCardPayment', post)
56
+ end
57
+
58
+ def create_payment(customer_id, amount, options = {})
59
+ raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
60
+
61
+ post = {}
62
+ add_customer_id(post, customer_id)
63
+ add_amount(post, amount)
64
+ add_payment_details(post, options)
65
+
66
+ commit('CreatePayment', post)
67
+ end
68
+
69
+ private
70
+ def add_payment_details(post, options)
71
+ post[:pmtDate] = (options[:payment_date] || Time.now.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
72
+ post[:pmtType] = PAYMENT_METHOD[options[:payment_method] || :credit_card]
73
+ end
74
+
75
+ def add_amount(post, money)
76
+ post[:pmtAmount] = amount(money)
77
+ end
78
+
79
+ def add_customer_id(post, customer_id)
80
+ post[:custId] = customer_id
81
+ end
82
+
83
+ def add_customer_data(post, options)
84
+ post[:acctNum] = options[:customer]
85
+ end
86
+
87
+ def add_address(post, options)
88
+ address = options[:billing_address] || options[:address] || {}
89
+
90
+ if name = address[:name]
91
+ segments = name.split(' ')
92
+ post[:lastName] = segments.pop
93
+ post[:firstName] = segments.join(' ')
94
+ else
95
+ post[:firstName] = address[:first_name]
96
+ post[:lastName] = address[:last_name]
97
+ end
98
+
99
+ post[:address] = address[:address1]
100
+ post[:city] = address[:city]
101
+ post[:state] = address[:state]
102
+ post[:zip] = address[:zip]
103
+ post[:phone] = address[:phone]
104
+ post[:fax] = address[:fax]
105
+ post[:email] = options[:email]
106
+ end
107
+
108
+ def add_credit_card(post, credit_card)
109
+ post[:ccName] = credit_card.name
110
+ post[:ccNum] = credit_card.number
111
+ post[:expMonth] = credit_card.month
112
+ post[:expYear] = credit_card.year
113
+ end
114
+
115
+ def build_request(action, params)
116
+ xml = Builder::XmlMarkup.new :indent => 2
117
+ xml.instruct!
118
+ xml.tag! 'env:Envelope',
119
+ { 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
120
+ 'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/',
121
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' } do
122
+
123
+ xml.tag! 'env:Body' do
124
+ xml.tag! action, { "xmlns" => xmlns(action) } do
125
+ xml.tag! "clientId", @options[:login]
126
+ xml.tag! "clientCode", @options[:password]
127
+ params.each {|key, value| xml.tag! key, value }
128
+ end
129
+ end
130
+ end
131
+ xml.target!
132
+ end
133
+
134
+ def xmlns(action)
135
+ if test? && action == 'AuthorizeCreditCardPayment'
136
+ TEST_XMLNS
137
+ else
138
+ LIVE_XMLNS
139
+ end
140
+ end
141
+
142
+ def url(action)
143
+ if test? && action == 'AuthorizeCreditCardPayment'
144
+ TEST_URL
145
+ else
146
+ LIVE_URL
147
+ end
148
+ end
149
+
150
+ def commit(action, params)
151
+ data = ssl_post(url(action), build_request(action, params),
152
+ { 'Content-Type' =>'text/xml; charset=utf-8',
153
+ 'SOAPAction' => "#{xmlns(action)}#{action}" }
154
+ )
155
+
156
+ response = parse(action, data)
157
+ Response.new(successful?(action, response), message_from(action, response), response,
158
+ :test => test?,
159
+ :authorization => authorization_from(action, response),
160
+ :avs_result => { :code => response[:avs_code] }
161
+ )
162
+ end
163
+
164
+ def authorization_from(action, response)
165
+ response[authorization_key(action)]
166
+ end
167
+
168
+ def authorization_key(action)
169
+ action == "AuthorizeCreditCardPayment" ? :trans_id : "#{action.underscore}_result".to_sym
170
+ end
171
+
172
+ def successful?(action, response)
173
+ key = authorization_key(action)
174
+
175
+ if key == :trans_id
176
+ response[:approved] == "true"
177
+ else
178
+ response[key].to_i > 0
179
+ end
180
+ end
181
+
182
+ def message_from(action, response)
183
+ if response[:faultcode]
184
+ ERROR_MESSAGE
185
+ elsif successful?(action, response)
186
+ SUCCESS_MESSAGE
187
+ else
188
+ FAILURE_MESSAGE
189
+ end
190
+ end
191
+
192
+ def parse(action, xml)
193
+ response = {}
194
+ response[:action] = action
195
+
196
+ xml = REXML::Document.new(xml)
197
+ if root = REXML::XPath.first(xml, "//#{action}Response")
198
+ root.elements.to_a.each do |node|
199
+ parse_element(response, node)
200
+ end
201
+ elsif root = REXML::XPath.first(xml, "//soap:Fault")
202
+ root.elements.to_a.each do |node|
203
+ response[node.name.underscore.to_sym] = node.text
204
+ end
205
+ end
206
+
207
+ response
208
+ end
209
+
210
+ def parse_element(response, node)
211
+ if node.has_elements?
212
+ node.elements.each{|e| parse_element(response, e) }
213
+ else
214
+ response[node.name.underscore.to_sym] = node.text.to_s.strip
215
+ end
216
+ end
217
+ end
218
+ end
219
+ end
220
+