active_paypal_adaptive_payment 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +0 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +130 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb +310 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/adaptive_payment_response.rb +82 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/exceptions.rb +17 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/utils.rb +14 -0
- data/lib/active_paypal_adaptive_payment.rb +13 -0
- metadata +89 -0
data/CHANGELOG
ADDED
File without changes
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jose Pablo Barrantes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# Active PayPal Adaptive Payment
|
2
|
+
|
3
|
+
This library is meant to interface with PayPal web services Adaptive Payment Gateway Library.
|
4
|
+
|
5
|
+
[Active Merchant]:http://www.activemerchant.org
|
6
|
+
|
7
|
+

|
8
|
+
|
9
|
+
## Supported
|
10
|
+
|
11
|
+
* payments
|
12
|
+
* preapprovals
|
13
|
+
* refunds
|
14
|
+
* currency conversions
|
15
|
+
* more soon!
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add the following line to your app Gemfile:
|
20
|
+
|
21
|
+
gem "active_paypal_adaptive_payment", "~> 0.1.0"
|
22
|
+
|
23
|
+
## Implementation
|
24
|
+
|
25
|
+
In your { payment/order }_controller.rb
|
26
|
+
|
27
|
+
def gateway
|
28
|
+
@gateway ||= PaypalAdaptivePaymentGateway.new(
|
29
|
+
:login => 'your_email',
|
30
|
+
:password => 'your_password',
|
31
|
+
:signature => ' your_signature',
|
32
|
+
:appid => 'your_app_id'
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
## Payment process
|
37
|
+
|
38
|
+
### Chained payments
|
39
|
+
|
40
|
+
def checkout
|
41
|
+
recipients = [{:email => 'receiver_email',
|
42
|
+
:amount => some_amount,
|
43
|
+
:primary => true},
|
44
|
+
{:email => 'receiver_email',
|
45
|
+
:amount => recipient_amount,
|
46
|
+
:primary => false}
|
47
|
+
]
|
48
|
+
response = gateway.pay(
|
49
|
+
:return_url => url_for(:action => 'action', :only_path => false),
|
50
|
+
:cancel_url => url_for(:action => 'action', :only_path => false),
|
51
|
+
:notify_url => url_for(:action => 'notify_action', :only_path => false),
|
52
|
+
:receiver_list => recipients
|
53
|
+
)
|
54
|
+
redirect_to response.redirect_url_for
|
55
|
+
end
|
56
|
+
|
57
|
+
Set the `:primary` flag to `false` for each recipient for a split payment.
|
58
|
+
|
59
|
+
## Debugging
|
60
|
+
|
61
|
+
Use either gateway.debug or response.debug this gives you the json
|
62
|
+
response, the xml sent and the url it was posted to.
|
63
|
+
|
64
|
+
From the Rails console it can be accessed like such:
|
65
|
+
|
66
|
+
ActiveMerchant::Billing::PaypalAdaptivePaymentGateway
|
67
|
+
|
68
|
+
## TODO
|
69
|
+
|
70
|
+
* Better documentation
|
71
|
+
|
72
|
+
## Contributors
|
73
|
+
|
74
|
+
* Jose Pablo Barrantes (<http://jpablobr.com/>)
|
75
|
+
* Zarne Dravitzki (<http://github.com/zarno>)
|
76
|
+
|
77
|
+
## Other previous contributors where some code was taken from.
|
78
|
+
|
79
|
+
* [Tommy Chheng](http://tommy.chheng.com)
|
80
|
+
- [Paypal Adaptive Ruby Gem Released](http://tommy.chheng.com/2009/12/29/paypal-adaptive-ruby-gem-released/)
|
81
|
+
- [paypal_adaptive](https://github.com/tc/paypal_adaptive)
|
82
|
+
|
83
|
+
* [lamp (Matt)](https://github.com/lamp)
|
84
|
+
- [paypal_adaptive_gateway](https://github.com/lamp/paypal_adaptive_gateway)
|
85
|
+
|
86
|
+
* [sentientmonkey (Scott Windsor)](https://github.com/sentientmonkey)
|
87
|
+
- [active_merchant](https://github.com/sentientmonkey/active_merchant)
|
88
|
+
|
89
|
+
* [sijokg](https://github.com/sijokg)
|
90
|
+
- [active_merchant](https://github.com/sijokg/active_merchant)
|
91
|
+
|
92
|
+
## Some PayPal Adaptive payment resources.
|
93
|
+
|
94
|
+
* [Adaptive Payment Fee Calculation Analysis](https://www.x.com/docs/DOC-2401)
|
95
|
+
* [ActiveMerchant paypaladaptive payments gateway](http://www.rorexperts.com/activemerchant-paypaladaptive-payments-gateway-t2245.html)
|
96
|
+
* [Trying to use with Paypal adaptive payments](http://groups.google.com/group/activemerchant/browse_thread/thread/866ad7dc5019c199/2a280b7dc396c41b?lnk=gst&q=adaptive+payment#2a280b7dc396c41b)
|
97
|
+
* [adpative payments (chained)](http://groups.google.com/group/activemerchant/browse_thread/thread/165c3e0bf4d10c02/aa8dd082b58354d9?lnk=gst&q=adaptive+payment#aa8dd082b58354d9)
|
98
|
+
* [Testing with a sandbox account without being logged on developer.paypal.com](http://groups.google.com/group/activemerchant/browse_thread/thread/ad69fc8116bfdf64/483f22071bb25e25?lnk=gst&q=adaptive+payment#483f22071bb25e25)
|
99
|
+
* [Split a transaction to distribute funds to two accounts?](http://groups.google.com/group/activemerchant/browse_thread/thread/e1f53087aee9d0c/2cd63df363861ce1?lnk=gst&q=adaptive+payment#2cd63df363861ce1)
|
100
|
+
|
101
|
+
## Note on Patches/Pull Requests:
|
102
|
+
|
103
|
+
* Fork the project.
|
104
|
+
* Make your feature addition or bug fix.
|
105
|
+
* Send me a pull request. Bonus points for topic branches.
|
106
|
+
|
107
|
+
## Copyright:
|
108
|
+
|
109
|
+
(The MIT License)
|
110
|
+
|
111
|
+
Copyright 2011 Jose Pablo Barrantes. MIT Licence, so go for it.
|
112
|
+
|
113
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
114
|
+
copy of this software and associated documentation files (the
|
115
|
+
'Software'), to deal in the Software without restriction, including
|
116
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
117
|
+
distribute, sublicense, an d/or sell copies of the Software, and to
|
118
|
+
permit persons to whom the Software is furnished to do so, subject to
|
119
|
+
the following conditions:
|
120
|
+
|
121
|
+
The above copyright notice and this permission notice shall be included
|
122
|
+
in all copies or substantial portions of the Software.
|
123
|
+
|
124
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
125
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
126
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
127
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
128
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
129
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
130
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,310 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
dir = File.dirname(__FILE__)
|
3
|
+
require dir + '/paypal_adaptive_payments/exceptions.rb'
|
4
|
+
require dir + '/paypal_adaptive_payments/adaptive_payment_response.rb'
|
5
|
+
require dir + '/paypal_adaptive_payments/utils.rb'
|
6
|
+
|
7
|
+
module ActiveMerchant
|
8
|
+
module Billing
|
9
|
+
class PaypalAdaptivePaymentGateway < Gateway
|
10
|
+
|
11
|
+
include AdaptivePaymentResponses
|
12
|
+
include AdaptiveUtils
|
13
|
+
|
14
|
+
TEST_URL = 'https://svcs.sandbox.paypal.com/AdaptivePayments/'
|
15
|
+
LIVE_URL = 'https://svcs.paypal.com/AdaptivePayments/'
|
16
|
+
|
17
|
+
# The countries the gateway supports merchants from as 2 digit ISO
|
18
|
+
# country codes
|
19
|
+
self.supported_countries = ['US']
|
20
|
+
|
21
|
+
# The homepage URL of the gateway
|
22
|
+
self.homepage_url = 'http://x.com/'
|
23
|
+
|
24
|
+
# The name of the gateway
|
25
|
+
self.display_name = 'Paypal Adaptive Payments'
|
26
|
+
|
27
|
+
attr_accessor :config_path
|
28
|
+
@config_path = "#{::Rails.root.to_s}/config/paypal.yml"
|
29
|
+
|
30
|
+
def initialize(options = {})
|
31
|
+
@config = {}
|
32
|
+
if options.empty?
|
33
|
+
load_config
|
34
|
+
else
|
35
|
+
@config.merge! options
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def pay(options)
|
40
|
+
commit 'Pay', build_adaptive_payment_pay_request(options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def execute_payment(options)
|
44
|
+
commit 'ExecutePayment', build_adaptive_payment_execute_request(options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def details_for_payment options
|
48
|
+
commit 'PaymentDetails', build_adaptive_payment_details_request(options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def refund options
|
52
|
+
commit 'Refund', build_adaptive_refund_details(options)
|
53
|
+
end
|
54
|
+
|
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
|
71
|
+
|
72
|
+
def preapproval_details_for options
|
73
|
+
commit 'PreapprovalDetails', build_preapproval_details(options)
|
74
|
+
end
|
75
|
+
|
76
|
+
def convert_currency options
|
77
|
+
commit 'ConvertCurrency', build_currency_conversion(options)
|
78
|
+
end
|
79
|
+
|
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
|
84
|
+
|
85
|
+
private
|
86
|
+
|
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
|
92
|
+
|
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
|
123
|
+
end
|
124
|
+
x.feesPayer opts[:fees_payer] ||= 'EACHRECEIVER'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
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
|
139
|
+
end
|
140
|
+
|
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'
|
149
|
+
end
|
150
|
+
x.payKey opts[:paykey]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
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
|
186
|
+
end
|
187
|
+
|
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
|
203
|
+
|
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
|
222
|
+
end
|
223
|
+
|
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
|
236
|
+
end
|
237
|
+
|
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
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
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)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def commit(action, data)
|
273
|
+
@response = parse(post_through_ssl(action, data))
|
274
|
+
end
|
275
|
+
|
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
|
295
|
+
|
296
|
+
def endpoint_url
|
297
|
+
test? ? TEST_URL : LIVE_URL
|
298
|
+
end
|
299
|
+
|
300
|
+
def test?
|
301
|
+
Base.gateway_mode == :test
|
302
|
+
end
|
303
|
+
|
304
|
+
def url action
|
305
|
+
@url = URI.parse(endpoint_url + action)
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
data/lib/active_merchant/billing/gateways/paypal_adaptive_payments/adaptive_payment_response.rb
ADDED
@@ -0,0 +1,82 @@
|
|
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
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ConfigDoesNotExist < StandardError; end;
|
2
|
+
|
3
|
+
class AttributenotFound < StandardError; end;
|
4
|
+
|
5
|
+
class PaypalAdaptivePaymentsApiError < StandardError
|
6
|
+
|
7
|
+
attr_reader :response
|
8
|
+
|
9
|
+
def initialize response
|
10
|
+
@response = response
|
11
|
+
end
|
12
|
+
|
13
|
+
def debug
|
14
|
+
@response.inspect
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_merchant/common'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'active_support'
|
9
|
+
require 'active_merchant/common'
|
10
|
+
end
|
11
|
+
|
12
|
+
dir = File.dirname(__FILE__) + '/active_merchant/billing/gateways'
|
13
|
+
require dir + '/paypal_adaptive_payment'
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_paypal_adaptive_payment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jose Pablo Barrantes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-21 00:00:00.000000000 +10:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activemerchant
|
17
|
+
requirement: &9269640 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *9269640
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activesupport
|
28
|
+
requirement: &9266120 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *9266120
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: builder
|
39
|
+
requirement: &9265100 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.0.0
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *9265100
|
48
|
+
description: This library is meant to interface with PayPal web services Adaptive
|
49
|
+
Payment Gateway Library.
|
50
|
+
email:
|
51
|
+
- xjpablobrx@gmail.com
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- lib/active_paypal_adaptive_payment.rb
|
57
|
+
- lib/active_merchant/billing/gateways/paypal_adaptive_payments/exceptions.rb
|
58
|
+
- lib/active_merchant/billing/gateways/paypal_adaptive_payments/utils.rb
|
59
|
+
- lib/active_merchant/billing/gateways/paypal_adaptive_payments/adaptive_payment_response.rb
|
60
|
+
- lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb
|
61
|
+
- MIT-LICENSE
|
62
|
+
- README.markdown
|
63
|
+
- CHANGELOG
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/jpablobr/active_paypal_adaptive_payment
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- - lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.6
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.6.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: ActiveMercant PayPal Adaptive Payment Library
|
89
|
+
test_files: []
|