vibedeck-activemerchant 1.18.2

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 +742 -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 +857 -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 +304 -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 +223 -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_digital_goods.rb +43 -0
  80. data/lib/active_merchant/billing/gateways/paypal_express.rb +221 -0
  81. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -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 +315 -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 +340 -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,304 @@
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 = test? ? :sandbox : :production
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
+ result = Braintree::Customer.create(
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
+ Response.new(result.success?, message_from_result(result),
89
+ {
90
+ :braintree_customer => (customer_hash(result.customer) if result.success?),
91
+ :customer_vault_id => (result.customer.id if result.success?)
92
+ }
93
+ )
94
+ end
95
+ end
96
+
97
+ def update(vault_id, creditcard, options = {})
98
+ braintree_credit_card = nil
99
+ customer_update_result = commit do
100
+ braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
101
+ return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
102
+ result = Braintree::Customer.update(vault_id,
103
+ :first_name => creditcard.first_name,
104
+ :last_name => creditcard.last_name,
105
+ :email => options[:email]
106
+ )
107
+ Response.new(result.success?, message_from_result(result),
108
+ :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?)
109
+ )
110
+ end
111
+ return customer_update_result unless customer_update_result.success?
112
+ credit_card_update_result = commit do
113
+ result = Braintree::CreditCard.update(braintree_credit_card.token,
114
+ :number => creditcard.number,
115
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
116
+ :expiration_year => creditcard.year.to_s
117
+ )
118
+ Response.new(result.success?, message_from_result(result),
119
+ :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?)
120
+ )
121
+ end
122
+ end
123
+
124
+ def unstore(customer_vault_id)
125
+ commit do
126
+ Braintree::Customer.delete(customer_vault_id)
127
+ Response.new(true, "OK")
128
+ end
129
+ end
130
+ alias_method :delete, :unstore
131
+
132
+ private
133
+
134
+ def map_address(address)
135
+ return {} if address.nil?
136
+ {
137
+ :street_address => address[:address1],
138
+ :extended_address => address[:address2],
139
+ :company => address[:company],
140
+ :locality => address[:city],
141
+ :region => address[:state],
142
+ :postal_code => address[:zip],
143
+ :country_name => address[:country]
144
+ }
145
+ end
146
+
147
+ def commit(&block)
148
+ yield
149
+ rescue Braintree::BraintreeError => ex
150
+ Response.new(false, ex.class.to_s)
151
+ end
152
+
153
+ def message_from_result(result)
154
+ if result.success?
155
+ "OK"
156
+ else
157
+ result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
158
+ end
159
+ end
160
+
161
+ def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
162
+ transaction_params = create_transaction_parameters(money, credit_card_or_vault_id, options)
163
+
164
+ commit do
165
+ result = Braintree::Transaction.send(transaction_type, transaction_params)
166
+ response_params, response_options, avs_result, cvv_result = {}, {}, {}, {}
167
+ if result.success?
168
+ response_params[:braintree_transaction] = transaction_hash(result.transaction)
169
+ response_params[:customer_vault_id] = result.transaction.customer_details.id
170
+ response_options[:authorization] = result.transaction.id
171
+ end
172
+ if result.transaction
173
+ response_options[:avs_result] = {
174
+ :code => nil, :message => nil,
175
+ :street_match => result.transaction.avs_street_address_response_code,
176
+ :postal_match => result.transaction.avs_postal_code_response_code
177
+ }
178
+ response_options[:cvv_result] = result.transaction.cvv_response_code
179
+ message = "#{result.transaction.processor_response_code} #{result.transaction.processor_response_text}"
180
+ else
181
+ message = message_from_result(result)
182
+ end
183
+ response = Response.new(result.success?, message, response_params, response_options)
184
+ response.cvv_result['message'] = ''
185
+ response
186
+ end
187
+ end
188
+
189
+ def extract_refund_args(args)
190
+ options = args.extract_options!
191
+
192
+ # money, transaction_id, options
193
+ if args.length == 1 # legacy signature
194
+ return nil, args[0], options
195
+ elsif args.length == 2
196
+ return args[0], args[1], options
197
+ else
198
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
199
+ end
200
+ end
201
+
202
+ def customer_hash(customer)
203
+ credit_cards = customer.credit_cards.map do |cc|
204
+ {
205
+ "bin" => cc.bin,
206
+ "expiration_date" => cc.expiration_date
207
+ }
208
+ end
209
+
210
+ {
211
+ "email" => customer.email,
212
+ "first_name" => customer.first_name,
213
+ "last_name" => customer.last_name,
214
+ "credit_cards" => credit_cards
215
+ }
216
+ end
217
+
218
+ def transaction_hash(transaction)
219
+ if transaction.vault_customer
220
+ vault_customer = {
221
+ }
222
+ vault_customer["credit_cards"] = transaction.vault_customer.credit_cards.map do |cc|
223
+ {
224
+ "bin" => cc.bin
225
+ }
226
+ end
227
+ else
228
+ vault_customer = nil
229
+ end
230
+
231
+ customer_details = {
232
+ "id" => transaction.customer_details.id,
233
+ "email" => transaction.customer_details.email
234
+ }
235
+
236
+ billing_details = {
237
+ "street_address" => transaction.billing_details.street_address,
238
+ "extended_address" => transaction.billing_details.extended_address,
239
+ "company" => transaction.billing_details.company,
240
+ "locality" => transaction.billing_details.locality,
241
+ "region" => transaction.billing_details.region,
242
+ "postal_code" => transaction.billing_details.postal_code,
243
+ "country_name" => transaction.billing_details.country_name,
244
+ }
245
+
246
+ shipping_details = {
247
+ "street_address" => transaction.shipping_details.street_address,
248
+ "extended_address" => transaction.shipping_details.extended_address,
249
+ "company" => transaction.shipping_details.company,
250
+ "locality" => transaction.shipping_details.locality,
251
+ "region" => transaction.shipping_details.region,
252
+ "postal_code" => transaction.shipping_details.postal_code,
253
+ "country_name" => transaction.shipping_details.country_name,
254
+ }
255
+
256
+ {
257
+ "order_id" => transaction.order_id,
258
+ "status" => transaction.status,
259
+ "customer_details" => customer_details,
260
+ "billing_details" => billing_details,
261
+ "shipping_details" => shipping_details,
262
+ "vault_customer" => vault_customer,
263
+ "merchant_account_id" => transaction.merchant_account_id
264
+ }
265
+ end
266
+
267
+ def create_transaction_parameters(money, credit_card_or_vault_id, options)
268
+ parameters = {
269
+ :amount => amount(money).to_s,
270
+ :order_id => options[:order_id],
271
+ :customer => {
272
+ :id => options[:store] == true ? "" : options[:store],
273
+ :email => options[:email]
274
+ },
275
+ :options => {
276
+ :store_in_vault => options[:store] ? true : false,
277
+ :submit_for_settlement => options[:submit_for_settlement]
278
+ }
279
+ }
280
+ if merchant_account_id = (options[:merchant_account_id] || @merchant_account_id)
281
+ parameters[:merchant_account_id] = merchant_account_id
282
+ end
283
+ if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
284
+ parameters[:customer_id] = credit_card_or_vault_id
285
+ else
286
+ parameters[:customer].merge!(
287
+ :first_name => credit_card_or_vault_id.first_name,
288
+ :last_name => credit_card_or_vault_id.last_name
289
+ )
290
+ parameters[:credit_card] = {
291
+ :number => credit_card_or_vault_id.number,
292
+ :cvv => credit_card_or_vault_id.verification_value,
293
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
294
+ :expiration_year => credit_card_or_vault_id.year.to_s
295
+ }
296
+ end
297
+ parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
298
+ parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
299
+ parameters
300
+ end
301
+ end
302
+ end
303
+ end
304
+