maedana-activemerchant 1.9.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/CHANGELOG +571 -0
  2. data/CONTRIBUTORS +170 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +150 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +49 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +161 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +169 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  26. data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
  27. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  28. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  29. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  30. data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
  31. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  32. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  33. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  34. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  35. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  36. data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
  37. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  38. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  39. data/lib/active_merchant/billing/gateways/iridium.rb +253 -0
  40. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  41. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  42. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  43. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  44. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  45. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  46. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  47. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  48. data/lib/active_merchant/billing/gateways/netaxept.rb +234 -0
  49. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  50. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  51. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  52. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  53. data/lib/active_merchant/billing/gateways/paybox_direct.rb +203 -0
  54. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  55. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  56. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  57. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  58. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  59. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  60. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  61. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  62. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  63. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  64. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  65. data/lib/active_merchant/billing/gateways/paypal/paypal_payment_details_response.rb +70 -0
  66. data/lib/active_merchant/billing/gateways/paypal_adaptive_payments.rb +298 -0
  67. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  68. data/lib/active_merchant/billing/gateways/paypal_express.rb +145 -0
  69. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  70. data/lib/active_merchant/billing/gateways/paypal_express_recurring.rb +310 -0
  71. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  72. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  73. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  74. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  75. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  76. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  77. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  78. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  79. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  80. data/lib/active_merchant/billing/gateways/sage_pay.rb +315 -0
  81. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  82. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  83. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  84. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  85. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  86. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  87. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  88. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  89. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  90. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  91. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  92. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  93. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  94. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  95. data/lib/active_merchant/billing/integrations.rb +17 -0
  96. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  97. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  98. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  99. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  100. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  101. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  102. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  103. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  104. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  105. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  106. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +188 -0
  107. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  108. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  109. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  110. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  111. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  112. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  113. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  114. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  115. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  116. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  117. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  118. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  119. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  120. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  121. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  122. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  123. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  124. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  125. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  126. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  127. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  128. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  129. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  130. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  131. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  132. data/lib/active_merchant/billing/integrations/return.rb +37 -0
  133. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  134. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  135. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +109 -0
  136. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +204 -0
  137. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +27 -0
  138. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  139. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  140. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  141. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  142. data/lib/active_merchant/billing/response.rb +32 -0
  143. data/lib/active_merchant/common.rb +14 -0
  144. data/lib/active_merchant/common/connection.rb +172 -0
  145. data/lib/active_merchant/common/country.rb +328 -0
  146. data/lib/active_merchant/common/error.rb +26 -0
  147. data/lib/active_merchant/common/post_data.rb +24 -0
  148. data/lib/active_merchant/common/posts_data.rb +47 -0
  149. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  150. data/lib/active_merchant/common/utils.rb +18 -0
  151. data/lib/active_merchant/common/validateable.rb +76 -0
  152. data/lib/active_merchant/version.rb +3 -0
  153. data/lib/certs/cacert.pem +7815 -0
  154. data/lib/maedana-activemerchant.rb +1 -0
  155. data/lib/support/gateway_support.rb +58 -0
  156. data/lib/support/outbound_hosts.rb +25 -0
  157. metadata +270 -0
@@ -0,0 +1,70 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PaypalPaymentDetailsResponse < Response
4
+ def action_type
5
+ @params['action_type']
6
+ end
7
+
8
+ def cancel_url
9
+ @params['cancel_url']
10
+ end
11
+
12
+ def currency_code
13
+ @params['currency_code']
14
+ end
15
+
16
+ def fees_payer
17
+ @params['fees_payer']
18
+ end
19
+
20
+ def ipn_notification_url
21
+ @params['ipn_notification_url']
22
+ end
23
+
24
+ def memo
25
+ @params['memo']
26
+ end
27
+
28
+ def payment_list
29
+ @params['payment_list']
30
+ end
31
+
32
+ def return_url
33
+ @params['return_url']
34
+ end
35
+
36
+ def ipn_notification_url
37
+ @params['ipn_notifcation_url']
38
+ end
39
+
40
+ def sender_email
41
+ @params['sender_email']
42
+ end
43
+
44
+ def status
45
+ @params['status']
46
+ end
47
+
48
+ def tracking_id
49
+ @params['tracking_id']
50
+ end
51
+
52
+ def fees_payer
53
+ @params['fees_payer']
54
+ end
55
+
56
+ def reverse_all_parallel_payments_on_error
57
+ @params['reverse_all_parallel_payments_on_error'] == 'true'
58
+ end
59
+
60
+ def log_default_shipping_address
61
+ @params['log_default_shipping_address'] == 'true'
62
+ end
63
+
64
+ def preapproval_key
65
+ @params['preapproval_key']
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,298 @@
1
+ require File.dirname(__FILE__) + '/paypal/paypal_payment_details_response'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class PaypalAdaptivePaymentGateway < Gateway
6
+ include PaypalExpressCommon
7
+
8
+ TEST_URL = 'https://svcs.sandbox.paypal.com/AdaptivePayments'
9
+ LIVE_URL = 'https://svcs.paypal.com/AdaptivePayments'
10
+
11
+ self.test_redirect_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd='
12
+ self.live_redirect_url = 'https://www.paypal.com/cgi-bin/webscr?cmd='
13
+
14
+
15
+ API_VERSION = '1.1.0'
16
+
17
+ SUCCESS_CODES = [ 'Success', 'SuccessWithWarning' ]
18
+
19
+ PAYMENT_PERIODS = ['DAILY', 'WEEKLY', 'BIWEEKLY', 'SEMIMONTHLY', 'MONTHLY', 'ANNUALLY']
20
+
21
+ FEES_PAYER_OPTIONS = ['SENDER', 'PRIMARYRECEIVER', 'EACHRECEIVER', 'SECONDARYONLY']
22
+
23
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
24
+ self.supported_countries = ['US']
25
+
26
+ # The card types supported by the payment gateway
27
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
28
+
29
+ # The homepage URL of the gateway
30
+ self.homepage_url = 'http://x.com/'
31
+
32
+ # The name of the gateway
33
+ self.display_name = 'Paypal Adaptive Payments'
34
+
35
+ self.default_currency = 'USD'
36
+
37
+ def initialize(options = {})
38
+ requires!(options, :login, :password)
39
+ @options = options
40
+ super
41
+ end
42
+
43
+ # Pay money to one or more recievers
44
+ #
45
+ # gateway.pay 1000, 'bob@example.com',
46
+ # :sender_email => "john@example.com", :return_url => "http://example.com/return", :cancel_url => "http://example.com/cancel"
47
+ #
48
+ # gateway.pay [1000, 'fred@example.com'],
49
+ # [2450, 'wilma@example.com', :primary => true],
50
+ # [2000, 'barney@example.com'],
51
+ # :sender_email => "john@example.com", :return_url => "http://example.com/return", :cancel_url => "http://example.com/cancel"
52
+ #
53
+ def pay(*args)
54
+ commit('Pay', build_pay_request(*args))
55
+ end
56
+
57
+ def payment_details(token, options = {})
58
+ commit('PaymentDetails', build_payment_details_request(token, options))
59
+ end
60
+
61
+ def preapproval(options)
62
+ requires!(options, :return_url, :cancel_url, :ending_date)
63
+ commit('Preapproval', build_preapproval_request(options))
64
+ end
65
+
66
+ def preapproval_details(token, options = {})
67
+ commit('PreapprovalDetails', build_preapproval_details_request(token, options))
68
+ end
69
+
70
+ def refund(*args)
71
+ commit('Refund', build_refund_request(*args))
72
+ end
73
+
74
+ def redirect_url_for(token, options = {})
75
+ if token =~ /AP\-/
76
+ "#{redirect_url}_ap-payment&payKey=#{token}"
77
+ elsif token =~ /PA\-/
78
+ "#{redirect_url}_ap-preapproval&preapprovalkey=#{token}"
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def endpoint_url
85
+ test? ? TEST_URL : LIVE_URL
86
+ end
87
+
88
+ def build_pay_request(*args)
89
+ default_options = args.last.is_a?(Hash) ? args.pop : {}
90
+ receivers = args.first.is_a?(Array) ? args : [args]
91
+
92
+ requires!(default_options, :return_url, :cancel_url)
93
+
94
+ currency = options[:currency] || currency(receivers.first[0])
95
+
96
+ xml = Builder::XmlMarkup.new
97
+ add_client_details(xml, default_options)
98
+ xml.tag! 'actionType', 'PAY'
99
+ xml.tag! 'feesPayer', fees_payer_option(default_options[:fees_payer]) unless default_options[:fees_payer].blank?
100
+ xml.tag! 'cancelUrl', default_options[:cancel_url]
101
+ xml.tag! 'currencyCode', currency
102
+ xml.tag! 'ipnNotificationUrl', default_options[:ipn_notification_url] unless default_options[:ipn_notification_url].blank?
103
+ xml.tag! 'logDefaultShippingAddress', true if default_options[:log_default_shipping_address]
104
+ xml.tag! 'memo', default_options[:memo] unless default_options[:memo].blank?
105
+ xml.tag! 'pin', default_options[:pin] unless default_options[:pin].blank?
106
+ xml.tag! 'preapprovalKey', default_options[:preapproval_key] unless default_options[:preapproval_key].blank?
107
+ xml.tag! 'receiverList' do
108
+ receivers.each do |money, receiver, options|
109
+ options ||= default_options
110
+ xml.tag! 'receiver' do
111
+ xml.tag! 'amount', amount(money)
112
+ xml.tag! 'email', receiver
113
+ xml.tag! 'primary', true if options[:primary]
114
+ end
115
+ end
116
+ end
117
+ xml.tag! 'reverseAllParallelPaymentsOnError', true if default_options[:reverse_all_parallel_payments_on_error]
118
+ xml.tag! 'senderEmail', default_options[:sender_email] unless default_options[:sender_email].blank?
119
+ xml.tag! 'returnUrl', default_options[:return_url]
120
+ xml.tag! 'trackingId', default_options[:tracking_id] unless default_options[:tracking_id].blank?
121
+ xml.target!
122
+ end
123
+
124
+ def build_payment_details_request(token, options)
125
+ xml = Builder::XmlMarkup.new
126
+ add_client_details(xml, options)
127
+ xml.tag! 'payKey', token unless token.blank?
128
+ xml.tag! 'transactionId', options[:transaction_id] unless options[:transaction_id].blank?
129
+ xml.tag! 'trackingId', options[:tracking_id] unless options[:tracking_id].blank?
130
+ xml.target!
131
+ end
132
+
133
+ def build_preapproval_request(options)
134
+ xml = Builder::XmlMarkup.new
135
+ add_client_details(xml, options)
136
+ xml.tag! 'cancelUrl', options[:cancel_url]
137
+ xml.tag! 'currencyCode', options[:currency] || self.default_currency
138
+ xml.tag! 'dateOfMonth', options[:date_of_month] unless options[:date_of_month].blank?
139
+ xml.tag! 'dayOfWeek', day_of_week(options[:date_of_week]) unless options[:date_of_week].blank?
140
+ xml.tag! 'endingDate', options[:ending_date]
141
+ xml.tag! 'maxAmountPerPayment', money(options[:max_amount_per_payment]) unless options[:max_amount_per_payment].blank?
142
+ xml.tag! 'maxNumberOfPayments', options[:max_number_of_payments] unless options[:max_number_of_payments].blank?
143
+ xml.tag! 'maxNumberOfPaymentsPerPeriod', options[:max_number_of_payments_per_period] unless options[:max_number_of_payments_per_period].blank?
144
+ xml.tag! 'paymentPeriod', payment_period(options[:payment_period]) unless options[:payment_period].blank?
145
+ xml.tag! 'senderEmail', options[:sender_email] unless options[:sender_email].blank?
146
+ xml.tag! 'returnUrl', options[:return_url]
147
+ xml.target!
148
+ end
149
+
150
+ def build_preapproval_details_request(token, options)
151
+ xml = Builder::XmlMarkup.new
152
+ add_client_details(xml, options)
153
+ xml.tag! 'preapprovalKey', token
154
+ xml.target!
155
+ end
156
+
157
+ def build_refund_request(*args)
158
+ default_options = args.last.is_a?(Hash) ? args.pop : {}
159
+ receivers = if args.first
160
+ args.first.is_a?(Array) ? args : [args]
161
+ else
162
+ []
163
+ end
164
+
165
+ currency = options[:currency] || (currency(receivers.first[0]) unless receivers.empty?) || self.default_currency
166
+
167
+ xml = Builder::XmlMarkup.new
168
+ add_client_details(xml, default_options)
169
+ xml.tag! 'currencyCode', currency
170
+ xml.tag! 'payKey', default_options[:pay_key] unless default_options[:pay_key].blank?
171
+ xml.tag! 'trackingId', default_options[:tracking_id] unless default_options[:tracking_id].blank?
172
+ xml.tag! 'transactionId', default_options[:transaction_id] unless default_options[:transaction_id].blank?
173
+ xml.tag! 'receivers' do
174
+ receivers.each do |money, receiver, options|
175
+ options ||= default_options
176
+ xml.tag! 'receiver' do
177
+ xml.tag! 'amount', amount(money)
178
+ xml.tag! 'email', receiver
179
+ xml.tag! 'primary', true if options[:primary]
180
+ end
181
+ end
182
+ end
183
+ xml.target!
184
+ end
185
+
186
+ def headers
187
+ {
188
+ "X-PAYPAL-REQUEST-DATA-FORMAT" => "XML",
189
+ "X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON",
190
+ "X-PAYPAL-SECURITY-USERID" => @options[:login],
191
+ "X-PAYPAL-SECURITY-PASSWORD" => @options[:password],
192
+ "X-PAYPAL-SECURITY-SIGNATURE" => @options[:signature],
193
+ "X-PAYPAL-SERVICE-VERSION" => API_VERSION,
194
+ "X-PAYPAL-APPLICATION-ID" => self.application_id
195
+ }
196
+ end
197
+
198
+ def day_of_week(d)
199
+ if d
200
+ if Date::DAYNAMES.include?(d.to_s.upcase)
201
+ d.to_s.upcase
202
+ elsif Date::DAYNAMES[d.to_i]
203
+ Date::DAYNAMES[d.to_i].upcase
204
+ end
205
+ end
206
+ end
207
+
208
+ def payment_period(p)
209
+ if p && PAYMENT_PERIODS.include?(p.to_s.upcase)
210
+ p.to_s.upcase
211
+ end
212
+ end
213
+
214
+ def fees_payer_option(o)
215
+ if o & FEES_PAYER_OPTIONS.include?(o.to_s.gsub('_', '').upcase)
216
+ o.to_s.gsub('_', '').upcase
217
+ end
218
+ end
219
+
220
+ def add_client_details(xml, options)
221
+ xml.clientDetails do
222
+ xml.ipAddress options[:remote_ip]
223
+ xml.deviceId options[:device_id] unless options[:device_id].blank?
224
+ xml.applicationId self.application_id
225
+ xml.partnerName options[:partner_name] unless options[:partner_name].blank?
226
+ end
227
+ end
228
+
229
+ def build_url(action)
230
+ "#{endpoint_url}/#{action}"
231
+ end
232
+
233
+ def successful?(response)
234
+ SUCCESS_CODES.include?(response[:ack])
235
+ end
236
+
237
+ def message_from(response)
238
+ response[:message] || response[:status] || response[:payment_exec_status] || response[:ack]
239
+ end
240
+
241
+ def authorization_from(response)
242
+ response[:pay_key] || response[:preapproval_key]
243
+ end
244
+
245
+ def build_response(action, success, message, response, options = {})
246
+ case action
247
+ when 'PaymentDetails'
248
+ PaypalPaymentDetailsResponse.new(success, message, response, options)
249
+ else
250
+ Response.new(success, message, response, options)
251
+ end
252
+ end
253
+
254
+ def build_request(action, body)
255
+ xml = Builder::XmlMarkup.new
256
+ xml.instruct!
257
+ xml.tag! "#{action}Request" do
258
+ xml.tag! 'requestEnvelope' do
259
+ xml.tag! 'detailLevel', 'ReturnAll'
260
+ end
261
+ xml << body
262
+ end
263
+ xml.target!
264
+ end
265
+
266
+ def parse(action, json)
267
+ result = ActiveSupport::JSON.decode(json)
268
+ response = {}
269
+ result.each do |k,v|
270
+ response[k.underscore.to_sym] = v if v.is_a?(String)
271
+ end
272
+ if result['responseEnvelope']
273
+ result['responseEnvelope'].each do |k,v|
274
+ response[k.underscore.to_sym] = v if v.is_a?(String)
275
+ end
276
+ end
277
+ if result['paymentInfoList']
278
+ response[:payment_list] = result['paymentInfoList']['paymentInfo']
279
+ end
280
+ if result['error']
281
+ response[:message] = result['error'].collect{|e| e['message'] }.uniq.join('. ')
282
+ response[:error_codes] = result['error'].collect{|e| e['errorId'] }.uniq.join(', ')
283
+ end
284
+ response
285
+ end
286
+
287
+ def commit(action, request)
288
+ response = parse(action, ssl_post(build_url(action), build_request(action,request), headers))
289
+ build_response(action, successful?(response), message_from(response), response,
290
+ :test => test?,
291
+ :authorization => authorization_from(response)
292
+ )
293
+ end
294
+
295
+ end
296
+ end
297
+ end
298
+
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/paypal'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # The PayPal gateway for PayPal Website Payments Pro Canada only supports Visa and MasterCard
6
+ class PaypalCaGateway < PaypalGateway
7
+ self.supported_cardtypes = [:visa, :master]
8
+ self.supported_countries = ['CA']
9
+ self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_wp-pro-overview-outside'
10
+ self.display_name = 'PayPal Website Payments Pro (CA)'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,145 @@
1
+ require File.dirname(__FILE__) + '/paypal/paypal_common_api'
2
+ require File.dirname(__FILE__) + '/paypal/paypal_express_response'
3
+ require File.dirname(__FILE__) + '/paypal_express_common'
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ class PaypalExpressGateway < Gateway
8
+ include PaypalCommonAPI
9
+ include PaypalExpressCommon
10
+
11
+ self.test_redirect_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='
12
+ self.supported_countries = ['US']
13
+ self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=xpt/merchant/ExpressCheckoutIntro-outside'
14
+ self.display_name = 'PayPal Express Checkout'
15
+
16
+ def setup_authorization(money, options = {})
17
+ requires!(options, :return_url, :cancel_return_url)
18
+
19
+ commit 'SetExpressCheckout', build_setup_request('Authorization', money, options)
20
+ end
21
+
22
+ def setup_purchase(money, options = {})
23
+ requires!(options, :return_url, :cancel_return_url)
24
+
25
+ commit 'SetExpressCheckout', build_setup_request('Sale', money, options)
26
+ end
27
+
28
+ def details_for(token)
29
+ commit 'GetExpressCheckoutDetails', build_get_details_request(token)
30
+ end
31
+
32
+ def authorize(money, options = {})
33
+ requires!(options, :token, :payer_id)
34
+
35
+ commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Authorization', money, options)
36
+ end
37
+
38
+ def purchase(money, options = {})
39
+ requires!(options, :token, :payer_id)
40
+
41
+ commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Sale', money, options)
42
+ end
43
+
44
+ private
45
+ def build_get_details_request(token)
46
+ xml = Builder::XmlMarkup.new :indent => 2
47
+ xml.tag! 'GetExpressCheckoutDetailsReq', 'xmlns' => PAYPAL_NAMESPACE do
48
+ xml.tag! 'GetExpressCheckoutDetailsRequest', 'xmlns:n2' => EBAY_NAMESPACE do
49
+ xml.tag! 'n2:Version', API_VERSION
50
+ xml.tag! 'Token', token
51
+ end
52
+ end
53
+
54
+ xml.target!
55
+ end
56
+
57
+ def build_sale_or_authorization_request(action, money, options)
58
+ currency_code = options[:currency] || currency(money)
59
+
60
+ xml = Builder::XmlMarkup.new :indent => 2
61
+ xml.tag! 'DoExpressCheckoutPaymentReq', 'xmlns' => PAYPAL_NAMESPACE do
62
+ xml.tag! 'DoExpressCheckoutPaymentRequest', 'xmlns:n2' => EBAY_NAMESPACE do
63
+ xml.tag! 'n2:Version', API_VERSION
64
+ xml.tag! 'n2:DoExpressCheckoutPaymentRequestDetails' do
65
+ xml.tag! 'n2:PaymentAction', action
66
+ xml.tag! 'n2:Token', options[:token]
67
+ xml.tag! 'n2:PayerID', options[:payer_id]
68
+ xml.tag! 'n2:PaymentDetails' do
69
+ xml.tag! 'n2:OrderTotal', localized_amount(money, currency_code), 'currencyID' => currency_code
70
+
71
+ # All of the values must be included together and add up to the order total
72
+ if [:subtotal, :shipping, :handling, :tax].all?{ |o| options.has_key?(o) }
73
+ xml.tag! 'n2:ItemTotal', localized_amount(options[:subtotal], currency_code), 'currencyID' => currency_code
74
+ xml.tag! 'n2:ShippingTotal', localized_amount(options[:shipping], currency_code),'currencyID' => currency_code
75
+ xml.tag! 'n2:HandlingTotal', localized_amount(options[:handling], currency_code),'currencyID' => currency_code
76
+ xml.tag! 'n2:TaxTotal', localized_amount(options[:tax], currency_code), 'currencyID' => currency_code
77
+ end
78
+
79
+ xml.tag! 'n2:NotifyURL', options[:notify_url]
80
+ xml.tag! 'n2:ButtonSource', application_id.to_s.slice(0,32) unless application_id.blank?
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ xml.target!
87
+ end
88
+
89
+ def build_setup_request(action, money, options)
90
+ currency_code = options[:currency] || currency(money)
91
+
92
+ xml = Builder::XmlMarkup.new :indent => 2
93
+ xml.tag! 'SetExpressCheckoutReq', 'xmlns' => PAYPAL_NAMESPACE do
94
+ xml.tag! 'SetExpressCheckoutRequest', 'xmlns:n2' => EBAY_NAMESPACE do
95
+ xml.tag! 'n2:Version', API_VERSION
96
+ xml.tag! 'n2:SetExpressCheckoutRequestDetails' do
97
+ xml.tag! 'n2:PaymentAction', action
98
+ xml.tag! 'n2:OrderTotal', amount(money).to_f.zero? ? localized_amount(100, currency_code) : localized_amount(money, currency_code), 'currencyID' => currency_code
99
+ if options[:max_amount]
100
+ xml.tag! 'n2:MaxAmount', localized_amount(options[:max_amount], currency_code), 'currencyID' => currency_code
101
+ end
102
+ add_address(xml, 'n2:Address', options[:shipping_address] || options[:address])
103
+ xml.tag! 'n2:AddressOverride', options[:address_override] ? '1' : '0'
104
+ xml.tag! 'n2:NoShipping', options[:no_shipping] ? '1' : '0'
105
+ xml.tag! 'n2:ReturnURL', options[:return_url]
106
+ xml.tag! 'n2:CancelURL', options[:cancel_return_url]
107
+ xml.tag! 'n2:IPAddress', options[:ip] unless options[:ip].blank?
108
+ xml.tag! 'n2:OrderDescription', options[:description]
109
+ xml.tag! 'n2:BuyerEmail', options[:email] unless options[:email].blank?
110
+ xml.tag! 'n2:InvoiceID', options[:order_id]
111
+
112
+ if options[:billing_agreement]
113
+ xml.tag! 'n2:BillingAgreementDetails' do
114
+ xml.tag! 'n2:BillingType', options[:billing_agreement][:type]
115
+ xml.tag! 'n2:BillingAgreementDescription', options[:billing_agreement][:description]
116
+ xml.tag! 'n2:PaymentType', options[:billing_agreement][:payment_type] || 'InstantOnly'
117
+ end
118
+ end
119
+
120
+ # Customization of the payment page
121
+ xml.tag! 'n2:PageStyle', options[:page_style] unless options[:page_style].blank?
122
+ xml.tag! 'n2:cpp-image-header', options[:header_image] unless options[:header_image].blank?
123
+ xml.tag! 'n2:cpp-header-back-color', options[:header_background_color] unless options[:header_background_color].blank?
124
+ xml.tag! 'n2:cpp-header-border-color', options[:header_border_color] unless options[:header_border_color].blank?
125
+ xml.tag! 'n2:cpp-payflow-color', options[:background_color] unless options[:background_color].blank?
126
+
127
+ if options[:allow_guest_checkout]
128
+ xml.tag! 'n2:SolutionType', 'Sole'
129
+ xml.tag! 'n2:LandingPage', 'Billing'
130
+ end
131
+
132
+ xml.tag! 'n2:LocaleCode', options[:locale] unless options[:locale].blank?
133
+ end
134
+ end
135
+ end
136
+
137
+ xml.target!
138
+ end
139
+
140
+ def build_response(success, message, response, options = {})
141
+ PaypalExpressResponse.new(success, message, response, options)
142
+ end
143
+ end
144
+ end
145
+ end