active_paypal_adaptive_payment 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb +255 -257
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/adaptive_payment_response.rb +131 -79
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/exceptions.rb +4 -5
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/ext.rb +10 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/utils.rb +7 -13
- metadata +9 -8
@@ -1,310 +1,308 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
dir = File.dirname(__FILE__)
|
3
|
+
require dir + '/paypal_adaptive_payments/ext.rb'
|
4
|
+
require dir + '/paypal_adaptive_payments/utils.rb'
|
3
5
|
require dir + '/paypal_adaptive_payments/exceptions.rb'
|
4
6
|
require dir + '/paypal_adaptive_payments/adaptive_payment_response.rb'
|
5
|
-
require
|
7
|
+
require 'json/add/rails'
|
6
8
|
|
7
|
-
module ActiveMerchant
|
8
|
-
module Billing
|
9
|
-
class PaypalAdaptivePaymentGateway < Gateway
|
9
|
+
module ActiveMerchant; module Billingl class PaypalAdaptivePaymentGateway < Gateway
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
include AdaptivePaymentResponses
|
12
|
+
include AdaptiveUtils
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
TEST_URL = 'https://svcs.sandbox.paypal.com/AdaptivePayments/'
|
15
|
+
LIVE_URL = 'https://svcs.paypal.com/AdaptivePayments/'
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
self.supported_countries = ['US']
|
17
|
+
# The countries the gateway supports merchants from as 2 digit ISO country codes
|
18
|
+
self.supported_countries = ['US']
|
20
19
|
|
21
|
-
|
22
|
-
|
20
|
+
# The homepage URL of the gateway
|
21
|
+
self.homepage_url = 'http://x.com/'
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
# The name of the gateway
|
24
|
+
self.display_name = 'Paypal Adaptive Payments'
|
26
25
|
|
27
|
-
|
28
|
-
|
26
|
+
attr_accessor :config_path
|
27
|
+
@config_path = "#{RAILS_ROOT}/config/paypal.yml"
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
def initialize(options = {})
|
30
|
+
@config = {}
|
31
|
+
if options.empty?
|
32
|
+
load_config
|
33
|
+
else
|
34
|
+
@config.merge! options
|
35
|
+
end
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
def pay(options)
|
39
|
+
commit 'Pay', build_adaptive_payment_pay_request(options)
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
def details_for_payment options
|
43
|
+
commit 'PaymentDetails', build_adaptive_payment_details_request(options)
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def refund options
|
47
|
+
commit 'Refund', build_adaptive_refund_details(options)
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
# Send a preapproval request to pay pal
|
51
|
+
#
|
52
|
+
# ==== Options
|
53
|
+
#
|
54
|
+
# * +:end_date+ - _xs:datetime_ The ending date
|
55
|
+
# * +:start_date+ - _xs:datetime_ The start date (defaults: current)
|
56
|
+
# * +:max_amount+ - _xs:decimal_ The preapproved maximum total amount of all payments.
|
57
|
+
# * +:currency_code+ - The currency code (defaults: USD)
|
58
|
+
# * +:cancel_url+ - URL to redirect the sender’s browser to after canceling the preapproval
|
59
|
+
# * +:return_url+ - URL to redirect the sender’s browser to after the sender has logged into PayPal and confirmed the preapproval
|
60
|
+
# * +:notify_url+ - The URL to which you want all IPN messages for this preapproval to be sent. (Optional)
|
61
|
+
#
|
62
|
+
# To get more details on fields see +Paypal PreApproval API+ at https://www.x.com/docs/DOC-1419
|
63
|
+
def preapprove_payment options
|
64
|
+
commit 'Preapproval', build_preapproval_payment(options)
|
65
|
+
end
|
54
66
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
# * +:end_date+ - _xs:datetime_ The ending date
|
60
|
-
# * +:start_date+ - _xs:datetime_ The start date (defaults: current)
|
61
|
-
# * +:max_amount+ - _xs:decimal_ The preapproved maximum total amount of all payments.
|
62
|
-
# * +:currency_code+ - The currency code (defaults: USD)
|
63
|
-
# * +:cancel_url+ - URL to redirect the sender’s browser to after canceling the preapproval
|
64
|
-
# * +:return_url+ - URL to redirect the sender’s browser to after the sender has logged into PayPal and confirmed the preapproval
|
65
|
-
# * +:notify_url+ - The URL to which you want all IPN messages for this preapproval to be sent. (Optional)
|
66
|
-
#
|
67
|
-
# To get more details on fields see +Paypal PreApproval API+ at https://www.x.com/docs/DOC-1419
|
68
|
-
def preapprove_payment options
|
69
|
-
commit 'Preapproval', build_preapproval_payment(options)
|
70
|
-
end
|
67
|
+
def cancel_preapproval options
|
68
|
+
commit 'CancelPreapproval', build_cancel_preapproval(options)
|
69
|
+
end
|
71
70
|
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
def preapproval_details_for options
|
72
|
+
commit 'PreapprovalDetails', build_preapproval_details(options)
|
73
|
+
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
def convert_currency options
|
76
|
+
commit 'ConvertCurrency', build_currency_conversion(options)
|
77
|
+
end
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
#debug method, provides an easy to use debug method for the class
|
80
|
+
def debug
|
81
|
+
"Url: #{@url}\n\n JSON: #{@xml} \n\n Raw: #{@raw}"
|
82
|
+
end
|
84
83
|
|
85
|
-
|
84
|
+
private
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
#loads config from default file if it is not provided to the constructor
|
87
|
+
def load_config
|
88
|
+
raise ConfigDoesNotExist if !File.exists?(@config_path);
|
89
|
+
@config.merge! Yaml.load_file(@config_path)[RAILS_ENV].symbolize_keys!
|
90
|
+
end
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
end
|
92
|
+
def build_adaptive_payment_pay_request opts
|
93
|
+
@xml = ''
|
94
|
+
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
|
95
|
+
xml.instruct!
|
96
|
+
xml.PayRequest do |x|
|
97
|
+
x.requestEnvelope do |x|
|
98
|
+
x.detailLevel 'ReturnAll'
|
99
|
+
x.errorLanguage opts[:error_language] ||= 'en_US'
|
100
|
+
end
|
101
|
+
x.actionType 'PAY'
|
102
|
+
x.senderEmail opts[:senderEmail]
|
103
|
+
x.cancelUrl opts[:cancel_url]
|
104
|
+
x.returnUrl opts[:return_url]
|
105
|
+
if opts[:notify_url]
|
106
|
+
x.ipnNotificationUrl opts[:notify_url]
|
107
|
+
end
|
108
|
+
x.memo opts[:memo] if opts[:memo]
|
109
|
+
x.feesPayer opts[:feesPayer] if opts[:feesPayer]
|
110
|
+
x.pin opts[:pin] if opts[:pin]
|
111
|
+
x.currencyCode opts[:currency_code] ||= 'USD'
|
112
|
+
x.receiverList do |x|
|
113
|
+
opts[:receiver_list].each do |receiver|
|
114
|
+
x.receiver do |x|
|
115
|
+
x.email receiver[:email]
|
116
|
+
x.amount currency_to_two_places(receiver[:amount])
|
117
|
+
x.primary receiver[:primary] if receiver[:primary]
|
118
|
+
x.paymentType receiver[:payment_type] ||= 'GOODS'
|
119
|
+
x.invoiceId receiver[:invoice_id] if receiver[:invoice_id]
|
123
120
|
end
|
124
|
-
x.feesPayer opts[:fees_payer] ||= 'EACHRECEIVER'
|
125
121
|
end
|
126
122
|
end
|
123
|
+
x.reverseAllParallelPaymentsOnError opts[:reverse_all_parallel_payments_on_error] || 'false'
|
124
|
+
end
|
125
|
+
end
|
127
126
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
x.payKey opts[:paykey]
|
138
|
-
end
|
127
|
+
def build_adaptive_payment_details_request opts
|
128
|
+
@xml = ''
|
129
|
+
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
|
130
|
+
xml.instruct!
|
131
|
+
xml.PayRequest do |x|
|
132
|
+
x.requestEnvelope do |x|
|
133
|
+
x.detailLevel 'ReturnAll'
|
134
|
+
x.errorLanguage opts[:error_language] ||= 'en_US'
|
139
135
|
end
|
136
|
+
x.payKey opts[:paykey]
|
137
|
+
end
|
138
|
+
end
|
140
139
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
140
|
+
def build_adaptive_refund_details options
|
141
|
+
@xml = ''
|
142
|
+
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
|
143
|
+
xml.instruct!
|
144
|
+
xml.RefundRequest do |x|
|
145
|
+
x.requestEnvelope do |x|
|
146
|
+
x.detailLevel 'ReturnAll'
|
147
|
+
x.errorLanguage options[:error_language] ||= 'en_US'
|
148
|
+
end
|
149
|
+
x.actionType 'REFUND'
|
150
|
+
if options[:pay_key]
|
151
|
+
x.payKey options[:pay_key]
|
152
|
+
end
|
153
|
+
if options[:transaction_id]
|
154
|
+
x.payKey options[:transaction_id]
|
155
|
+
end
|
156
|
+
if options[:tracking_id]
|
157
|
+
x.trackingId options[:tracking_id]
|
158
|
+
end
|
159
|
+
x.cancelUrl options[:cancel_url]
|
160
|
+
x.returnUrl options[:return_url]
|
161
|
+
x.currencyCode options[:currency_code] ||= 'USD'
|
162
|
+
x.receiverList do |x|
|
163
|
+
options[:receiver_list].each do |receiver|
|
164
|
+
x.receiver do |x|
|
165
|
+
x.amount receiver[:amount]
|
166
|
+
x.paymentType receiver[:payment_type] ||= 'GOODS'
|
167
|
+
x.invoiceId receiver[:invoice_id] if receiver[:invoice_id]
|
168
|
+
x.email receiver[:email]
|
149
169
|
end
|
150
|
-
x.payKey opts[:paykey]
|
151
170
|
end
|
152
171
|
end
|
172
|
+
x.feesPayer options[:fees_payer] ||= 'EACHRECEIVER'
|
173
|
+
end
|
174
|
+
end
|
153
175
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
170
|
-
if options[:tracking_id]
|
171
|
-
x.trackingId options[:tracking_id]
|
172
|
-
end
|
173
|
-
x.currencyCode options[:currency_code] ||= 'USD'
|
174
|
-
x.receiverList do |x|
|
175
|
-
options[:receiver_list].each do |receiver|
|
176
|
-
x.receiver do |x|
|
177
|
-
x.amount receiver[:amount]
|
178
|
-
x.paymentType receiver[:payment_type] ||= 'GOODS'
|
179
|
-
x.invoiceId receiver[:invoice_id] if receiver[:invoice_id]
|
180
|
-
x.email receiver[:email]
|
181
|
-
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
176
|
+
def build_preapproval_payment options
|
177
|
+
opts = {
|
178
|
+
:currency_code => "USD",
|
179
|
+
:start_date => DateTime.current
|
180
|
+
}.update(options)
|
181
|
+
|
182
|
+
@xml = ''
|
183
|
+
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
|
184
|
+
xml.instruct!
|
185
|
+
xml.PreapprovalRequest do |x|
|
186
|
+
# request envelope
|
187
|
+
x.requestEnvelope do |x|
|
188
|
+
x.detailLevel 'ReturnAll'
|
189
|
+
x.errorLanguage opts[:error_language] ||= 'en_US'
|
190
|
+
x.senderEmail opts[:senderEmail]
|
186
191
|
end
|
187
192
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
193
|
+
# required preapproval fields
|
194
|
+
x.endingDate opts[:end_date].strftime("%Y-%m-%dT%H%%3a%M%%3a%S")
|
195
|
+
x.startingDate opts[:start_date].strftime("%Y-%m-%dT%H%%3a%M%%3a%S")
|
196
|
+
x.maxTotalAmountOfAllPayments opts[:max_amount]
|
197
|
+
x.maxNumberOfPayments opts[:maxNumberOfPayments]
|
198
|
+
x.currencyCode options[:currency_code]
|
199
|
+
x.cancelUrl opts[:cancel_url]
|
200
|
+
x.returnUrl opts[:return_url]
|
201
|
+
|
202
|
+
# notify url
|
203
|
+
if opts[:notify_url]
|
204
|
+
x.ipnNotificationUrl opts[:notify_url]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
203
208
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
#optional preapproval fields
|
213
|
-
x.maxAmountPerPayment opts[:max_amount_per_payment] unless opts[:max_amount_per_payment].blank?
|
214
|
-
x.maxNumberOfPayments opts[:max_number_of_payments] unless opts[:max_number_of_payments].blank?
|
215
|
-
x.memo opts[:memo] unless opts[:memo].blank?
|
216
|
-
|
217
|
-
# notify url
|
218
|
-
if opts[:notify_url]
|
219
|
-
x.ipnNotificationUrl opts[:notify_url]
|
220
|
-
end
|
221
|
-
end
|
209
|
+
def build_preapproval_details options
|
210
|
+
@xml = ''
|
211
|
+
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
|
212
|
+
xml.instruct!
|
213
|
+
xml.PreapprovalDetailsRequest do |x|
|
214
|
+
x.requestEnvelope do |x|
|
215
|
+
x.detailLevel 'ReturnAll'
|
216
|
+
x.errorLanguage options[:error_language] ||= 'en_US'
|
222
217
|
end
|
218
|
+
x.preapprovalKey options[:preapproval_key]
|
219
|
+
x.getBillingAddress options[:get_billing_address] if options[:get_billing_address]
|
220
|
+
end
|
221
|
+
end
|
223
222
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
223
|
+
def build_cancel_preapproval options
|
224
|
+
@xml = ''
|
225
|
+
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
|
226
|
+
xml.instruct!
|
227
|
+
xml.PreapprovalDetailsRequest do |x|
|
228
|
+
x.requestEnvelope do |x|
|
229
|
+
x.detailLevel 'ReturnAll'
|
230
|
+
x.errorLanguage options[:error_language] ||= 'en_US'
|
231
|
+
end
|
232
|
+
x.preapprovalKey options[:preapproval_key]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def build_currency_conversion options
|
237
|
+
@xml = ''
|
238
|
+
xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
|
239
|
+
xml.instruct!
|
240
|
+
xml.ConvertCurrencyRequest do |x|
|
241
|
+
x.requestEnvelope do |x|
|
242
|
+
x.detailLevel 'ReturnAll'
|
243
|
+
x.errorLanguage options[:error_language] ||= 'en_US'
|
236
244
|
end
|
237
245
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
x.requestEnvelope do |x|
|
244
|
-
x.detailLevel 'ReturnAll'
|
245
|
-
x.errorLanguage opts[:error_language] ||= 'en_US'
|
246
|
-
end
|
247
|
-
x.baseAmountList do |x|
|
248
|
-
x.currency do |x|
|
249
|
-
x.amount options[:amount]
|
250
|
-
x.code options[:currency_code] ||= 'USD'
|
251
|
-
end
|
252
|
-
end
|
253
|
-
x.convertoToCurrencyList do |x|
|
254
|
-
options[:currencies].each do |currency|
|
255
|
-
x.currency currency
|
256
|
-
end
|
246
|
+
x.baseAmountList do |x|
|
247
|
+
options[:currency_list].each do |currency|
|
248
|
+
x.currency do |x|
|
249
|
+
x.amount currency[:amount]
|
250
|
+
x.code currency[:code ]
|
257
251
|
end
|
258
252
|
end
|
259
253
|
end
|
260
254
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
if resp['responseEnvelope']['ack'] == 'Failure'
|
265
|
-
error = AdaptivePaypalErrorResponse.new(resp)
|
266
|
-
raise PaypalAdaptivePaymentsApiError.new(error)
|
267
|
-
else
|
268
|
-
AdaptivePaypalSuccessResponse.new(resp)
|
255
|
+
x.convertToCurrencyList do |x|
|
256
|
+
options[:to_currencies].each do |k,v|
|
257
|
+
x.currencyCode "#{v}"
|
269
258
|
end
|
270
259
|
end
|
260
|
+
end
|
261
|
+
end
|
271
262
|
|
272
|
-
|
273
|
-
|
274
|
-
|
263
|
+
def parse json
|
264
|
+
@raw = json
|
265
|
+
resp = JSON.parse json
|
266
|
+
if resp['responseEnvelope']['ack'] == 'Failure'
|
267
|
+
error = AdaptivePaypalErrorResponse.new(json)
|
268
|
+
else
|
269
|
+
AdaptivePaypalSuccessResponse.new(resp)
|
270
|
+
end
|
271
|
+
end
|
275
272
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON",
|
280
|
-
"X-PAYPAL-SECURITY-USERID" => @config[:login],
|
281
|
-
"X-PAYPAL-SECURITY-PASSWORD" => @config[:password],
|
282
|
-
"X-PAYPAL-SECURITY-SIGNATURE" => @config[:signature],
|
283
|
-
"X-PAYPAL-APPLICATION-ID" => @config[:appid]
|
284
|
-
}
|
285
|
-
url action
|
286
|
-
request = Net::HTTP::Post.new(@url.path)
|
287
|
-
request.body = @xml
|
288
|
-
headers.each_pair { |k,v| request[k] = v }
|
289
|
-
request.content_type = 'text/xml'
|
290
|
-
server = Net::HTTP.new(@url.host, 443)
|
291
|
-
server.use_ssl = true
|
292
|
-
server.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
293
|
-
server.start { |http| http.request(request) }.body
|
294
|
-
end
|
273
|
+
def commit(action, data)
|
274
|
+
@response = parse(post_through_ssl(action, data))
|
275
|
+
end
|
295
276
|
|
296
|
-
|
297
|
-
|
298
|
-
|
277
|
+
def post_through_ssl(action, parameters = {})
|
278
|
+
headers = {
|
279
|
+
"X-PAYPAL-REQUEST-DATA-FORMAT" => "XML",
|
280
|
+
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON",
|
281
|
+
"X-PAYPAL-SECURITY-USERID" => @config[:login],
|
282
|
+
"X-PAYPAL-SECURITY-PASSWORD" => @config[:password],
|
283
|
+
"X-PAYPAL-SECURITY-SIGNATURE" => @config[:signature],
|
284
|
+
"X-PAYPAL-APPLICATION-ID" => @config[:appid]
|
285
|
+
}
|
286
|
+
url action
|
287
|
+
request = Net::HTTP::Post.new(@url.path)
|
288
|
+
request.body = @xml
|
289
|
+
headers.each_pair { |k,v| request[k] = v }
|
290
|
+
request.content_type = 'text/xml'
|
291
|
+
server = Net::HTTP.new(@url.host, 443)
|
292
|
+
server.use_ssl = true
|
293
|
+
server.start { |http| http.request(request) }.body
|
294
|
+
end
|
299
295
|
|
300
|
-
|
301
|
-
|
302
|
-
|
296
|
+
def endpoint_url
|
297
|
+
test? ? TEST_URL : LIVE_URL
|
298
|
+
end
|
303
299
|
|
304
|
-
|
305
|
-
|
306
|
-
|
300
|
+
def test?
|
301
|
+
Base.gateway_mode == :test
|
302
|
+
end
|
307
303
|
|
308
|
-
|
304
|
+
def url action
|
305
|
+
@url = URI.parse(endpoint_url + action)
|
309
306
|
end
|
310
|
-
|
307
|
+
|
308
|
+
end; end; end
|
data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/adaptive_payment_response.rb
CHANGED
@@ -1,82 +1,134 @@
|
|
1
|
-
module ActiveMerchant
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
1
|
+
module ActiveMerchant; module Billing; module AdaptivePaymentResponses
|
2
|
+
|
3
|
+
class AdaptivePaypalSuccessResponse
|
4
|
+
|
5
|
+
REDIRECT_URL = 'https://www.paypal.com/webscr?cmd=_ap-payment&paykey='
|
6
|
+
TEST_REDIRECT_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey='
|
7
|
+
|
8
|
+
attr_reader :paykey
|
9
|
+
|
10
|
+
def initialize json
|
11
|
+
@paykey = json['payKey']
|
12
|
+
@params = json
|
13
|
+
end
|
14
|
+
|
15
|
+
def redirect_url_for
|
16
|
+
Base.gateway_mode == :test ? (TEST_REDIRECT_URL + @paykey) : (REDIRECT_URL + @paykey)
|
17
|
+
end
|
18
|
+
|
19
|
+
def ack
|
20
|
+
@params['responseEnvelope']['ack']
|
21
|
+
end
|
22
|
+
|
23
|
+
def paymentExecStatus
|
24
|
+
@params['paymentExecStatus']
|
25
|
+
end
|
26
|
+
|
27
|
+
def transactionStatus
|
28
|
+
@params['transactionStatus']
|
29
|
+
end
|
30
|
+
|
31
|
+
def senderEmail
|
32
|
+
@params['senderEmail']
|
33
|
+
end
|
34
|
+
|
35
|
+
def actionType
|
36
|
+
@params['actionType']
|
37
|
+
end
|
38
|
+
|
39
|
+
def feesPayer
|
40
|
+
@params['feesPayer']
|
41
|
+
end
|
42
|
+
|
43
|
+
def currencyCode
|
44
|
+
@params['currencyCode']
|
45
|
+
end
|
46
|
+
|
47
|
+
def payKey
|
48
|
+
@params['payKey']
|
49
|
+
end
|
50
|
+
|
51
|
+
def correlationId
|
52
|
+
@params['responseEnvelope']['correlationId']
|
53
|
+
end
|
54
|
+
|
55
|
+
def build
|
56
|
+
@params['responseEnvelope']['build']
|
57
|
+
end
|
58
|
+
|
59
|
+
def refundInfoList
|
60
|
+
@params['refundInfoList']
|
61
|
+
end
|
62
|
+
|
63
|
+
def preapprovalKey
|
64
|
+
@params['preapprovalKey']
|
65
|
+
end
|
66
|
+
|
67
|
+
def curPaymentsAmount
|
68
|
+
@params['curPaymentsAmount']
|
69
|
+
end
|
70
|
+
|
71
|
+
def status
|
72
|
+
@params['status']
|
73
|
+
end
|
74
|
+
|
75
|
+
def curPeriodAttempts
|
76
|
+
@params['curPeriodAttempts']
|
77
|
+
end
|
78
|
+
|
79
|
+
def approved
|
80
|
+
@params['approved']
|
81
|
+
end
|
82
|
+
|
83
|
+
def method_missing name
|
84
|
+
begin
|
85
|
+
@params[name.to_s]
|
86
|
+
rescue
|
87
|
+
raise AttributenotFound
|
80
88
|
end
|
81
89
|
end
|
90
|
+
|
91
|
+
def [](key)
|
92
|
+
return @params[key] if @params.include? key
|
93
|
+
raise AttributenotFound
|
94
|
+
end
|
95
|
+
|
96
|
+
def status
|
97
|
+
@params['status']
|
98
|
+
end
|
99
|
+
|
82
100
|
end
|
101
|
+
|
102
|
+
class AdaptivePaypalErrorResponse
|
103
|
+
|
104
|
+
def initialize error
|
105
|
+
@raw = error
|
106
|
+
@errlist = ActiveSupport::JSON.decode(error)
|
107
|
+
end
|
108
|
+
|
109
|
+
def debug
|
110
|
+
@raw.inspect
|
111
|
+
end
|
112
|
+
|
113
|
+
def ack
|
114
|
+
@raw['responseEnvelope']['ack']
|
115
|
+
end
|
116
|
+
|
117
|
+
def timestamp
|
118
|
+
@raw['responseEnvelope']['timestamp']
|
119
|
+
end
|
120
|
+
|
121
|
+
def build
|
122
|
+
@raw['responseEnvelope']['build']
|
123
|
+
end
|
124
|
+
|
125
|
+
def correlationId
|
126
|
+
@raw['responseEnvelope']['correlationId']
|
127
|
+
end
|
128
|
+
|
129
|
+
def errormessage
|
130
|
+
@errlist['error']
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end; end; end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
class ConfigDoesNotExist < StandardError; end;
|
2
|
-
|
3
2
|
class AttributenotFound < StandardError; end;
|
4
3
|
|
5
4
|
class PaypalAdaptivePaymentsApiError < StandardError
|
6
|
-
|
5
|
+
|
7
6
|
attr_reader :response
|
8
|
-
|
7
|
+
|
9
8
|
def initialize response
|
10
9
|
@response = response
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
def debug
|
14
13
|
@response.inspect
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
end
|
@@ -1,14 +1,8 @@
|
|
1
|
-
module ActiveMerchant
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def currency_to_two_places amount
|
7
|
-
return 0.01 if amount < 0.01
|
8
|
-
("%.2f" % amount).to_f
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
1
|
+
module ActiveMerchant; module Billing; module AdaptiveUtils
|
2
|
+
|
3
|
+
def currency_to_two_places amount
|
4
|
+
return 0.01 if amount < 1
|
5
|
+
("%.2f" % amount).to_f
|
14
6
|
end
|
7
|
+
|
8
|
+
end; end; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_paypal_adaptive_payment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-28 00:00:00.000000000 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemerchant
|
17
|
-
requirement: &
|
17
|
+
requirement: &13160920 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.5.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *13160920
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &13160440 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 3.0.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *13160440
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: builder
|
39
|
-
requirement: &
|
39
|
+
requirement: &13159960 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: 2.0.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *13159960
|
48
48
|
description: This library is meant to interface with PayPal web services Adaptive
|
49
49
|
Payment Gateway Library.
|
50
50
|
email:
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/active_merchant/billing/gateways/paypal_adaptive_payments/exceptions.rb
|
58
58
|
- lib/active_merchant/billing/gateways/paypal_adaptive_payments/utils.rb
|
59
59
|
- lib/active_merchant/billing/gateways/paypal_adaptive_payments/adaptive_payment_response.rb
|
60
|
+
- lib/active_merchant/billing/gateways/paypal_adaptive_payments/ext.rb
|
60
61
|
- lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb
|
61
62
|
- MIT-LICENSE
|
62
63
|
- README.markdown
|