paypal-sdk-adaptivepayments 1.96.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +17 -0
- data/README.md +163 -0
- data/Rakefile +14 -0
- data/lib/paypal-sdk/adaptive_payments/api.rb +21 -0
- data/lib/paypal-sdk/adaptive_payments/data_types.rb +998 -0
- data/lib/paypal-sdk/adaptive_payments/services.rb +325 -0
- data/lib/paypal-sdk/adaptive_payments/version.rb +7 -0
- data/lib/paypal-sdk/adaptive_payments.rb +16 -0
- data/lib/paypal-sdk-adaptivepayments.rb +2 -0
- data/spec/adaptive_payments_spec.rb +27 -0
- data/spec/config/cert_key.pem +33 -0
- data/spec/config/paypal.yml +25 -0
- data/spec/convert_currency_spec.rb +39 -0
- data/spec/spec_helper.rb +6 -0
- metadata +86 -0
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'paypal-sdk-core', :git => "https://github.com/paypal/sdk-core-ruby.git"
|
6
|
+
|
7
|
+
if Dir.exist? File.expand_path('../samples', __FILE__)
|
8
|
+
gem 'adaptive_payments_samples', :path => 'samples', :require => false
|
9
|
+
group :test do
|
10
|
+
gem 'rspec-rails', :require => false
|
11
|
+
gem 'capybara', :require => false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'rspec'
|
17
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# AdaptivePayments
|
2
|
+
|
3
|
+
SDK for AdaptivePayments.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'paypal-sdk-adaptivepayments'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install paypal-sdk-adaptivepayments
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
For Rails application:
|
22
|
+
|
23
|
+
rails g paypal:sdk:install
|
24
|
+
|
25
|
+
For other ruby application, create a configuration file(`config/paypal.yml`):
|
26
|
+
|
27
|
+
development: &default
|
28
|
+
username: jb-us-seller_api1.paypal.com
|
29
|
+
password: WX4WTU3S8MY44S7F
|
30
|
+
signature: AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy
|
31
|
+
app_id: APP-80W284485P519543T
|
32
|
+
http_timeout: 30
|
33
|
+
mode: sandbox
|
34
|
+
sandbox_email_address: Platform.sdk.seller@gmail.com
|
35
|
+
# # with certificate
|
36
|
+
# cert_path: "config/cert_key.pem"
|
37
|
+
# # with token authentication
|
38
|
+
# token: ESTy2hio5WJQo1iixkH29I53RJxaS0Gvno1A6.YQXZgktxbY4I2Tdg
|
39
|
+
# token_secret: ZKPhUYuwJwYsfWdzorozWO2U9pI
|
40
|
+
# # with Proxy
|
41
|
+
# http_proxy: http://proxy-ipaddress:3129/
|
42
|
+
# # with device ip address
|
43
|
+
# device_ipaddress: "127.0.0.1"
|
44
|
+
test:
|
45
|
+
<<: *default
|
46
|
+
production:
|
47
|
+
<<: *default
|
48
|
+
mode: live
|
49
|
+
|
50
|
+
Load Configurations from specified file:
|
51
|
+
|
52
|
+
PayPal::SDK::Core::Config.load('config/paypal.yml', ENV['RACK_ENV'] || 'development')
|
53
|
+
|
54
|
+
## Create API object
|
55
|
+
|
56
|
+
Create API object:
|
57
|
+
|
58
|
+
api = PayPal::SDK::AdaptivePayments::API.new
|
59
|
+
|
60
|
+
Override configuration while creating a object:
|
61
|
+
|
62
|
+
api = PayPal::SDK::AdaptivePayments::API.new(:development)
|
63
|
+
api = PayPal::SDK::AdaptivePayments::API.new(:development, :app_id => "XYZ")
|
64
|
+
api = PayPal::SDK::AdaptivePayments::API.new(:app_id => "XYZ") # Take default environment.
|
65
|
+
|
66
|
+
Change configuration:
|
67
|
+
|
68
|
+
api.set_config :testing
|
69
|
+
api.set_config :testing, app_id => "XYZ"
|
70
|
+
|
71
|
+
|
72
|
+
## Build Request Object
|
73
|
+
|
74
|
+
To make api request, we need to build a request object.
|
75
|
+
|
76
|
+
# To build a empty request object for convert currency
|
77
|
+
convert_currency_request = api.build_convert_currency()
|
78
|
+
|
79
|
+
# To build a request object with default data
|
80
|
+
convert_currency_request = api.build_convert_currency( :baseAmountList => { :currency => [ { :code => "USD", :amount => "5.0" } ] } )
|
81
|
+
|
82
|
+
The Build method can be access with camelcase or underscore:
|
83
|
+
|
84
|
+
api = api.build_convert_currency()
|
85
|
+
# (or)
|
86
|
+
api = api.BuildConvertCurrency()
|
87
|
+
|
88
|
+
## Assign value to members
|
89
|
+
|
90
|
+
Members can be access with camelcase or underscore format.
|
91
|
+
|
92
|
+
pay_request.receiverList.receiver[0].amount = 1.0
|
93
|
+
# With underscore
|
94
|
+
pay_request.receiver_list.receiver[0].email = "platfo_1255612361_per@gmail.com"
|
95
|
+
|
96
|
+
To Assign multiple values:
|
97
|
+
|
98
|
+
pay_request.receiverList.receiver[0] = { :amount => "1.0", :email => "platfo_1255612361_per@gmail.com" }
|
99
|
+
|
100
|
+
To Get members list for the given object( For Reference ):
|
101
|
+
|
102
|
+
convert_currency_request.members
|
103
|
+
convert_currency_request.baseAmountList.members
|
104
|
+
|
105
|
+
## Make API Request
|
106
|
+
|
107
|
+
Make api call with request object:
|
108
|
+
|
109
|
+
pay_response = api.pay(pay_request)
|
110
|
+
|
111
|
+
Make api call with hash:
|
112
|
+
|
113
|
+
pay_response = api.pay({:baseAmountList => { :currency => [ { :code => "USD", :amount => "5.0" } ] }})
|
114
|
+
|
115
|
+
## Access values from response object
|
116
|
+
|
117
|
+
To get response status:
|
118
|
+
|
119
|
+
pay_response.responseEnvelope.ack
|
120
|
+
|
121
|
+
|
122
|
+
## Example
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
require 'paypal-sdk-adaptivepayments'
|
126
|
+
@api = PayPal::SDK::AdaptivePayments::API.new
|
127
|
+
|
128
|
+
# Build request object
|
129
|
+
@pay_request = @api.build_pay()
|
130
|
+
@pay_request.actionType = "PAY"
|
131
|
+
@pay_request.cancelUrl = "http://localhost:3000/adaptive_payments/pay"
|
132
|
+
@pay_request.currencyCode = "USD"
|
133
|
+
@pay_request.feesPayer = "SENDER"
|
134
|
+
@pay_request.receiverList.receiver[0].amount = 1.0
|
135
|
+
@pay_request.receiverList.receiver[0].email = "platfo_1255612361_per@gmail.com"
|
136
|
+
@pay_request.returnUrl = "http://localhost:3000/adaptive_payments/pay"
|
137
|
+
@pay_request.fundingConstraint.allowedFundingType.fundingTypeInfo = []
|
138
|
+
@pay_request.sender.email = "platfo_1255077030_biz@gmail.com"
|
139
|
+
|
140
|
+
# Make API call & get response
|
141
|
+
@pay_response = @api.pay(@pay_request)
|
142
|
+
|
143
|
+
# Access response
|
144
|
+
@pay_response.responseEnvelope.ack
|
145
|
+
```
|
146
|
+
|
147
|
+
## Samples
|
148
|
+
|
149
|
+
Add following line in rails `Gemfile`:
|
150
|
+
|
151
|
+
gem 'paypal-sdk-adaptivepayments'
|
152
|
+
gem 'adaptive_payments_samples', :git => "https://github.com/paypal/adaptivepayments-sdk-ruby.git", :group => :development
|
153
|
+
|
154
|
+
Configure routes(`config/routes.rb`):
|
155
|
+
|
156
|
+
mount AdaptivePaymentsSamples::Engine => "/samples" if Rails.env.development?
|
157
|
+
|
158
|
+
To get default paypal configuration execute:
|
159
|
+
|
160
|
+
rails g paypal:sdk:install
|
161
|
+
|
162
|
+
Run `rails server` and check the samples.
|
163
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc "Run tests"
|
4
|
+
task :rspec do
|
5
|
+
cmd = "bundle exec rspec && cd samples && bundle exec rspec"
|
6
|
+
system(cmd) || raise("#{cmd} failed")
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "View samples"
|
10
|
+
task :samples do
|
11
|
+
system("cd samples/spec/dummy && bundle exec rails server")
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :rspec
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'paypal-sdk-core'
|
2
|
+
|
3
|
+
module PayPal
|
4
|
+
module SDK
|
5
|
+
module AdaptivePayments
|
6
|
+
class API < Core::API::Platform
|
7
|
+
include Services
|
8
|
+
|
9
|
+
def initialize(environment = nil, options = {})
|
10
|
+
super(SERVICE_NAME, environment, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
ADAPTIVE_PAYMENTS_HTTP_HEADER = { "X-PAYPAL-REQUEST-SOURCE" => "adaptivepayments-ruby-sdk-#{VERSION}" }
|
14
|
+
def default_http_header
|
15
|
+
super.merge(ADAPTIVE_PAYMENTS_HTTP_HEADER)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|