activemerchant-kiddy 1.15.0.kiddy

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/CHANGELOG +688 -0
  2. data/CONTRIBUTORS +233 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +164 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant/billing/avs_result.rb +98 -0
  7. data/lib/active_merchant/billing/base.rb +57 -0
  8. data/lib/active_merchant/billing/check.rb +68 -0
  9. data/lib/active_merchant/billing/credit_card.rb +172 -0
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  11. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  12. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  13. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  14. data/lib/active_merchant/billing/gateway.rb +170 -0
  15. data/lib/active_merchant/billing/gateways/authorize_net.rb +671 -0
  16. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
  17. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
  18. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
  19. data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
  20. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  21. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  22. data/lib/active_merchant/billing/gateways/bogus.rb +132 -0
  23. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
  26. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  28. data/lib/active_merchant/billing/gateways/cyber_source.rb +410 -0
  29. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  30. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  31. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  32. data/lib/active_merchant/billing/gateways/epay.rb +268 -0
  33. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  34. data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
  35. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  36. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  37. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  38. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  39. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  40. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  41. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  42. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  43. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  44. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  45. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  46. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  47. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  48. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
  49. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  50. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  51. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  52. data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
  53. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  54. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  55. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  56. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  57. data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
  58. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  59. data/lib/active_merchant/billing/gateways/orbital.rb +317 -0
  60. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  61. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  62. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  63. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  64. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  65. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  66. data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
  67. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  68. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  69. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  70. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  71. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
  72. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  73. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  74. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  75. data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
  76. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  77. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  78. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  79. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  80. data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
  81. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  82. data/lib/active_merchant/billing/gateways/quickpay.rb +218 -0
  83. data/lib/active_merchant/billing/gateways/realex.rb +311 -0
  84. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  85. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  86. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  87. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  88. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  89. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  90. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  91. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  92. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
  93. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  94. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  95. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  96. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  97. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  98. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  99. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  100. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  101. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  102. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  103. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  104. data/lib/active_merchant/billing/gateways.rb +18 -0
  105. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  106. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  107. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  108. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  109. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  110. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  111. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  112. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  113. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  114. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  115. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  116. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  117. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  118. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  119. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  120. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  121. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  122. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  123. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  124. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  125. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  126. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  127. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  128. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  129. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  130. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  131. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  132. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  133. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +48 -0
  134. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  135. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  136. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  137. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  138. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  139. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  140. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  141. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  142. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  143. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  144. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  145. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  146. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  147. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  148. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  149. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  150. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  151. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  152. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  153. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  154. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  155. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  156. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  157. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  158. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  159. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  160. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +88 -0
  161. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  162. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  163. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  164. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  165. data/lib/active_merchant/billing/integrations/world_pay.rb +38 -0
  166. data/lib/active_merchant/billing/integrations.rb +17 -0
  167. data/lib/active_merchant/billing/response.rb +32 -0
  168. data/lib/active_merchant/billing.rb +9 -0
  169. data/lib/active_merchant/common/connection.rb +177 -0
  170. data/lib/active_merchant/common/country.rb +328 -0
  171. data/lib/active_merchant/common/error.rb +26 -0
  172. data/lib/active_merchant/common/post_data.rb +24 -0
  173. data/lib/active_merchant/common/posts_data.rb +63 -0
  174. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  175. data/lib/active_merchant/common/utils.rb +22 -0
  176. data/lib/active_merchant/common/validateable.rb +81 -0
  177. data/lib/active_merchant/common.rb +14 -0
  178. data/lib/active_merchant/version.rb +3 -0
  179. data/lib/active_merchant.rb +50 -0
  180. data/lib/activemerchant.rb +1 -0
  181. data/lib/certs/cacert.pem +7815 -0
  182. data/lib/support/gateway_support.rb +58 -0
  183. data/lib/support/outbound_hosts.rb +25 -0
  184. metadata +273 -0
@@ -0,0 +1,139 @@
1
+ require File.dirname(__FILE__) + '/beanstream/beanstream_core'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # This class implements the Canadian {Beanstream}[http://www.beanstream.com] payment gateway.
6
+ # It is also named TD Canada Trust Online Mart payment gateway.
7
+ # To learn more about the specification of Beanstream gateway, please read the OM_Direct_Interface_API.pdf,
8
+ # which you can get from your Beanstream account or get from me by email.
9
+ #
10
+ # == Supported transaction types by Beanstream:
11
+ # * +P+ - Purchase
12
+ # * +PA+ - Pre Authorization
13
+ # * +PAC+ - Pre Authorization Completion
14
+ #
15
+ # == Secure Payment Profiles:
16
+ # BeanStream supports payment profiles (vaults). This allows you to store cc information with BeanStream and process subsequent transactions with a customer id.
17
+ # Secure Payment Profiles must be enabled on your account (must be done over the phone).
18
+ # Your API Access Passcode must be set in Administration => account settings => order settings.
19
+ # To learn more about storing credit cards with the Beanstream gateway, please read the BEAN_Payment_Profiles.pdf (I had to phone BeanStream to request it.)
20
+ #
21
+ # == Notes
22
+ # * Recurring billing is not yet implemented.
23
+ # * Adding of order products information is not implemented.
24
+ # * Ensure that country and province data is provided as a code such as "CA", "US", "QC".
25
+ # * login is the Beanstream merchant ID, username and password should be enabled in your Beanstream account and passed in using the <tt>:user</tt> and <tt>:password</tt> options.
26
+ # * Test your app with your true merchant id and test credit card information provided in the api pdf document.
27
+ # * Beanstream does not allow Payment Profiles to be deleted with their API. The accounts are 'closed', but have to be deleted manually.
28
+ #
29
+ # Example authorization (Beanstream PA transaction type):
30
+ #
31
+ # twenty = 2000
32
+ # gateway = BeanstreamGateway.new(
33
+ # :login => '100200000',
34
+ # :user => 'xiaobozz',
35
+ # :password => 'password'
36
+ # )
37
+ #
38
+ # credit_card = CreditCard.new(
39
+ # :number => '4030000010001234',
40
+ # :month => 8,
41
+ # :year => 2011,
42
+ # :first_name => 'xiaobo',
43
+ # :last_name => 'zzz',
44
+ # :verification_value => 137
45
+ # )
46
+ # response = gateway.authorize(twenty, credit_card,
47
+ # :order_id => '1234',
48
+ # :billing_address => {
49
+ # :name => 'xiaobo zzz',
50
+ # :phone => '555-555-5555',
51
+ # :address1 => '1234 Levesque St.',
52
+ # :address2 => 'Apt B',
53
+ # :city => 'Montreal',
54
+ # :state => 'QC',
55
+ # :country => 'CA',
56
+ # :zip => 'H2C1X8'
57
+ # },
58
+ # :email => 'xiaobozzz@example.com',
59
+ # :subtotal => 800,
60
+ # :shipping => 100,
61
+ # :tax1 => 100,
62
+ # :tax2 => 100,
63
+ # :custom => 'reference one'
64
+ # )
65
+ class BeanstreamGateway < Gateway
66
+ include BeanstreamCore
67
+
68
+ def authorize(money, source, options = {})
69
+ post = {}
70
+ add_amount(post, money)
71
+ add_invoice(post, options)
72
+ add_source(post, source)
73
+ add_address(post, options)
74
+ add_transaction_type(post, :authorization)
75
+ commit(post)
76
+ end
77
+
78
+ def purchase(money, source, options = {})
79
+ post = {}
80
+ add_amount(post, money)
81
+ add_invoice(post, options)
82
+ add_source(post, source)
83
+ add_address(post, options)
84
+ add_transaction_type(post, purchase_action(source))
85
+ commit(post)
86
+ end
87
+
88
+ def void(authorization, options = {})
89
+ reference, amount, type = split_auth(authorization)
90
+
91
+ post = {}
92
+ add_reference(post, reference)
93
+ add_original_amount(post, amount)
94
+ add_transaction_type(post, void_action(type))
95
+ commit(post)
96
+ end
97
+
98
+ def interac
99
+ @interac ||= BeanstreamInteracGateway.new(@options)
100
+ end
101
+
102
+ # To match the other stored-value gateways, like TrustCommerce,
103
+ # store and unstore need to be defined
104
+ def store(credit_card, options = {})
105
+ post = {}
106
+ add_address(post, options)
107
+ add_credit_card(post, credit_card)
108
+ add_secure_profile_variables(post,options)
109
+ commit(post, true)
110
+ end
111
+
112
+ #can't actually delete a secure profile with the supplicaed API. This function sets the status of the profile to closed (C).
113
+ #Closed profiles will have to removed manually.
114
+ def delete(vault_id)
115
+ update(vault_id, false, {:status => "C"})
116
+ end
117
+
118
+ alias_method :unstore, :delete
119
+
120
+ # Update the values (such as CC expiration) stored at
121
+ # the gateway. The CC number must be supplied in the
122
+ # CreditCard object.
123
+ def update(vault_id, credit_card, options = {})
124
+ post = {}
125
+ add_address(post, options)
126
+ add_credit_card(post, credit_card)
127
+ options.merge!({:vault_id => vault_id, :operation => secure_profile_action(:modify)})
128
+ add_secure_profile_variables(post,options)
129
+ commit(post, true)
130
+ end
131
+
132
+ private
133
+ def build_response(*args)
134
+ Response.new(*args)
135
+ end
136
+ end
137
+ end
138
+ end
139
+
@@ -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,132 @@
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, creditcard, options = {})
22
+ money = amount(money)
23
+ case creditcard.number
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, creditcard, options = {})
34
+ money = amount(money)
35
+ case creditcard.number
36
+ when '1'
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, creditcard, options = {})
46
+ money = amount(money)
47
+ case creditcard.number
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, creditcard, options = {})
58
+ if creditcard.is_a?(String)
59
+ deprecated CREDIT_DEPRECATION_MESSAGE
60
+ return refund(money, creditcard, options)
61
+ end
62
+
63
+ money = amount(money)
64
+ case creditcard.number
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, ident, options = {})
75
+ money = amount(money)
76
+ case ident
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, ident, options = {})
87
+ money = amount(money)
88
+ case ident
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(ident, options = {})
99
+ case ident
100
+ when '1'
101
+ raise Error, VOID_ERROR_MESSAGE
102
+ when '2'
103
+ Response.new(false, FAILURE_MESSAGE, {:authorization => ident, :error => FAILURE_MESSAGE }, :test => true)
104
+ else
105
+ Response.new(true, SUCCESS_MESSAGE, {:authorization => ident}, :test => true)
106
+ end
107
+ end
108
+
109
+ def store(creditcard, options = {})
110
+ case creditcard.number
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(identification, options = {})
121
+ case identification
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
+ end
131
+ end
132
+ 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]
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,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,293 @@
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
+ parameters = {
162
+ :amount => amount(money).to_s,
163
+ :order_id => options[:order_id],
164
+ :customer => {
165
+ :id => options[:store] == true ? "" : options[:store],
166
+ :email => options[:email]
167
+ },
168
+ :options => {
169
+ :store_in_vault => options[:store] ? true : false,
170
+ :submit_for_settlement => options[:submit_for_settlement]
171
+ }
172
+ }
173
+ if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
174
+ parameters[:customer_id] = credit_card_or_vault_id
175
+ else
176
+ parameters[:customer].merge!(
177
+ :first_name => credit_card_or_vault_id.first_name,
178
+ :last_name => credit_card_or_vault_id.last_name
179
+ )
180
+ parameters[:credit_card] = {
181
+ :number => credit_card_or_vault_id.number,
182
+ :cvv => credit_card_or_vault_id.verification_value,
183
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
184
+ :expiration_year => credit_card_or_vault_id.year.to_s
185
+ }
186
+ end
187
+ parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
188
+ parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
189
+ commit do
190
+ result = Braintree::Transaction.send(transaction_type, parameters)
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
+ message = result.transaction.processor_response_code + " " + result.transaction.processor_response_text
205
+ else
206
+ message = message_from_result(result)
207
+ end
208
+ response = Response.new(result.success?, message, response_params, response_options)
209
+ response.cvv_result['message'] = ''
210
+ response
211
+ end
212
+ end
213
+
214
+ def extract_refund_args(args)
215
+ options = args.extract_options!
216
+
217
+ # money, transaction_id, options
218
+ if args.length == 1 # legacy signature
219
+ return nil, args[0], options
220
+ elsif args.length == 2
221
+ return args[0], args[1], options
222
+ else
223
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
224
+ end
225
+ end
226
+
227
+ def customer_hash(customer)
228
+ credit_cards = customer.credit_cards.map do |cc|
229
+ {
230
+ "bin" => cc.bin,
231
+ "expiration_date" => cc.expiration_date
232
+ }
233
+ end
234
+
235
+ {
236
+ "email" => customer.email,
237
+ "first_name" => customer.first_name,
238
+ "last_name" => customer.last_name,
239
+ "credit_cards" => credit_cards
240
+ }
241
+ end
242
+
243
+ def transaction_hash(transaction)
244
+ if transaction.vault_customer
245
+ vault_customer = {
246
+ }
247
+ vault_customer["credit_cards"] = transaction.vault_customer.credit_cards.map do |cc|
248
+ {
249
+ "bin" => cc.bin
250
+ }
251
+ end
252
+ else
253
+ vault_customer = nil
254
+ end
255
+
256
+ customer_details = {
257
+ "id" => transaction.customer_details.id,
258
+ "email" => transaction.customer_details.email
259
+ }
260
+
261
+ billing_details = {
262
+ "street_address" => transaction.billing_details.street_address,
263
+ "extended_address" => transaction.billing_details.extended_address,
264
+ "company" => transaction.billing_details.company,
265
+ "locality" => transaction.billing_details.locality,
266
+ "region" => transaction.billing_details.region,
267
+ "postal_code" => transaction.billing_details.postal_code,
268
+ "country_name" => transaction.billing_details.country_name,
269
+ }
270
+
271
+ shipping_details = {
272
+ "street_address" => transaction.shipping_details.street_address,
273
+ "extended_address" => transaction.shipping_details.extended_address,
274
+ "company" => transaction.shipping_details.company,
275
+ "locality" => transaction.shipping_details.locality,
276
+ "region" => transaction.shipping_details.region,
277
+ "postal_code" => transaction.shipping_details.postal_code,
278
+ "country_name" => transaction.shipping_details.country_name,
279
+ }
280
+
281
+ {
282
+ "order_id" => transaction.order_id,
283
+ "status" => transaction.status,
284
+ "customer_details" => customer_details,
285
+ "billing_details" => billing_details,
286
+ "shipping_details" => shipping_details,
287
+ "vault_customer" => vault_customer
288
+ }
289
+ end
290
+ end
291
+ end
292
+ end
293
+
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/smart_ps.rb'
2
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ class BraintreeOrangeGateway < SmartPs
7
+ include BraintreeCommon
8
+
9
+ self.display_name = 'Braintree (Orange Platform)'
10
+
11
+ def api_url
12
+ 'https://secure.braintreepaymentgateway.com/api/transact.php'
13
+ end
14
+ end
15
+ end
16
+ end
17
+