creative-pp-adaptive 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +4 -0
- data/README.md +302 -0
- data/Rakefile +8 -0
- data/lib/pp-adaptive.rb +77 -0
- data/lib/pp-adaptive/abstract_request.rb +55 -0
- data/lib/pp-adaptive/abstract_response.rb +46 -0
- data/lib/pp-adaptive/cancel_preapproval_request.rb +7 -0
- data/lib/pp-adaptive/cancel_preapproval_response.rb +7 -0
- data/lib/pp-adaptive/client.rb +276 -0
- data/lib/pp-adaptive/convert_currency_request.rb +33 -0
- data/lib/pp-adaptive/convert_currency_response.rb +11 -0
- data/lib/pp-adaptive/exception.rb +4 -0
- data/lib/pp-adaptive/execute_payment_request.rb +9 -0
- data/lib/pp-adaptive/execute_payment_response.rb +12 -0
- data/lib/pp-adaptive/get_payment_options_request.rb +7 -0
- data/lib/pp-adaptive/get_payment_options_response.rb +32 -0
- data/lib/pp-adaptive/pay_request.rb +65 -0
- data/lib/pp-adaptive/pay_response.rb +29 -0
- data/lib/pp-adaptive/payment_details_request.rb +9 -0
- data/lib/pp-adaptive/payment_details_response.rb +53 -0
- data/lib/pp-adaptive/preapproval_details_request.rb +8 -0
- data/lib/pp-adaptive/preapproval_details_response.rb +35 -0
- data/lib/pp-adaptive/preapproval_request.rb +36 -0
- data/lib/pp-adaptive/preapproval_response.rb +7 -0
- data/lib/pp-adaptive/refund_request.rb +14 -0
- data/lib/pp-adaptive/refund_response.rb +12 -0
- data/lib/pp-adaptive/set_payment_options_request.rb +33 -0
- data/lib/pp-adaptive/set_payment_options_response.rb +7 -0
- data/lib/pp-adaptive/support/aliases.rb +33 -0
- data/lib/pp-adaptive/support/coerced_array.rb +58 -0
- data/lib/pp-adaptive/support/json_model.rb +141 -0
- data/lib/pp-adaptive/support/node.rb +46 -0
- data/lib/pp-adaptive/support/node_list.rb +44 -0
- data/lib/pp-adaptive/types/account_identifier.rb +6 -0
- data/lib/pp-adaptive/types/address.rb +17 -0
- data/lib/pp-adaptive/types/address_list.rb +5 -0
- data/lib/pp-adaptive/types/aliases/receiver_aliases.rb +15 -0
- data/lib/pp-adaptive/types/aliases/receiver_list_aliases.rb +32 -0
- data/lib/pp-adaptive/types/base_address.rb +11 -0
- data/lib/pp-adaptive/types/client_details_type.rb +12 -0
- data/lib/pp-adaptive/types/currency_code.rb +5 -0
- data/lib/pp-adaptive/types/currency_conversion.rb +17 -0
- data/lib/pp-adaptive/types/currency_conversion_list.rb +15 -0
- data/lib/pp-adaptive/types/currency_conversion_table.rb +5 -0
- data/lib/pp-adaptive/types/currency_list.rb +5 -0
- data/lib/pp-adaptive/types/currency_type.rb +6 -0
- data/lib/pp-adaptive/types/display_options.rb +8 -0
- data/lib/pp-adaptive/types/error_data.rb +11 -0
- data/lib/pp-adaptive/types/error_list.rb +5 -0
- data/lib/pp-adaptive/types/fault_message.rb +23 -0
- data/lib/pp-adaptive/types/funding_constraint.rb +5 -0
- data/lib/pp-adaptive/types/funding_plan.rb +28 -0
- data/lib/pp-adaptive/types/funding_plan_charge.rb +11 -0
- data/lib/pp-adaptive/types/funding_source.rb +9 -0
- data/lib/pp-adaptive/types/funding_type_info.rb +5 -0
- data/lib/pp-adaptive/types/funding_type_list.rb +5 -0
- data/lib/pp-adaptive/types/initiating_entity.rb +15 -0
- data/lib/pp-adaptive/types/institution_customer.rb +11 -0
- data/lib/pp-adaptive/types/invoice_data.rb +7 -0
- data/lib/pp-adaptive/types/invoice_item.rb +9 -0
- data/lib/pp-adaptive/types/pay_error.rb +18 -0
- data/lib/pp-adaptive/types/pay_error_list.rb +5 -0
- data/lib/pp-adaptive/types/payment_info.rb +16 -0
- data/lib/pp-adaptive/types/payment_info_list.rb +5 -0
- data/lib/pp-adaptive/types/phone_number_type.rb +7 -0
- data/lib/pp-adaptive/types/receiver.rb +17 -0
- data/lib/pp-adaptive/types/receiver_identifier.rb +12 -0
- data/lib/pp-adaptive/types/receiver_list.rb +5 -0
- data/lib/pp-adaptive/types/receiver_options.rb +21 -0
- data/lib/pp-adaptive/types/refund_info.rb +20 -0
- data/lib/pp-adaptive/types/refund_info_list.rb +5 -0
- data/lib/pp-adaptive/types/request_envelope.rb +6 -0
- data/lib/pp-adaptive/types/response_envelope.rb +13 -0
- data/lib/pp-adaptive/types/sender_identifier.rb +5 -0
- data/lib/pp-adaptive/types/sender_options.rb +5 -0
- data/lib/pp-adaptive/version.rb +3 -0
- data/pp-adaptive.gemspec +28 -0
- data/spec/public/cancel_preapproval_request_spec.rb +19 -0
- data/spec/public/cancel_preapproval_response_spec.rb +6 -0
- data/spec/public/client_spec.rb +151 -0
- data/spec/public/convert_currency_request_spec.rb +33 -0
- data/spec/public/convert_currency_response_spec.rb +62 -0
- data/spec/public/execute_payment_request_spec.rb +34 -0
- data/spec/public/execute_payment_response_spec.rb +66 -0
- data/spec/public/get_payment_options_request_spec.rb +19 -0
- data/spec/public/get_payment_options_response_spec.rb +141 -0
- data/spec/public/json_model_spec.rb +56 -0
- data/spec/public/node_list_spec.rb +58 -0
- data/spec/public/node_spec.rb +54 -0
- data/spec/public/pay_request_spec.rb +155 -0
- data/spec/public/pay_response_spec.rb +197 -0
- data/spec/public/payment_details_request_spec.rb +34 -0
- data/spec/public/payment_details_response_spec.rb +211 -0
- data/spec/public/preapproval_details_request_spec.rb +29 -0
- data/spec/public/preapproval_details_response_spec.rb +200 -0
- data/spec/public/preapproval_request_spec.rb +114 -0
- data/spec/public/preapproval_response_spec.rb +14 -0
- data/spec/public/refund_request_spec.rb +61 -0
- data/spec/public/refund_response_spec.rb +116 -0
- data/spec/public/set_payment_options_request_spec.rb +140 -0
- data/spec/public/set_payment_options_response_spec.rb +6 -0
- data/spec/shared/a_fault_message.rb +60 -0
- data/spec/shared/a_request_envelope.rb +14 -0
- data/spec/shared/a_response_envelope.rb +36 -0
- data/spec/spec_helper.rb +24 -0
- metadata +264 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79cad064ea06aef0e3e1d3ee573ab6a8ed146669
|
4
|
+
data.tar.gz: cea5a9a46df1c20f01228f4bd5ba84b66696efb0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0b46b651a5fe7b6689af8eab5befff332d719f62697d3cde86fe4753445c36a557b3ac784488a77981d2385ceebce7eaf4ba935283729a61f24d8ea0296b926
|
7
|
+
data.tar.gz: 0382f8145a703cb141041e9f02f376f6de34c2b31319f66b7a0637a0c09af6a8ed08b1bfc25ee2e168a33cc6a7419ab9f4e2b428ace4352189f46d714eaf2a70
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes in this gem will be documented here.
|
3
|
+
This project aspires to follow [semantic versioning](http://semver.org).
|
4
|
+
|
5
|
+
## 1.1.1 - 2016-05-05
|
6
|
+
### Added
|
7
|
+
- :receiver_email interpretation in PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID for mobile express checkouts
|
8
|
+
|
9
|
+
## 1.1.0 - 2016-03-03
|
10
|
+
### Added
|
11
|
+
- Support for mobile responsive express checkout via option and new methods on Client
|
12
|
+
- "pry" gem in dev dependencies, so one can `binding.pry`
|
13
|
+
|
14
|
+
## 1.0.0 - 2014-10-31
|
15
|
+
### Added
|
16
|
+
- Core funcionality
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,302 @@
|
|
1
|
+
# pp-adative [![Build Status](https://travis-ci.org/flippa/pp-adaptive.svg?branch=master)](https://travis-ci.org/flippa/pp-adaptive)
|
2
|
+
|
3
|
+
A Ruby API for PayPal Adaptive Payments
|
4
|
+
|
5
|
+
This gem provides access to PayPal's Adaptive Payments API using easy-to-use
|
6
|
+
ruby classes. The internals are largely backed by
|
7
|
+
[Virtus](https://github.com/solnic/virtus) and
|
8
|
+
[RestClient](https://github.com/archiloque/rest-client), and so are easy to
|
9
|
+
work with.
|
10
|
+
|
11
|
+
## Installing the Gem
|
12
|
+
|
13
|
+
Via rubygems:
|
14
|
+
|
15
|
+
gem install pp-adaptive
|
16
|
+
|
17
|
+
All API calls are made by calling `#execute` on the client, with the relevant
|
18
|
+
request type. Naming conventions have been ruby-ized, but you should just
|
19
|
+
follow along with the PayPal documentation to understand the inputs and outputs.
|
20
|
+
|
21
|
+
Some aliases have been added, to make things simpler. Some example scenarios
|
22
|
+
are outlined below, but due to the size of the API, this README does not aim
|
23
|
+
in any way to be an exhaustive reproduction of the official Adaptive Payments
|
24
|
+
documentation. Given the declarative, model-style, nature of the classes in
|
25
|
+
this gem, it probably makes sense to just browse the source to know what
|
26
|
+
fields are available.
|
27
|
+
|
28
|
+
## Example API calls
|
29
|
+
|
30
|
+
The following example should give you enough of an idea to be able to
|
31
|
+
follow your senses and use this gem in your own applications.
|
32
|
+
|
33
|
+
### <a name="regular_payment"></a> Taking a regular payment
|
34
|
+
|
35
|
+
A typical checkout payment request starts like this.
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
require "pp-adaptive"
|
39
|
+
|
40
|
+
client = AdaptivePayments::Client.new(
|
41
|
+
:user_id => "your-api-user-id",
|
42
|
+
:password => "your-api-password",
|
43
|
+
:signature => "your-api-signature",
|
44
|
+
:app_id => "your-app-id",
|
45
|
+
:sandbox => true
|
46
|
+
)
|
47
|
+
|
48
|
+
client.execute(:Pay,
|
49
|
+
:action_type => "PAY",
|
50
|
+
:receiver_email => "your@email.com",
|
51
|
+
:receiver_amount => 50,
|
52
|
+
:currency_code => "USD",
|
53
|
+
:cancel_url => "https://your-site.com/cancel",
|
54
|
+
:return_url => "https://your-site.com/return"
|
55
|
+
) do |response|
|
56
|
+
|
57
|
+
if response.success?
|
58
|
+
puts "Pay key: #{response.pay_key}"
|
59
|
+
|
60
|
+
# send the user to PayPal to make the payment
|
61
|
+
# e.g. https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=abc
|
62
|
+
redirect_to client.payment_url(response)
|
63
|
+
else
|
64
|
+
puts "#{response.ack_code}: #{response.error_message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
### Checking the payment status on return
|
71
|
+
|
72
|
+
When the customer is sent back from PayPal to your `return_url`, you need to
|
73
|
+
check if the payment was successful or not.
|
74
|
+
|
75
|
+
``` ruby
|
76
|
+
require "pp-adaptive"
|
77
|
+
|
78
|
+
client = AdaptivePayments::Client.new(
|
79
|
+
:user_id => "your-api-user-id",
|
80
|
+
:password => "your-api-password",
|
81
|
+
:signature => "your-api-signature",
|
82
|
+
:app_id => "your-app-id",
|
83
|
+
:sandbox => true
|
84
|
+
)
|
85
|
+
|
86
|
+
client.execute(:PaymentDetails, :pay_key => "pay-key-from-pay-request") do |response|
|
87
|
+
if response.success?
|
88
|
+
puts "Payment status: #{response.payment_exec_status}"
|
89
|
+
else
|
90
|
+
puts "#{response.ack_code}: #{response.error_message}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
### Initiating a chained payment
|
96
|
+
|
97
|
+
If you need to take a cut of a payment and forward the remainder onto one
|
98
|
+
or more other recipients, you use a chained payment. This is just a regular
|
99
|
+
PayRequest, except it includes multiple receivers, one of which is marked as
|
100
|
+
'primary'.
|
101
|
+
|
102
|
+
``` ruby
|
103
|
+
require "pp-adaptive"
|
104
|
+
|
105
|
+
client = AdaptivePayments::Client.new(
|
106
|
+
:user_id => "your-api-user-id",
|
107
|
+
:password => "your-api-password",
|
108
|
+
:signature => "your-api-signature",
|
109
|
+
:app_id => "your-app-id",
|
110
|
+
:sandbox => true
|
111
|
+
)
|
112
|
+
|
113
|
+
client.execute(:Pay,
|
114
|
+
:action_type => "PAY",
|
115
|
+
:currency_code => "USD",
|
116
|
+
:cancel_url => "https://your-site.com/cancel",
|
117
|
+
:return_url => "https://your-site.com/return",
|
118
|
+
:receivers => [
|
119
|
+
{ :email => "your@email.com", :amount => 50, :primary => true },
|
120
|
+
{ :email => "other@site.tld", :amount => 45 }
|
121
|
+
]
|
122
|
+
) do |response|
|
123
|
+
|
124
|
+
if response.success?
|
125
|
+
puts "Pay key: #{response.pay_key}"
|
126
|
+
|
127
|
+
# send the user to PayPal to make the payment
|
128
|
+
# e.g. https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=abc
|
129
|
+
redirect_to client.payment_url(response)
|
130
|
+
else
|
131
|
+
puts "#{response.ack_code}: #{response.error_message}"
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
In the above example, you get $5 from the $50 payment, with the remaining $45
|
138
|
+
going to other@site.tld.
|
139
|
+
|
140
|
+
### Setting up a Preapproval Agreement
|
141
|
+
|
142
|
+
If you need to be able to take payments from a user's account on-demand, you
|
143
|
+
get the user to authorize you for preapproved payments.
|
144
|
+
|
145
|
+
``` ruby
|
146
|
+
require "pp-adaptive"
|
147
|
+
|
148
|
+
client = AdaptivePayments::Client.new(
|
149
|
+
:user_id => "your-api-user-id",
|
150
|
+
:password => "your-api-password",
|
151
|
+
:signature => "your-api-signature",
|
152
|
+
:app_id => "your-app-id",
|
153
|
+
:sandbox => false
|
154
|
+
)
|
155
|
+
|
156
|
+
client.execute(:Preapproval,
|
157
|
+
:ending_date => DateTime.now.next_year,
|
158
|
+
:starting_date => DateTime.now,
|
159
|
+
:max_total_amount => BigDecimal("950.00"),
|
160
|
+
:currency_code => "USD",
|
161
|
+
:cancel_url => "http://site.com/cancelled",
|
162
|
+
:return_url => "http://site.com/completed"
|
163
|
+
) do |response|
|
164
|
+
# you may alternatively pass a PreapprovalRequest instance
|
165
|
+
|
166
|
+
if response.success?
|
167
|
+
puts "Preapproval key: #{response.preapproval_key}"
|
168
|
+
|
169
|
+
# send the user to PayPal to give their approval
|
170
|
+
# e.g. https://www.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=abc
|
171
|
+
redirect_to client.preapproval_url(response)
|
172
|
+
else
|
173
|
+
puts "#{response.ack_code}: #{response.error_message}"
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
### Taking a payment using an existing Preapproval
|
180
|
+
|
181
|
+
To take a payment from a user who has previously authorized you for preapproved
|
182
|
+
payments, just pass the `pay_key` in the usual PayRequest.
|
183
|
+
|
184
|
+
``` ruby
|
185
|
+
require "pp-adaptive"
|
186
|
+
|
187
|
+
client = AdaptivePayments::Client.new(
|
188
|
+
:user_id => "your-api-user-id",
|
189
|
+
:password => "your-api-password",
|
190
|
+
:signature => "your-api-signature",
|
191
|
+
:app_id => "your-app-id",
|
192
|
+
:sandbox => false
|
193
|
+
)
|
194
|
+
|
195
|
+
client.execute(:Pay,
|
196
|
+
:preapproval_key => "existing-preapproval-key",
|
197
|
+
:action_type => "PAY",
|
198
|
+
:receiver_email => "your@email.com",
|
199
|
+
:receiver_amount => 50,
|
200
|
+
:currency_code => "USD",
|
201
|
+
:cancel_url => "https://your-site.com/cancel",
|
202
|
+
:return_url => "https://your-site.com/return"
|
203
|
+
) do |response|
|
204
|
+
|
205
|
+
if response.success?
|
206
|
+
puts "Pay key: #{response.pay_key}"
|
207
|
+
puts "Status: #{response.payment_exec_status}"
|
208
|
+
else
|
209
|
+
puts "#{response.ack_code}: #{response.error_message}"
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
215
|
+
### Issuing a refund
|
216
|
+
|
217
|
+
If you have the pay_key from a previously made payment (up to 60 days), you
|
218
|
+
can send a RefundRequest.
|
219
|
+
|
220
|
+
``` ruby
|
221
|
+
require "pp-adaptive"
|
222
|
+
|
223
|
+
client = AdaptivePayments::Client.new(
|
224
|
+
:user_id => "your-api-user-id",
|
225
|
+
:password => "your-api-password",
|
226
|
+
:signature => "your-api-signature",
|
227
|
+
:app_id => "your-app-id",
|
228
|
+
:sandbox => false
|
229
|
+
)
|
230
|
+
|
231
|
+
client.execute(:Refund, :pay_key => "the-pay-key") do |response|
|
232
|
+
if response.success?
|
233
|
+
puts "Refund sent"
|
234
|
+
else
|
235
|
+
puts "#{response.ack_code}: #{response.error_message}"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
```
|
239
|
+
|
240
|
+
You can also do partial refunds by passing an `amount` field in the request.
|
241
|
+
|
242
|
+
### <a name="mobile_checkout"></a>Taking a regular payment with a responsive mobile checkout
|
243
|
+
Mobile checkouts uses the [Mobile Express Checkout](https://developer.paypal.com/docs/classic/express-checkout/ht_ec-singleItemPayment-curl-etc/) setup, an alternative to adaptive API.
|
244
|
+
The difference is that there is a first POST to paypal to retrieve a token, then a redirect to PayPal, and finally, another POST to paypal after user accepts the payment to finalize the deal.
|
245
|
+
|
246
|
+
Please consult `client.rb#express_handshake` and `client.rb#express_perform` for details on what options to pass and what to expect in response.
|
247
|
+
|
248
|
+
A TODO is to wrap the response strings in more functional response objects.
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
# 1. initialize @client with the optional :checkout_type attribute
|
252
|
+
@client = AdaptivePayments::Client.new(
|
253
|
+
:user_id => "your-api-user-id",
|
254
|
+
:password => "your-api-password",
|
255
|
+
:signature => "your-api-signature",
|
256
|
+
:app_id => "your-app-id",
|
257
|
+
:sandbox => true,
|
258
|
+
:checkout_type => "mobile" # this does the trick
|
259
|
+
)
|
260
|
+
|
261
|
+
# 2. call the handshake method and obtain the token
|
262
|
+
@client.express_handshake(options) do |response|
|
263
|
+
token = response.split("&").select{|param| param["TOKEN="].present?}.first.split("=").last
|
264
|
+
if token.present?
|
265
|
+
# do some transaction logging
|
266
|
+
redirect_to @client.express_checkout_url(token))
|
267
|
+
else
|
268
|
+
render json: response
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
# User does his thing at PayPal here
|
273
|
+
|
274
|
+
# 3. process PayPal return GET parameters at success_path
|
275
|
+
@client.express_perform(options)) do |response|
|
276
|
+
success = response["ACK=Success"].present? ? true : false
|
277
|
+
# use success boolean to process logging, order updates
|
278
|
+
end
|
279
|
+
```
|
280
|
+
|
281
|
+
### Other API calls
|
282
|
+
|
283
|
+
Adaptive Payments is a very extensive API with a lot of endpoints and a lot
|
284
|
+
of fields within each request. It wouldn't be wise to attempt to document them
|
285
|
+
all here, but the official API documentation covers everything in detail.
|
286
|
+
|
287
|
+
https://developer.paypal.com/webapps/developer/docs/classic/adaptive-payments/integration-guide/APIntro/
|
288
|
+
|
289
|
+
Just ruby-ize the fields (i.e. underscores, not camel case) and open up the
|
290
|
+
request/response classes in this repository to get a feel for how this all works.
|
291
|
+
|
292
|
+
## Contributors
|
293
|
+
|
294
|
+
* [d11wtq](https://github.com/d11wtq)
|
295
|
+
* [Maxim-Filimonov](https://github.com/Maxim-Filimonov)
|
296
|
+
* [hajder](https://github.com/hajder)
|
297
|
+
* [Epigene](https://github.com/Epigene)
|
298
|
+
|
299
|
+
## License & Copyright
|
300
|
+
|
301
|
+
Copyright © Flippa.com Pty Ltd. Licensed under the MIT license. See the
|
302
|
+
LICENSE file for details.
|
data/Rakefile
ADDED
data/lib/pp-adaptive.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "pp-adaptive/version"
|
2
|
+
|
3
|
+
require "pp-adaptive/exception"
|
4
|
+
|
5
|
+
require "pp-adaptive/support/aliases"
|
6
|
+
require "pp-adaptive/support/json_model"
|
7
|
+
require "pp-adaptive/support/coerced_array"
|
8
|
+
require "pp-adaptive/support/node"
|
9
|
+
require "pp-adaptive/support/node_list"
|
10
|
+
|
11
|
+
require "pp-adaptive/types/aliases/receiver_aliases"
|
12
|
+
require "pp-adaptive/types/aliases/receiver_list_aliases"
|
13
|
+
|
14
|
+
require "pp-adaptive/types/client_details_type"
|
15
|
+
require "pp-adaptive/types/request_envelope"
|
16
|
+
require "pp-adaptive/types/phone_number_type"
|
17
|
+
require "pp-adaptive/types/receiver"
|
18
|
+
require "pp-adaptive/types/receiver_list"
|
19
|
+
require "pp-adaptive/types/account_identifier"
|
20
|
+
require "pp-adaptive/types/sender_identifier"
|
21
|
+
require "pp-adaptive/types/funding_type_info"
|
22
|
+
require "pp-adaptive/types/funding_type_list"
|
23
|
+
require "pp-adaptive/types/funding_constraint"
|
24
|
+
require "pp-adaptive/types/response_envelope"
|
25
|
+
require "pp-adaptive/types/error_data"
|
26
|
+
require "pp-adaptive/types/error_list"
|
27
|
+
require "pp-adaptive/types/fault_message"
|
28
|
+
require "pp-adaptive/types/base_address"
|
29
|
+
require "pp-adaptive/types/address"
|
30
|
+
require "pp-adaptive/types/address_list"
|
31
|
+
require "pp-adaptive/types/currency_type"
|
32
|
+
require "pp-adaptive/types/currency_code"
|
33
|
+
require "pp-adaptive/types/currency_list"
|
34
|
+
require "pp-adaptive/types/currency_conversion"
|
35
|
+
require "pp-adaptive/types/currency_conversion_list"
|
36
|
+
require "pp-adaptive/types/currency_conversion_table"
|
37
|
+
require "pp-adaptive/types/funding_source"
|
38
|
+
require "pp-adaptive/types/funding_plan_charge"
|
39
|
+
require "pp-adaptive/types/funding_plan"
|
40
|
+
require "pp-adaptive/types/invoice_item"
|
41
|
+
require "pp-adaptive/types/invoice_data"
|
42
|
+
require "pp-adaptive/types/institution_customer"
|
43
|
+
require "pp-adaptive/types/initiating_entity"
|
44
|
+
require "pp-adaptive/types/receiver_identifier"
|
45
|
+
require "pp-adaptive/types/display_options"
|
46
|
+
require "pp-adaptive/types/sender_options"
|
47
|
+
require "pp-adaptive/types/receiver_options"
|
48
|
+
require "pp-adaptive/types/pay_error"
|
49
|
+
require "pp-adaptive/types/pay_error_list"
|
50
|
+
require "pp-adaptive/types/payment_info"
|
51
|
+
require "pp-adaptive/types/payment_info_list"
|
52
|
+
require "pp-adaptive/types/refund_info"
|
53
|
+
require "pp-adaptive/types/refund_info_list"
|
54
|
+
|
55
|
+
require "pp-adaptive/abstract_request"
|
56
|
+
require "pp-adaptive/abstract_response"
|
57
|
+
require "pp-adaptive/pay_request"
|
58
|
+
require "pp-adaptive/pay_response"
|
59
|
+
require "pp-adaptive/payment_details_request"
|
60
|
+
require "pp-adaptive/payment_details_response"
|
61
|
+
require "pp-adaptive/execute_payment_request"
|
62
|
+
require "pp-adaptive/execute_payment_response"
|
63
|
+
require "pp-adaptive/get_payment_options_request"
|
64
|
+
require "pp-adaptive/get_payment_options_response"
|
65
|
+
require "pp-adaptive/set_payment_options_request"
|
66
|
+
require "pp-adaptive/set_payment_options_response"
|
67
|
+
require "pp-adaptive/preapproval_request"
|
68
|
+
require "pp-adaptive/preapproval_response"
|
69
|
+
require "pp-adaptive/preapproval_details_request"
|
70
|
+
require "pp-adaptive/preapproval_details_response"
|
71
|
+
require "pp-adaptive/cancel_preapproval_request"
|
72
|
+
require "pp-adaptive/cancel_preapproval_response"
|
73
|
+
require "pp-adaptive/refund_request"
|
74
|
+
require "pp-adaptive/refund_response"
|
75
|
+
require "pp-adaptive/convert_currency_request"
|
76
|
+
require "pp-adaptive/convert_currency_response"
|
77
|
+
require "pp-adaptive/client"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module AdaptivePayments
|
2
|
+
# AbstractRequest is a JsonModel that defines some default behaviour for all requests
|
3
|
+
#
|
4
|
+
# A request defines the operation it executes and provides a method for building the corresponding response.
|
5
|
+
# All requests provide a RequestEnvelope by default. There is no need to re-define it in descendants.
|
6
|
+
class AbstractRequest < JsonModel
|
7
|
+
# The RequestEnvelope, providing the detail_level and error_language.
|
8
|
+
#
|
9
|
+
# Aliases are defined for #detail_level and #error_language. They do not need to be accessed through the
|
10
|
+
# request_envelope.
|
11
|
+
attribute :request_envelope, Node[RequestEnvelope], :param => "requestEnvelope"
|
12
|
+
|
13
|
+
alias_params :request_envelope, {
|
14
|
+
:detail_level => :detail_level,
|
15
|
+
:error_language => :error_language
|
16
|
+
}
|
17
|
+
|
18
|
+
class << self
|
19
|
+
# Set or get the API operation for the request class
|
20
|
+
#
|
21
|
+
# @param [Symbol] name
|
22
|
+
# the name of the operation defined in the Adaptive Payments API, optional
|
23
|
+
#
|
24
|
+
# @return [Symbol]
|
25
|
+
# the name of the operation defined in the Adaptive Payments API
|
26
|
+
def operation(name = nil)
|
27
|
+
@operation = name unless name.nil?
|
28
|
+
@operation
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get the request class for the given operation.
|
32
|
+
#
|
33
|
+
# @param [Symbol] operation
|
34
|
+
# the name of the operation
|
35
|
+
#
|
36
|
+
# @return [AbstractRequest]
|
37
|
+
# the request subclass
|
38
|
+
def for_operation(name)
|
39
|
+
AdaptivePayments.const_get(name.to_s + "Request")
|
40
|
+
end
|
41
|
+
|
42
|
+
# Given a JSON string, return the corresponding response.
|
43
|
+
#
|
44
|
+
# @param [String] json
|
45
|
+
# the raw JSON string as returned by the API
|
46
|
+
#
|
47
|
+
# @return [AbstractResponse]
|
48
|
+
# the corresponding response for the JSON
|
49
|
+
def build_response(json)
|
50
|
+
klass = AdaptivePayments.const_get(operation.to_s + "Response")
|
51
|
+
klass.from_json(json.to_s)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|