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,142 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # Bogus Gateway
4
+ class BogusGateway < Gateway
5
+ AUTHORIZATION = '53433'
6
+
7
+ SUCCESS_MESSAGE = "Bogus Gateway: Forced success"
8
+ FAILURE_MESSAGE = "Bogus Gateway: Forced failure"
9
+ ERROR_MESSAGE = "Bogus Gateway: Use CreditCard number 1 for success, 2 for exception and anything else for error"
10
+ CREDIT_ERROR_MESSAGE = "Bogus Gateway: Use CreditCard number 1 for success, 2 for exception and anything else for error"
11
+ UNSTORE_ERROR_MESSAGE = "Bogus Gateway: Use trans_id 1 for success, 2 for exception and anything else for error"
12
+ CAPTURE_ERROR_MESSAGE = "Bogus Gateway: Use authorization number 1 for exception, 2 for error and anything else for success"
13
+ VOID_ERROR_MESSAGE = "Bogus Gateway: Use authorization number 1 for exception, 2 for error and anything else for success"
14
+ REFUND_ERROR_MESSAGE = "Bogus Gateway: Use trans_id number 1 for exception, 2 for error and anything else for success"
15
+
16
+ self.supported_countries = ['US']
17
+ self.supported_cardtypes = [:bogus]
18
+ self.homepage_url = 'http://example.com'
19
+ self.display_name = 'Bogus'
20
+
21
+ def authorize(money, credit_card_or_reference, options = {})
22
+ money = amount(money)
23
+ case normalize(credit_card_or_reference)
24
+ when '1'
25
+ Response.new(true, SUCCESS_MESSAGE, {:authorized_amount => money}, :test => true, :authorization => AUTHORIZATION )
26
+ when '2'
27
+ Response.new(false, FAILURE_MESSAGE, {:authorized_amount => money, :error => FAILURE_MESSAGE }, :test => true)
28
+ else
29
+ raise Error, ERROR_MESSAGE
30
+ end
31
+ end
32
+
33
+ def purchase(money, credit_card_or_reference, options = {})
34
+ money = amount(money)
35
+ case normalize(credit_card_or_reference)
36
+ when '1', AUTHORIZATION
37
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
38
+ when '2'
39
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE },:test => true)
40
+ else
41
+ raise Error, ERROR_MESSAGE
42
+ end
43
+ end
44
+
45
+ def recurring(money, credit_card_or_reference, options = {})
46
+ money = amount(money)
47
+ case normalize(credit_card_or_reference)
48
+ when '1'
49
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
50
+ when '2'
51
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE },:test => true)
52
+ else
53
+ raise Error, ERROR_MESSAGE
54
+ end
55
+ end
56
+
57
+ def credit(money, credit_card_or_reference, options = {})
58
+ if credit_card_or_reference.is_a?(String)
59
+ deprecated CREDIT_DEPRECATION_MESSAGE
60
+ return refund(money, credit_card_or_reference, options)
61
+ end
62
+
63
+ money = amount(money)
64
+ case normalize(credit_card_or_reference)
65
+ when '1'
66
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true )
67
+ when '2'
68
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
69
+ else
70
+ raise Error, CREDIT_ERROR_MESSAGE
71
+ end
72
+ end
73
+
74
+ def refund(money, reference, options = {})
75
+ money = amount(money)
76
+ case reference
77
+ when '1'
78
+ raise Error, REFUND_ERROR_MESSAGE
79
+ when '2'
80
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
81
+ else
82
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
83
+ end
84
+ end
85
+
86
+ def capture(money, reference, options = {})
87
+ money = amount(money)
88
+ case reference
89
+ when '1'
90
+ raise Error, CAPTURE_ERROR_MESSAGE
91
+ when '2'
92
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
93
+ else
94
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
95
+ end
96
+ end
97
+
98
+ def void(reference, options = {})
99
+ case reference
100
+ when '1'
101
+ raise Error, VOID_ERROR_MESSAGE
102
+ when '2'
103
+ Response.new(false, FAILURE_MESSAGE, {:authorization => reference, :error => FAILURE_MESSAGE }, :test => true)
104
+ else
105
+ Response.new(true, SUCCESS_MESSAGE, {:authorization => reference}, :test => true)
106
+ end
107
+ end
108
+
109
+ def store(credit_card_or_reference, options = {})
110
+ case normalize(credit_card_or_reference)
111
+ when '1'
112
+ Response.new(true, SUCCESS_MESSAGE, {:billingid => '1'}, :test => true, :authorization => AUTHORIZATION)
113
+ when '2'
114
+ Response.new(false, FAILURE_MESSAGE, {:billingid => nil, :error => FAILURE_MESSAGE }, :test => true)
115
+ else
116
+ raise Error, ERROR_MESSAGE
117
+ end
118
+ end
119
+
120
+ def unstore(reference, options = {})
121
+ case reference
122
+ when '1'
123
+ Response.new(true, SUCCESS_MESSAGE, {}, :test => true)
124
+ when '2'
125
+ Response.new(false, FAILURE_MESSAGE, {:error => FAILURE_MESSAGE },:test => true)
126
+ else
127
+ raise Error, UNSTORE_ERROR_MESSAGE
128
+ end
129
+ end
130
+
131
+ private
132
+
133
+ def normalize(credit_card_or_reference)
134
+ if credit_card_or_reference.respond_to?(:number)
135
+ credit_card_or_reference.number
136
+ else
137
+ credit_card_or_reference.to_s
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class BraintreeGateway < Gateway
6
+ include BraintreeCommon
7
+
8
+ def self.new(options={})
9
+ if options.has_key?(:login)
10
+ BraintreeOrangeGateway.new(options)
11
+ else
12
+ BraintreeBlueGateway.new(options)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module BraintreeCommon
2
+ def self.included(base)
3
+ base.supported_countries = ['US']
4
+ base.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
5
+ base.homepage_url = 'http://www.braintreepaymentsolutions.com'
6
+ base.display_name = 'Braintree'
7
+ base.default_currency = 'USD'
8
+ end
9
+ end
@@ -0,0 +1,335 @@
1
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
2
+
3
+ begin
4
+ require "braintree"
5
+ rescue LoadError
6
+ raise "Could not load the braintree gem. Use `gem install braintree` to install it."
7
+ end
8
+
9
+ raise "Need braintree gem 2.x.y. Run `gem install braintree --version '~>2.0'` to get the correct version." unless Braintree::Version::Major == 2
10
+
11
+ module ActiveMerchant #:nodoc:
12
+ module Billing #:nodoc:
13
+ class BraintreeBlueGateway < Gateway
14
+ include BraintreeCommon
15
+
16
+ self.display_name = 'Braintree (Blue Platform)'
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :merchant_id, :public_key, :private_key)
20
+ @options = options
21
+ @merchant_account_id = options[:merchant_account_id]
22
+ Braintree::Configuration.merchant_id = options[:merchant_id]
23
+ Braintree::Configuration.public_key = options[:public_key]
24
+ Braintree::Configuration.private_key = options[:private_key]
25
+ Braintree::Configuration.environment = (options[:environment] || (test? ? :sandbox : :production)).to_sym
26
+ Braintree::Configuration.logger.level = Logger::ERROR if Braintree::Configuration.logger
27
+ Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
28
+ super
29
+ end
30
+
31
+ def authorize(money, credit_card_or_vault_id, options = {})
32
+ create_transaction(:sale, money, credit_card_or_vault_id, options)
33
+ end
34
+
35
+ def capture(money, authorization, options = {})
36
+ commit do
37
+ result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
38
+ Response.new(result.success?, message_from_result(result))
39
+ end
40
+ end
41
+
42
+ def purchase(money, credit_card_or_vault_id, options = {})
43
+ authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
44
+ end
45
+
46
+ def credit(money, credit_card_or_vault_id, options = {})
47
+ create_transaction(:credit, money, credit_card_or_vault_id, options)
48
+ end
49
+
50
+ def refund(*args)
51
+ # legacy signature: #refund(transaction_id, options = {})
52
+ # new signature: #refund(money, transaction_id, options = {})
53
+ money, transaction_id, options = extract_refund_args(args)
54
+ money = amount(money).to_s if money
55
+
56
+ commit do
57
+ result = Braintree::Transaction.refund(transaction_id, money)
58
+ Response.new(result.success?, message_from_result(result),
59
+ {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
60
+ {:authorization => (result.transaction.id if result.success?)}
61
+ )
62
+ end
63
+ end
64
+
65
+ def void(authorization, options = {})
66
+ commit do
67
+ result = Braintree::Transaction.void(authorization)
68
+ Response.new(result.success?, message_from_result(result),
69
+ {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
70
+ {:authorization => (result.transaction.id if result.success?)}
71
+ )
72
+ end
73
+ end
74
+
75
+ def store(creditcard, options = {})
76
+ commit do
77
+ parameters = {
78
+ :first_name => creditcard.first_name,
79
+ :last_name => creditcard.last_name,
80
+ :email => options[:email],
81
+ :credit_card => {
82
+ :number => creditcard.number,
83
+ :cvv => creditcard.verification_value,
84
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
85
+ :expiration_year => creditcard.year.to_s
86
+ }
87
+ }
88
+ result = Braintree::Customer.create(merge_credit_card_options(parameters, options))
89
+ Response.new(result.success?, message_from_result(result),
90
+ {
91
+ :braintree_customer => (customer_hash(result.customer) if result.success?),
92
+ :customer_vault_id => (result.customer.id if result.success?)
93
+ }
94
+ )
95
+ end
96
+ end
97
+
98
+ def update(vault_id, creditcard, options = {})
99
+ braintree_credit_card = nil
100
+ customer_update_result = commit do
101
+ braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
102
+ return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
103
+
104
+ options.merge!(:update_existing_token => braintree_credit_card.token)
105
+ credit_card_params = merge_credit_card_options({
106
+ :credit_card => {
107
+ :number => creditcard.number,
108
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
109
+ :expiration_year => creditcard.year.to_s
110
+ }
111
+ }, options)[:credit_card]
112
+
113
+ result = Braintree::Customer.update(vault_id,
114
+ :first_name => creditcard.first_name,
115
+ :last_name => creditcard.last_name,
116
+ :email => options[:email],
117
+ :credit_card => credit_card_params
118
+ )
119
+ Response.new(result.success?, message_from_result(result),
120
+ :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?),
121
+ :customer_vault_id => (result.customer.id if result.success?)
122
+ )
123
+ end
124
+ end
125
+
126
+ def unstore(customer_vault_id)
127
+ commit do
128
+ Braintree::Customer.delete(customer_vault_id)
129
+ Response.new(true, "OK")
130
+ end
131
+ end
132
+ alias_method :delete, :unstore
133
+
134
+ private
135
+
136
+ def merge_credit_card_options(parameters, options)
137
+ valid_options = {}
138
+ options.each do |key, value|
139
+ valid_options[key] = value if [:update_existing_token, :verify_card, :verification_merchant_account_id].include?(key)
140
+ end
141
+
142
+ parameters[:credit_card] ||= {}
143
+ parameters[:credit_card].merge!(:options => valid_options)
144
+ parameters[:credit_card][:billing_address] = map_address(options[:billing_address]) if options[:billing_address]
145
+ parameters
146
+ end
147
+
148
+ def map_address(address)
149
+ return {} if address.nil?
150
+ mapped = {
151
+ :street_address => address[:address1],
152
+ :extended_address => address[:address2],
153
+ :company => address[:company],
154
+ :locality => address[:city],
155
+ :region => address[:state],
156
+ :postal_code => address[:zip],
157
+ }
158
+ if(address[:country] || address[:country_code_alpha2])
159
+ mapped[:country_code_alpha2] = (address[:country] || address[:country_code_alpha2])
160
+ elsif address[:country_name]
161
+ mapped[:country_name] = address[:country_name]
162
+ elsif address[:country_code_alpha3]
163
+ mapped[:country_code_alpha3] = address[:country_code_alpha3]
164
+ elsif address[:country_code_numeric]
165
+ mapped[:country_code_numeric] = address[:country_code_numeric]
166
+ end
167
+ mapped
168
+ end
169
+
170
+ def commit(&block)
171
+ yield
172
+ rescue Braintree::BraintreeError => ex
173
+ Response.new(false, ex.class.to_s)
174
+ end
175
+
176
+ def message_from_result(result)
177
+ if result.success?
178
+ "OK"
179
+ elsif result.errors.size == 0 && result.credit_card_verification
180
+ "Processor declined: #{result.credit_card_verification.processor_response_text} (#{result.credit_card_verification.processor_response_code})"
181
+ else
182
+ result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
183
+ end
184
+ end
185
+
186
+ def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
187
+ transaction_params = create_transaction_parameters(money, credit_card_or_vault_id, options)
188
+
189
+ commit do
190
+ result = Braintree::Transaction.send(transaction_type, transaction_params)
191
+ response_params, response_options, avs_result, cvv_result = {}, {}, {}, {}
192
+ if result.success?
193
+ response_params[:braintree_transaction] = transaction_hash(result.transaction)
194
+ response_params[:customer_vault_id] = result.transaction.customer_details.id
195
+ response_options[:authorization] = result.transaction.id
196
+ end
197
+ if result.transaction
198
+ response_options[:avs_result] = {
199
+ :code => nil, :message => nil,
200
+ :street_match => result.transaction.avs_street_address_response_code,
201
+ :postal_match => result.transaction.avs_postal_code_response_code
202
+ }
203
+ response_options[:cvv_result] = result.transaction.cvv_response_code
204
+ if result.transaction.status == "gateway_rejected"
205
+ message = "Transaction declined - gateway rejected"
206
+ else
207
+ message = "#{result.transaction.processor_response_code} #{result.transaction.processor_response_text}"
208
+ end
209
+ else
210
+ message = message_from_result(result)
211
+ end
212
+ response = Response.new(result.success?, message, response_params, response_options)
213
+ response.cvv_result['message'] = ''
214
+ response
215
+ end
216
+ end
217
+
218
+ def extract_refund_args(args)
219
+ options = args.extract_options!
220
+
221
+ # money, transaction_id, options
222
+ if args.length == 1 # legacy signature
223
+ return nil, args[0], options
224
+ elsif args.length == 2
225
+ return args[0], args[1], options
226
+ else
227
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
228
+ end
229
+ end
230
+
231
+ def customer_hash(customer)
232
+ credit_cards = customer.credit_cards.map do |cc|
233
+ {
234
+ "bin" => cc.bin,
235
+ "expiration_date" => cc.expiration_date,
236
+ "token" => cc.token
237
+ }
238
+ end
239
+
240
+ {
241
+ "email" => customer.email,
242
+ "first_name" => customer.first_name,
243
+ "last_name" => customer.last_name,
244
+ "credit_cards" => credit_cards,
245
+ "id" => customer.id
246
+ }
247
+ end
248
+
249
+ def transaction_hash(transaction)
250
+ if transaction.vault_customer
251
+ vault_customer = {
252
+ }
253
+ vault_customer["credit_cards"] = transaction.vault_customer.credit_cards.map do |cc|
254
+ {
255
+ "bin" => cc.bin
256
+ }
257
+ end
258
+ else
259
+ vault_customer = nil
260
+ end
261
+
262
+ customer_details = {
263
+ "id" => transaction.customer_details.id,
264
+ "email" => transaction.customer_details.email
265
+ }
266
+
267
+ billing_details = {
268
+ "street_address" => transaction.billing_details.street_address,
269
+ "extended_address" => transaction.billing_details.extended_address,
270
+ "company" => transaction.billing_details.company,
271
+ "locality" => transaction.billing_details.locality,
272
+ "region" => transaction.billing_details.region,
273
+ "postal_code" => transaction.billing_details.postal_code,
274
+ "country_name" => transaction.billing_details.country_name,
275
+ }
276
+
277
+ shipping_details = {
278
+ "street_address" => transaction.shipping_details.street_address,
279
+ "extended_address" => transaction.shipping_details.extended_address,
280
+ "company" => transaction.shipping_details.company,
281
+ "locality" => transaction.shipping_details.locality,
282
+ "region" => transaction.shipping_details.region,
283
+ "postal_code" => transaction.shipping_details.postal_code,
284
+ "country_name" => transaction.shipping_details.country_name,
285
+ }
286
+
287
+ {
288
+ "order_id" => transaction.order_id,
289
+ "status" => transaction.status,
290
+ "customer_details" => customer_details,
291
+ "billing_details" => billing_details,
292
+ "shipping_details" => shipping_details,
293
+ "vault_customer" => vault_customer,
294
+ "merchant_account_id" => transaction.merchant_account_id
295
+ }
296
+ end
297
+
298
+ def create_transaction_parameters(money, credit_card_or_vault_id, options)
299
+ parameters = {
300
+ :amount => amount(money).to_s,
301
+ :order_id => options[:order_id],
302
+ :customer => {
303
+ :id => options[:store] == true ? "" : options[:store],
304
+ :email => options[:email]
305
+ },
306
+ :options => {
307
+ :store_in_vault => options[:store] ? true : false,
308
+ :submit_for_settlement => options[:submit_for_settlement]
309
+ }
310
+ }
311
+ if merchant_account_id = (options[:merchant_account_id] || @merchant_account_id)
312
+ parameters[:merchant_account_id] = merchant_account_id
313
+ end
314
+ if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
315
+ parameters[:customer_id] = credit_card_or_vault_id
316
+ else
317
+ parameters[:customer].merge!(
318
+ :first_name => credit_card_or_vault_id.first_name,
319
+ :last_name => credit_card_or_vault_id.last_name
320
+ )
321
+ parameters[:credit_card] = {
322
+ :number => credit_card_or_vault_id.number,
323
+ :cvv => credit_card_or_vault_id.verification_value,
324
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
325
+ :expiration_year => credit_card_or_vault_id.year.to_s
326
+ }
327
+ end
328
+ parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
329
+ parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
330
+ parameters
331
+ end
332
+ end
333
+ end
334
+ end
335
+