fishman-activemerchant 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/CHANGELOG +733 -0
  2. data/CONTRIBUTORS +257 -0
  3. data/MIT-LICENSE +20 -0
  4. data/gem-public_cert.pem +20 -0
  5. data/lib/active_merchant.rb +47 -0
  6. data/lib/active_merchant/billing.rb +9 -0
  7. data/lib/active_merchant/billing/avs_result.rb +98 -0
  8. data/lib/active_merchant/billing/base.rb +57 -0
  9. data/lib/active_merchant/billing/check.rb +68 -0
  10. data/lib/active_merchant/billing/credit_card.rb +260 -0
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  12. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  15. data/lib/active_merchant/billing/gateway.rb +170 -0
  16. data/lib/active_merchant/billing/gateways.rb +18 -0
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +693 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
  19. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  24. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  25. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  26. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  27. data/lib/active_merchant/billing/gateways/braintree_blue.rb +303 -0
  28. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  29. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  30. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  31. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  32. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  33. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  34. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  35. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  36. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  37. data/lib/active_merchant/billing/gateways/eway_managed.rb +264 -0
  38. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  39. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  40. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  41. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  42. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  43. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  45. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  46. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  47. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  48. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  49. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  50. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  51. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
  52. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  53. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  54. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  55. data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
  56. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  57. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  58. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  59. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  60. data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
  61. data/lib/active_merchant/billing/gateways/optimal_payment.rb +274 -0
  62. data/lib/active_merchant/billing/gateways/orbital.rb +321 -0
  63. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  64. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  65. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  66. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  67. data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
  68. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  69. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  70. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  72. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  73. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  74. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  75. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  76. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +354 -0
  77. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  78. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/paypal_express.rb +184 -0
  80. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  81. data/lib/active_merchant/billing/gateways/paypal_express_de.rb +14 -0
  82. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  83. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  84. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  85. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  86. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  87. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  88. data/lib/active_merchant/billing/gateways/quickpay.rb +297 -0
  89. data/lib/active_merchant/billing/gateways/realex.rb +311 -0
  90. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  91. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  92. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  93. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  94. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  95. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  96. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  97. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  98. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
  99. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  100. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  101. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  102. data/lib/active_merchant/billing/gateways/stripe.rb +212 -0
  103. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  104. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  105. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  106. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  107. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  108. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  109. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  110. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  111. data/lib/active_merchant/billing/integrations.rb +17 -0
  112. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  113. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  114. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  115. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  116. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  117. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  118. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  119. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  120. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  121. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  122. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  123. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  124. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  125. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  126. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  127. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  128. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  129. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  130. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  131. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +28 -0
  132. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +50 -0
  133. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  134. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  135. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  136. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  137. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  138. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  139. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  140. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  141. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  142. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  143. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  144. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  145. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  146. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  147. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  148. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  149. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  150. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  151. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  152. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  153. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  154. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  155. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  156. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +58 -0
  157. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  158. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  159. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  160. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  161. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  162. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  163. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  164. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  165. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  166. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  167. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  168. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  169. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  170. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  171. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  172. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  173. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  174. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  175. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  176. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  177. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  178. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  179. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  180. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  181. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  182. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  183. data/lib/active_merchant/billing/response.rb +32 -0
  184. data/lib/active_merchant/version.rb +3 -0
  185. data/lib/activemerchant.rb +1 -0
  186. data/lib/support/gateway_support.rb +58 -0
  187. data/lib/support/outbound_hosts.rb +25 -0
  188. metadata +335 -0
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/beanstream/beanstream_core'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class BeanstreamInteracResponse < Response
6
+ def redirect
7
+ params['pageContents']
8
+ end
9
+ end
10
+
11
+ class BeanstreamInteracGateway < Gateway
12
+ include BeanstreamCore
13
+
14
+ # Confirm a transaction posted back from the bank to Beanstream.
15
+ # Confirming a transaction does not require any credentials,
16
+ # and in an application with many merchants sharing a funded
17
+ # URL the application may not yet know which merchant the
18
+ # post back is for until the response of the confirmation is
19
+ # received, which contains the order number.
20
+ def self.confirm(transaction)
21
+ gateway = new(:login => '')
22
+ gateway.confirm(transaction)
23
+ end
24
+
25
+ def purchase(money, options = {})
26
+ post = {}
27
+ add_amount(post, money)
28
+ add_invoice(post, options)
29
+ add_address(post, options)
30
+ add_interac_details(post, options)
31
+ add_transaction_type(post, :purchase)
32
+ commit(post)
33
+ end
34
+
35
+ # Confirm a transaction posted back from the bank to Beanstream.
36
+ def confirm(transaction)
37
+ post(transaction)
38
+ end
39
+
40
+ private
41
+
42
+ def add_interac_details(post, options)
43
+ address = options[:billing_address] || options[:address] || {}
44
+ post[:trnCardOwner] = address[:name]
45
+ post[:paymentMethod] = 'IO'
46
+ end
47
+
48
+ def build_response(*args)
49
+ BeanstreamInteracResponse.new(*args)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,11 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class BluePayGateway < AuthorizeNetGateway
4
+ self.test_url = "https://secure.bluepay.com/interfaces/a.net.test"
5
+ self.live_url = "https://secure.bluepay.com/interfaces/a.net"
6
+ self.homepage_url = 'http://www.bluepay.com/'
7
+ self.display_name = 'BluePay'
8
+ end
9
+ end
10
+ end
11
+
@@ -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,303 @@
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
+ Braintree::Configuration.merchant_id = options[:merchant_id]
22
+ Braintree::Configuration.public_key = options[:public_key]
23
+ Braintree::Configuration.private_key = options[:private_key]
24
+ Braintree::Configuration.environment = test? ? :sandbox : :production
25
+ Braintree::Configuration.logger.level = Logger::ERROR if Braintree::Configuration.logger
26
+ Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
27
+ super
28
+ end
29
+
30
+ def authorize(money, credit_card_or_vault_id, options = {})
31
+ create_transaction(:sale, money, credit_card_or_vault_id, options)
32
+ end
33
+
34
+ def capture(money, authorization, options = {})
35
+ commit do
36
+ result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
37
+ Response.new(result.success?, message_from_result(result))
38
+ end
39
+ end
40
+
41
+ def purchase(money, credit_card_or_vault_id, options = {})
42
+ authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
43
+ end
44
+
45
+ def credit(money, credit_card_or_vault_id, options = {})
46
+ create_transaction(:credit, money, credit_card_or_vault_id, options)
47
+ end
48
+
49
+ def refund(*args)
50
+ # legacy signature: #refund(transaction_id, options = {})
51
+ # new signature: #refund(money, transaction_id, options = {})
52
+ money, transaction_id, options = extract_refund_args(args)
53
+ money = amount(money).to_s if money
54
+
55
+ commit do
56
+ result = Braintree::Transaction.refund(transaction_id, money)
57
+ Response.new(result.success?, message_from_result(result),
58
+ {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
59
+ {:authorization => (result.transaction.id if result.success?)}
60
+ )
61
+ end
62
+ end
63
+
64
+ def void(authorization, options = {})
65
+ commit do
66
+ result = Braintree::Transaction.void(authorization)
67
+ Response.new(result.success?, message_from_result(result),
68
+ {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
69
+ {:authorization => (result.transaction.id if result.success?)}
70
+ )
71
+ end
72
+ end
73
+
74
+ def store(creditcard, options = {})
75
+ commit do
76
+ result = Braintree::Customer.create(
77
+ :first_name => creditcard.first_name,
78
+ :last_name => creditcard.last_name,
79
+ :email => options[:email],
80
+ :credit_card => {
81
+ :number => creditcard.number,
82
+ :cvv => creditcard.verification_value,
83
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
84
+ :expiration_year => creditcard.year.to_s
85
+ }
86
+ )
87
+ Response.new(result.success?, message_from_result(result),
88
+ {
89
+ :braintree_customer => (customer_hash(result.customer) if result.success?),
90
+ :customer_vault_id => (result.customer.id if result.success?)
91
+ }
92
+ )
93
+ end
94
+ end
95
+
96
+ def update(vault_id, creditcard, options = {})
97
+ braintree_credit_card = nil
98
+ customer_update_result = commit do
99
+ braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
100
+ return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
101
+ result = Braintree::Customer.update(vault_id,
102
+ :first_name => creditcard.first_name,
103
+ :last_name => creditcard.last_name,
104
+ :email => options[:email]
105
+ )
106
+ Response.new(result.success?, message_from_result(result),
107
+ :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?)
108
+ )
109
+ end
110
+ return customer_update_result unless customer_update_result.success?
111
+ credit_card_update_result = commit do
112
+ result = Braintree::CreditCard.update(braintree_credit_card.token,
113
+ :number => creditcard.number,
114
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
115
+ :expiration_year => creditcard.year.to_s
116
+ )
117
+ Response.new(result.success?, message_from_result(result),
118
+ :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?)
119
+ )
120
+ end
121
+ end
122
+
123
+ def unstore(customer_vault_id)
124
+ commit do
125
+ Braintree::Customer.delete(customer_vault_id)
126
+ Response.new(true, "OK")
127
+ end
128
+ end
129
+ alias_method :delete, :unstore
130
+
131
+ private
132
+
133
+ def map_address(address)
134
+ return {} if address.nil?
135
+ {
136
+ :street_address => address[:address1],
137
+ :extended_address => address[:address2],
138
+ :company => address[:company],
139
+ :locality => address[:city],
140
+ :region => address[:state],
141
+ :postal_code => address[:zip],
142
+ :country_name => address[:country]
143
+ }
144
+ end
145
+
146
+ def commit(&block)
147
+ yield
148
+ rescue Braintree::BraintreeError => ex
149
+ Response.new(false, ex.class.to_s)
150
+ end
151
+
152
+ def message_from_result(result)
153
+ if result.success?
154
+ "OK"
155
+ else
156
+ result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
157
+ end
158
+ end
159
+
160
+ def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
161
+ transaction_params = create_transaction_parameters(money, credit_card_or_vault_id, options)
162
+
163
+ commit do
164
+ result = Braintree::Transaction.send(transaction_type, transaction_params)
165
+ response_params, response_options, avs_result, cvv_result = {}, {}, {}, {}
166
+ if result.success?
167
+ response_params[:braintree_transaction] = transaction_hash(result.transaction)
168
+ response_params[:customer_vault_id] = result.transaction.customer_details.id
169
+ response_options[:authorization] = result.transaction.id
170
+ end
171
+ if result.transaction
172
+ response_options[:avs_result] = {
173
+ :code => nil, :message => nil,
174
+ :street_match => result.transaction.avs_street_address_response_code,
175
+ :postal_match => result.transaction.avs_postal_code_response_code
176
+ }
177
+ response_options[:cvv_result] = result.transaction.cvv_response_code
178
+ message = "#{result.transaction.processor_response_code} #{result.transaction.processor_response_text}"
179
+ else
180
+ message = message_from_result(result)
181
+ end
182
+ response = Response.new(result.success?, message, response_params, response_options)
183
+ response.cvv_result['message'] = ''
184
+ response
185
+ end
186
+ end
187
+
188
+ def extract_refund_args(args)
189
+ options = args.extract_options!
190
+
191
+ # money, transaction_id, options
192
+ if args.length == 1 # legacy signature
193
+ return nil, args[0], options
194
+ elsif args.length == 2
195
+ return args[0], args[1], options
196
+ else
197
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
198
+ end
199
+ end
200
+
201
+ def customer_hash(customer)
202
+ credit_cards = customer.credit_cards.map do |cc|
203
+ {
204
+ "bin" => cc.bin,
205
+ "expiration_date" => cc.expiration_date
206
+ }
207
+ end
208
+
209
+ {
210
+ "email" => customer.email,
211
+ "first_name" => customer.first_name,
212
+ "last_name" => customer.last_name,
213
+ "credit_cards" => credit_cards
214
+ }
215
+ end
216
+
217
+ def transaction_hash(transaction)
218
+ if transaction.vault_customer
219
+ vault_customer = {
220
+ }
221
+ vault_customer["credit_cards"] = transaction.vault_customer.credit_cards.map do |cc|
222
+ {
223
+ "bin" => cc.bin
224
+ }
225
+ end
226
+ else
227
+ vault_customer = nil
228
+ end
229
+
230
+ customer_details = {
231
+ "id" => transaction.customer_details.id,
232
+ "email" => transaction.customer_details.email
233
+ }
234
+
235
+ billing_details = {
236
+ "street_address" => transaction.billing_details.street_address,
237
+ "extended_address" => transaction.billing_details.extended_address,
238
+ "company" => transaction.billing_details.company,
239
+ "locality" => transaction.billing_details.locality,
240
+ "region" => transaction.billing_details.region,
241
+ "postal_code" => transaction.billing_details.postal_code,
242
+ "country_name" => transaction.billing_details.country_name,
243
+ }
244
+
245
+ shipping_details = {
246
+ "street_address" => transaction.shipping_details.street_address,
247
+ "extended_address" => transaction.shipping_details.extended_address,
248
+ "company" => transaction.shipping_details.company,
249
+ "locality" => transaction.shipping_details.locality,
250
+ "region" => transaction.shipping_details.region,
251
+ "postal_code" => transaction.shipping_details.postal_code,
252
+ "country_name" => transaction.shipping_details.country_name,
253
+ }
254
+
255
+ {
256
+ "order_id" => transaction.order_id,
257
+ "status" => transaction.status,
258
+ "customer_details" => customer_details,
259
+ "billing_details" => billing_details,
260
+ "shipping_details" => shipping_details,
261
+ "vault_customer" => vault_customer,
262
+ "merchant_account_id" => transaction.merchant_account_id
263
+ }
264
+ end
265
+
266
+ def create_transaction_parameters(money, credit_card_or_vault_id, options)
267
+ parameters = {
268
+ :amount => amount(money).to_s,
269
+ :order_id => options[:order_id],
270
+ :customer => {
271
+ :id => options[:store] == true ? "" : options[:store],
272
+ :email => options[:email]
273
+ },
274
+ :options => {
275
+ :store_in_vault => options[:store] ? true : false,
276
+ :submit_for_settlement => options[:submit_for_settlement]
277
+ }
278
+ }
279
+ if options.has_key?(:merchant_account_id)
280
+ parameters[:merchant_account_id] = options[:merchant_account_id]
281
+ end
282
+ if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
283
+ parameters[:customer_id] = credit_card_or_vault_id
284
+ else
285
+ parameters[:customer].merge!(
286
+ :first_name => credit_card_or_vault_id.first_name,
287
+ :last_name => credit_card_or_vault_id.last_name
288
+ )
289
+ parameters[:credit_card] = {
290
+ :number => credit_card_or_vault_id.number,
291
+ :cvv => credit_card_or_vault_id.verification_value,
292
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
293
+ :expiration_year => credit_card_or_vault_id.year.to_s
294
+ }
295
+ end
296
+ parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
297
+ parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
298
+ parameters
299
+ end
300
+ end
301
+ end
302
+ end
303
+