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.
@@ -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 dir + '/paypal_adaptive_payments/utils.rb'
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
- include AdaptivePaymentResponses
12
- include AdaptiveUtils
11
+ include AdaptivePaymentResponses
12
+ include AdaptiveUtils
13
13
 
14
- TEST_URL = 'https://svcs.sandbox.paypal.com/AdaptivePayments/'
15
- LIVE_URL = 'https://svcs.paypal.com/AdaptivePayments/'
14
+ TEST_URL = 'https://svcs.sandbox.paypal.com/AdaptivePayments/'
15
+ LIVE_URL = 'https://svcs.paypal.com/AdaptivePayments/'
16
16
 
17
- # The countries the gateway supports merchants from as 2 digit ISO
18
- # country codes
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
- # The homepage URL of the gateway
22
- self.homepage_url = 'http://x.com/'
20
+ # The homepage URL of the gateway
21
+ self.homepage_url = 'http://x.com/'
23
22
 
24
- # The name of the gateway
25
- self.display_name = 'Paypal Adaptive Payments'
23
+ # The name of the gateway
24
+ self.display_name = 'Paypal Adaptive Payments'
26
25
 
27
- attr_accessor :config_path
28
- @config_path = "#{::Rails.root.to_s}/config/paypal.yml"
26
+ attr_accessor :config_path
27
+ @config_path = "#{RAILS_ROOT}/config/paypal.yml"
29
28
 
30
- def initialize(options = {})
31
- @config = {}
32
- if options.empty?
33
- load_config
34
- else
35
- @config.merge! options
36
- end
37
- end
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
- def pay(options)
40
- commit 'Pay', build_adaptive_payment_pay_request(options)
41
- end
38
+ def pay(options)
39
+ commit 'Pay', build_adaptive_payment_pay_request(options)
40
+ end
42
41
 
43
- def execute_payment(options)
44
- commit 'ExecutePayment', build_adaptive_payment_execute_request(options)
45
- end
42
+ def details_for_payment options
43
+ commit 'PaymentDetails', build_adaptive_payment_details_request(options)
44
+ end
46
45
 
47
- def details_for_payment options
48
- commit 'PaymentDetails', build_adaptive_payment_details_request(options)
49
- end
46
+ def refund options
47
+ commit 'Refund', build_adaptive_refund_details(options)
48
+ end
50
49
 
51
- def refund options
52
- commit 'Refund', build_adaptive_refund_details(options)
53
- end
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
- # Send a preapproval request to pay pal
56
- #
57
- # ==== Options
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
- def preapproval_details_for options
73
- commit 'PreapprovalDetails', build_preapproval_details(options)
74
- end
71
+ def preapproval_details_for options
72
+ commit 'PreapprovalDetails', build_preapproval_details(options)
73
+ end
75
74
 
76
- def convert_currency options
77
- commit 'ConvertCurrency', build_currency_conversion(options)
78
- end
75
+ def convert_currency options
76
+ commit 'ConvertCurrency', build_currency_conversion(options)
77
+ end
79
78
 
80
- #debug method, provides an easy to use debug method for the class
81
- def debug
82
- "Url: #{@url}\n\n JSON: #{@xml} \n\n Raw: #{@raw}"
83
- end
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
- private
84
+ private
86
85
 
87
- #loads config from default file if it is not provided to the constructor
88
- def load_config
89
- raise ConfigDoesNotExist if !File.exists?(@config_path);
90
- @config.merge! Yaml.load_file(@config_path)[Rails.env || RAILS_ENV].symbolize_keys!
91
- end
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
- def build_adaptive_payment_pay_request opts
94
- @xml = ''
95
- xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
96
- xml.instruct!
97
- xml.PayRequest do |x|
98
- x.requestEnvelope do |x|
99
- x.detailLevel 'ReturnAll'
100
- x.errorLanguage opts[:error_language] ||= 'en_US'
101
- end
102
- x.actionType opts[:pay_primary] ? 'PAY_PRIMARY' : 'PAY'
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.trackingId opts[:tracking_id] if opts[:tracking_id]
109
- x.memo opts[:memo] if opts[:memo]
110
- x.pin opts[:pin] if opts[:pin]
111
- x.currencyCode opts[:currency_code] ||= 'USD'
112
- x.senderEmail opts[:senders_email] if opts[:senders_email]
113
- x.receiverList do |x|
114
- opts[:receiver_list].each do |receiver|
115
- x.receiver do |x|
116
- x.email receiver[:email]
117
- x.amount currency_to_two_places(receiver[:amount])
118
- x.primary receiver[:primary] if receiver[:primary]
119
- x.paymentType receiver[:payment_type] ||= 'GOODS'
120
- x.invoiceId receiver[:invoice_id] if receiver[:invoice_id]
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
- def build_adaptive_payment_execute_request opts
129
- @xml = ''
130
- xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
131
- xml.instruct!
132
- xml.ExecutePaymentRequest do |x|
133
- x.requestEnvelope do |x|
134
- x.detailLevel 'ReturnAll'
135
- x.errorLanguage opts[:error_language] ||= 'en_US'
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
- def build_adaptive_payment_details_request opts
142
- @xml = ''
143
- xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
144
- xml.instruct!
145
- xml.PayRequest do |x|
146
- x.requestEnvelope do |x|
147
- x.detailLevel 'ReturnAll'
148
- x.errorLanguage opts[:error_language] ||= 'en_US'
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
- def build_adaptive_refund_details options
155
- @xml = ''
156
- xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
157
- xml.instruct!
158
- xml.RefundRequest do |x|
159
- x.requestEnvelope do |x|
160
- x.detailLevel 'ReturnAll'
161
- x.errorLanguage options[:error_language] ||= 'en_US'
162
- end
163
- x.actionType 'REFUND'
164
- if options[:pay_key]
165
- x.payKey options[:pay_key]
166
- end
167
- if options[:transaction_id]
168
- x.payKey options[:transaction_id]
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
- def build_preapproval_payment options
189
- opts = {
190
- :currency_code => "USD",
191
- :start_date => DateTime.current
192
- }.update(options)
193
-
194
- @xml = ''
195
- xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
196
- xml.instruct!
197
- xml.PreapprovalRequest do |x|
198
- # request envelope
199
- x.requestEnvelope do |x|
200
- x.detailLevel 'ReturnAll'
201
- x.errorLanguage opts[:error_language] ||= 'en_US'
202
- end
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
- # required preapproval fields
205
- x.endingDate opts[:end_date].strftime("%Y-%m-%dT%H:%M:%S%Z")
206
- x.startingDate opts[:start_date].strftime("%Y-%m-%dT%H:%M:%S%Z")
207
- x.maxTotalAmountOfAllPayments opts[:max_amount]
208
- x.currencyCode opts[:currency_code]
209
- x.cancelUrl opts[:cancel_url]
210
- x.returnUrl opts[:return_url]
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
- def build_preapproval_details options
225
- @xml = ''
226
- xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
227
- xml.instruct!
228
- xml.PreapprovalDetailsRequest do |x|
229
- x.requestEnvelope do |x|
230
- x.detailLevel 'ReturnAll'
231
- x.errorLanguage opts[:error_language] ||= 'en_US'
232
- end
233
- x.preapprovalKey options[:preapproval_key]
234
- x.getBillingAddress options[:get_billing_address] if options[:get_billing_address]
235
- end
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
- def build_currency_conversion options
239
- @xml = ''
240
- xml = Builder::XmlMarkup.new :target => @xml, :indent => 2
241
- xml.instruct!
242
- xml.ConvertCurrencyRequest do |x|
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
- def parse json
262
- @raw = json
263
- resp = JSON.parse json
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
- def commit(action, data)
273
- @response = parse(post_through_ssl(action, data))
274
- end
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
- def post_through_ssl(action, parameters = {})
277
- headers = {
278
- "X-PAYPAL-REQUEST-DATA-FORMAT" => "XML",
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
- def endpoint_url
297
- test? ? TEST_URL : LIVE_URL
298
- end
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
- def test?
301
- Base.gateway_mode == :test
302
- end
296
+ def endpoint_url
297
+ test? ? TEST_URL : LIVE_URL
298
+ end
303
299
 
304
- def url action
305
- @url = URI.parse(endpoint_url + action)
306
- end
300
+ def test?
301
+ Base.gateway_mode == :test
302
+ end
307
303
 
308
- end
304
+ def url action
305
+ @url = URI.parse(endpoint_url + action)
309
306
  end
310
- end
307
+
308
+ end; end; end
@@ -1,82 +1,134 @@
1
- module ActiveMerchant
2
- module Billing
3
- module AdaptivePaymentResponses
4
-
5
- class AdaptivePaypalSuccessResponse
6
-
7
- BASE_REDIRECT_URL = 'https://www.paypal.com/webscr?cmd='
8
- TEST_BASE_REDIRECT_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd='
9
- PAY_COMMAND = '_ap-payment&paykey='
10
- PREAPPROVAL_COMMAND = '_ap-preapproval&preapprovalkey='
11
-
12
- attr_reader :paykey, :preapprovalkey
13
-
14
- def initialize json
15
-
16
- @paykey = json['payKey']
17
- @preapprovalkey = json['preapprovalKey']
18
- @params = json
19
- end
20
-
21
- def redirect_url_for
22
- (Base.gateway_mode == :test ? TEST_BASE_REDIRECT_URL : BASE_REDIRECT_URL) + PAY_COMMAND + @paykey
23
- end
24
-
25
- def redirect_preapproval_url_for
26
- (Base.gateway_mode == :test ? TEST_BASE_REDIRECT_URL : BASE_REDIRECT_URL) + PREAPPROVAL_COMMAND + @preapprovalkey
27
- end
28
-
29
- def ack
30
- @params['responseEnvelope']['ack']
31
- end
32
-
33
- def method_missing name
34
- begin
35
- @params[name.to_s]
36
- rescue
37
- raise AttributenotFound
38
- end
39
- end
40
-
41
- def [](key)
42
- return @params[key] if @params.include? key
43
- raise AttributenotFound
44
- end
45
-
46
- def status
47
- @params['status']
48
- end
49
-
50
- def refund_status
51
- @params["refundInfoList"]["refundInfo"].first["refundStatus"]
52
- end
53
-
54
- def execute_status
55
- @params['paymentExecStatus']
56
- end
57
-
58
- def refund_complete?
59
- refund_status == 'REFUNDED' || refund_status == 'ALREADY_REVERSED_OR_REFUNDED'
60
- end
61
-
62
- def execute_complete?
63
- execute_status == 'COMPLETED'
64
- end
65
-
66
- end
67
-
68
- class AdaptivePaypalErrorResponse
69
-
70
- def initialize error
71
- @raw = error
72
- end
73
-
74
- def debug
75
- @raw.inspect
76
- end
77
-
78
- end
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
@@ -0,0 +1,10 @@
1
+ # fix for case sensitive headers in paypal (issue #1)
2
+ module Net; module HTTPHeader
3
+ def []= key, val
4
+ unless val
5
+ @header.delete key
6
+ return val
7
+ end
8
+ @header[key] = [val]
9
+ end
10
+ end; end
@@ -1,14 +1,8 @@
1
- module ActiveMerchant
2
- module Billing
3
-
4
- module AdaptiveUtils
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.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-21 00:00:00.000000000 +10:00
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: &9269640 !ruby/object:Gem::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: *9269640
25
+ version_requirements: *13160920
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &9266120 !ruby/object:Gem::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: *9266120
36
+ version_requirements: *13160440
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: builder
39
- requirement: &9265100 !ruby/object:Gem::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: *9265100
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