adapt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/lib/adapt.rb +16 -0
- data/lib/adapt/base.rb +101 -0
- data/lib/adapt/common.rb +13 -0
- data/lib/adapt/common/client_details.rb +14 -0
- data/lib/adapt/common/error_data.rb +16 -0
- data/lib/adapt/common/error_parameter.rb +7 -0
- data/lib/adapt/common/fault_message.rb +8 -0
- data/lib/adapt/common/phone_number_type.rb +9 -0
- data/lib/adapt/common/receiver.rb +14 -0
- data/lib/adapt/common/receiver_list.rb +7 -0
- data/lib/adapt/common/request_envelope.rb +8 -0
- data/lib/adapt/common/response_envelope.rb +10 -0
- data/lib/adapt/methods.rb +14 -0
- data/lib/adapt/methods/cancel_preapproval.rb +7 -0
- data/lib/adapt/methods/convert_currency.rb +40 -0
- data/lib/adapt/methods/execute_payment.rb +7 -0
- data/lib/adapt/methods/get_payment_options.rb +7 -0
- data/lib/adapt/methods/pay.rb +68 -0
- data/lib/adapt/methods/payment_details.rb +7 -0
- data/lib/adapt/methods/preapproval.rb +39 -0
- data/lib/adapt/methods/preapproval_details.rb +7 -0
- data/lib/adapt/methods/refund.rb +7 -0
- data/lib/adapt/methods/set_payment_options.rb +33 -0
- data/lib/adapt/service.rb +83 -0
- metadata +209 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Tyler Hunt
|
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 PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL 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/lib/adapt.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'bigdecimal'
|
3
|
+
require 'patron'
|
4
|
+
|
5
|
+
module Adapt
|
6
|
+
VERSION = '56.0'.freeze
|
7
|
+
|
8
|
+
LIVE = 'https://svcs.paypal.com/AdaptivePayments'.freeze
|
9
|
+
SANDBOX = 'https://svcs.sandbox.paypal.com/AdaptivePayments'.freeze
|
10
|
+
BETA = 'https://svcs.beta-sandbox.paypal.com/AdaptivePayments'.freeze
|
11
|
+
|
12
|
+
autoload :Base, 'adapt/base'
|
13
|
+
autoload :Common, 'adapt/common'
|
14
|
+
autoload :Methods, 'adapt/methods'
|
15
|
+
autoload :Service, 'adapt/service'
|
16
|
+
end
|
data/lib/adapt/base.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module Adapt
|
4
|
+
class Base
|
5
|
+
include ActiveModel::Validations
|
6
|
+
|
7
|
+
class_inheritable_array :properties
|
8
|
+
self.properties ||= []
|
9
|
+
|
10
|
+
def self.property(name, options={}, &block)
|
11
|
+
unless default = options.delete(:default)
|
12
|
+
attr_reader(name)
|
13
|
+
else
|
14
|
+
define_method(name) do
|
15
|
+
unless instance_variable_defined?(:"@#{name}")
|
16
|
+
send(:"#{name}=", default)
|
17
|
+
end
|
18
|
+
|
19
|
+
instance_variable_get(:"@#{name}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
type = if block_given?
|
24
|
+
const_set(
|
25
|
+
name.to_s.classify,
|
26
|
+
Class.new(Base).tap { |base| base.class_eval(&block) }
|
27
|
+
)
|
28
|
+
else
|
29
|
+
options.delete(:type)
|
30
|
+
end
|
31
|
+
|
32
|
+
unless type
|
33
|
+
attr_writer(name)
|
34
|
+
else
|
35
|
+
collection = options.delete(:collection) || type.is_a?(Array)
|
36
|
+
type = type.first if type.is_a?(Array)
|
37
|
+
|
38
|
+
define_method(:"#{name}=") do |value|
|
39
|
+
value = unless collection
|
40
|
+
type.new(value)
|
41
|
+
else
|
42
|
+
value.collect { |attributes| attributes.is_a?(Hash) ? type.new(attributes) : attributes }
|
43
|
+
end
|
44
|
+
|
45
|
+
instance_variable_set(:"@#{name}", value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
validates(name, options) if options.any?
|
50
|
+
properties << name unless properties.include?(name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize(attributes={})
|
54
|
+
self.attributes = attributes
|
55
|
+
end
|
56
|
+
|
57
|
+
def attributes
|
58
|
+
attributes = properties.each_with_object({}) do |name, attributes|
|
59
|
+
value = send(name)
|
60
|
+
attributes[name] = value unless value.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
encode_keys(attributes)
|
64
|
+
end
|
65
|
+
|
66
|
+
def attributes=(attributes)
|
67
|
+
attributes.each do |key, value|
|
68
|
+
send(:"#{decode_key(key)}=", value)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_json
|
73
|
+
ActiveSupport::JSON.encode(attributes)
|
74
|
+
end
|
75
|
+
|
76
|
+
def from_json(json)
|
77
|
+
self.attributes = ActiveSupport::JSON.decode(json)
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
def encode_keys(object)
|
82
|
+
case object
|
83
|
+
when Array then object.collect { |value| encode_keys(value) }
|
84
|
+
when Hash then Hash[object.collect { |key, value| [encode_key(key), encode_keys(value)] }]
|
85
|
+
when Base then encode_keys(object.attributes)
|
86
|
+
else object
|
87
|
+
end
|
88
|
+
end
|
89
|
+
private :encode_keys
|
90
|
+
|
91
|
+
def encode_key(key)
|
92
|
+
key.is_a?(Symbol) ? key.to_s.camelcase(:lower) : key
|
93
|
+
end
|
94
|
+
private :encode_key
|
95
|
+
|
96
|
+
def decode_key(key)
|
97
|
+
key.is_a?(Symbol) ? key : key.underscore.to_sym
|
98
|
+
end
|
99
|
+
private :decode_key
|
100
|
+
end
|
101
|
+
end
|
data/lib/adapt/common.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Common
|
3
|
+
autoload :ClientDetails, 'adapt/common/client_details'
|
4
|
+
autoload :ErrorData, 'adapt/common/error_data'
|
5
|
+
autoload :ErrorParameter, 'adapt/common/error_parameter'
|
6
|
+
autoload :FaultMessage, 'adapt/common/fault_message'
|
7
|
+
autoload :PhoneNumberType, 'adapt/common/phone_number_type'
|
8
|
+
autoload :Receiver, 'adapt/common/receiver'
|
9
|
+
autoload :ReceiverList, 'adapt/common/receiver_list'
|
10
|
+
autoload :RequestEnvelope, 'adapt/common/request_envelope'
|
11
|
+
autoload :ResponseEnvelope, 'adapt/common/response_envelope'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Common
|
3
|
+
class ClientDetails < Base
|
4
|
+
property :application_id, :presence => true
|
5
|
+
property :customer_id, :presence => true
|
6
|
+
property :customer_type, :presence => true
|
7
|
+
property :device_id
|
8
|
+
property :geo_location, :presence => true
|
9
|
+
property :ip_address, :presence => true
|
10
|
+
property :model, :presence => true
|
11
|
+
property :partner_name, :presence => true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Common
|
3
|
+
class ErrorData < Base
|
4
|
+
SEVERITIES = %w(Error Warning).freeze
|
5
|
+
|
6
|
+
property :category
|
7
|
+
property :domain
|
8
|
+
property :error_id
|
9
|
+
property :exception_id
|
10
|
+
property :message
|
11
|
+
property :parameter
|
12
|
+
property :severity, :inclusion => { :in => SEVERITIES }
|
13
|
+
property :subdomain
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Common
|
3
|
+
class Receiver < Base
|
4
|
+
PAYMENT_TYPES = %w(GOODS SERVICE PERSONAL CASHADVANCE).freeze
|
5
|
+
|
6
|
+
property :amount, :presence => true
|
7
|
+
property :email
|
8
|
+
property :invoice_id
|
9
|
+
property :payment_type, :inclusion => { :in => PAYMENT_TYPES }
|
10
|
+
property :phone, :type => Common::PhoneNumberType
|
11
|
+
property :primary, :default => false, :inclusion => { :in => [true, false] }, :presence => true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Methods
|
3
|
+
autoload :CancelPreapproval, 'adapt/methods/cancel_preapproval'
|
4
|
+
autoload :ConvertCurrency, 'adapt/methods/convert_currency'
|
5
|
+
autoload :ExecutePayment, 'adapt/methods/execute_payment'
|
6
|
+
autoload :GetPaymentOptions, 'adapt/methods/get_payment_options'
|
7
|
+
autoload :Pay, 'adapt/methods/pay'
|
8
|
+
autoload :PaymentDetails, 'adapt/methods/payment_details'
|
9
|
+
autoload :Preapproval, 'adapt/methods/preapproval'
|
10
|
+
autoload :PreapprovalDetails, 'adapt/methods/preapproval_details'
|
11
|
+
autoload :Refund, 'adapt/methods/refund'
|
12
|
+
autoload :SetPaymentOptions, 'adapt/methods/set_payment_options'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Methods
|
3
|
+
# Obtains Foreign Exchange currency conversion rates for a list of amounts
|
4
|
+
class ConvertCurrency < Base
|
5
|
+
CURRENCY_CODES = %w(AUD BRL CAD CZK DKK EUR HKD HUF ILS JPY MYR MXN NOK NZD PHP PLN GBP SGD SEK CHF TWD THB USD).freeze
|
6
|
+
|
7
|
+
class CurrencyType < Base
|
8
|
+
property :amount, :presence => true
|
9
|
+
property :code, :presence => true, :inclusion => { :in => CURRENCY_CODES }
|
10
|
+
end
|
11
|
+
|
12
|
+
class Request < Base
|
13
|
+
property :base_amount_list, :collection => true do
|
14
|
+
property :currency, :type => CurrencyType
|
15
|
+
end
|
16
|
+
|
17
|
+
property :convert_to_currency_list, :collection => true do
|
18
|
+
property :currency_code, :presence => true, :inclusion => { :in => CURRENCY_CODES }
|
19
|
+
end
|
20
|
+
|
21
|
+
property :request_envelope, :type => Common::RequestEnvelope
|
22
|
+
end
|
23
|
+
|
24
|
+
class Response < Base
|
25
|
+
property :estimated_amount_table do
|
26
|
+
property :currency_conversion_list, :collection => true do
|
27
|
+
property :base_amount, :type => CurrencyType
|
28
|
+
|
29
|
+
property :currency_list do
|
30
|
+
property :currency, :type => [CurrencyType]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
property :response_envelope, :type => Common::ResponseEnvelope
|
36
|
+
property :error, :type => [Common::ErrorData]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Methods
|
3
|
+
# Transfers funds from a sender's PayPal account to one or more receivers’
|
4
|
+
# PayPal accounts (up to 6 receivers)
|
5
|
+
#
|
6
|
+
# Redirect the user to the following URL for approval:
|
7
|
+
# "https://www.paypal.com/webscr?cmd=_ap-payment&paykey=#{response.pay_key}"
|
8
|
+
class Pay
|
9
|
+
ACTION_TYPES = %w(PAY CREATE PAY_PRIMARY).freeze
|
10
|
+
CURRENCY_CODES = %w(AUD BRL CAD CZK DKK EUR HKD HUF ILS JPY MYR MXN NOK NZD PHP PLN GBP SGD SEK CHF TWD THB USD).freeze
|
11
|
+
FEES_PAYERS = %w(SENDER PRIMARYRECEIVER EACHRECEIVER SECONDARYONLY).freeze
|
12
|
+
PAYMENT_PERIODS = %w(NO_PERIOD_SPECIFIED DAILY WEEKLY BIWEEKLY SEMIMONTHLY MONTHLY ANNUALLY).freeze
|
13
|
+
PIN_TYPES = %w(NOT_REQUIRED REQUIRED).freeze
|
14
|
+
WEEK_DAYS = %w(NO_DAY_SPECIFIED SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY).freeze
|
15
|
+
FUNDING_TYPES = %w(ECHECK BALANCE CREDITCARD)
|
16
|
+
|
17
|
+
class Request < Base
|
18
|
+
property :action_type, :inclusion => { :in => ACTION_TYPES }, :presence => true
|
19
|
+
property :cancel_url, :presence => true
|
20
|
+
property :client_details
|
21
|
+
property :currency_code, :inclusion => { :in => CURRENCY_CODES }
|
22
|
+
property :date_of_month, :numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 31 }
|
23
|
+
property :day_of_week, :inclusion => { :in => WEEK_DAYS }
|
24
|
+
property :ending_date
|
25
|
+
property :ipn_notification_url
|
26
|
+
property :max_amount_per_payment
|
27
|
+
property :max_number_of_payments
|
28
|
+
property :max_number_of_payments_per_period
|
29
|
+
property :max_total_amount_of_all_payments
|
30
|
+
property :payment_period, :inclusion => { :in => PAYMENT_PERIODS }
|
31
|
+
property :pin_type, :inclusion => { :in => PIN_TYPES }
|
32
|
+
property :starting_date, :presence => true
|
33
|
+
property :fees_payer, :inclusion => { :in => FEES_PAYERS }
|
34
|
+
property :memo, :length => { :maximum => 1000 }
|
35
|
+
property :pin
|
36
|
+
property :preapproval_key
|
37
|
+
property :receiver_list, :type => Common::ReceiverList
|
38
|
+
property :request_envelope, :type => Common::RequestEnvelope, :presence => true
|
39
|
+
property :return_url, :presence => true
|
40
|
+
property :reverse_all_parallel_payments_on_error, :inclusion => { :in => [true, false] }
|
41
|
+
property :sender_email
|
42
|
+
property :tracking_id
|
43
|
+
|
44
|
+
property :funding_constraint, :collection => true do
|
45
|
+
property :allowed_funding_type do
|
46
|
+
property :funding_type_info do
|
47
|
+
property :funding_type, :presence => true, :inclusion => { :in => FUNDING_TYPES }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Response < Base
|
54
|
+
property :error, :type => Common::ErrorData, :collection => true
|
55
|
+
property :pay_key
|
56
|
+
property :payment_exec_status
|
57
|
+
property :response_envelope, :type => Common::ResponseEnvelope
|
58
|
+
|
59
|
+
property :pay_error_list do
|
60
|
+
property :pay_error, :collection => true do
|
61
|
+
property :error, :type => Common::ErrorData
|
62
|
+
property :receiver, :type => Common::Receiver
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Methods
|
3
|
+
# Sets up pre-approvals, which is an approval to make future payments on the
|
4
|
+
# sender's behalf
|
5
|
+
class Preapproval < Base
|
6
|
+
CURRENCY_CODES = %w(AUD BRL CAD CZK DKK EUR HKD HUF ILS JPY MYR MXN NOK NZD PHP PLN GBP SGD SEK CHF TWD THB USD).freeze
|
7
|
+
DAYS_OF_WEEK = %w(NO_DAY_SPECIFIED SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAR FRIDAY SATURDAY).freeze
|
8
|
+
PAYMENT_PERIODS = %w(NO_PERIOD_SPECIFIED DAILY WEEKLY BIWEEKLY SEMIMONTHLY MONTHLY ANNUALLY).freeze
|
9
|
+
PIN_TYPES = %w(NOT_REQUIRED REQUIRED).freeze
|
10
|
+
|
11
|
+
class Request < Base
|
12
|
+
property :cancel_url, :presence => true
|
13
|
+
property :client_details, :type => Common::ClientDetails
|
14
|
+
property :currency_code, :presence => true, :inclusion => { :in => CURRENCY_CODES }
|
15
|
+
property :date_of_month, :numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 31 }
|
16
|
+
property :day_of_week, :inclusion => { :in => DAYS_OF_WEEK }
|
17
|
+
property :ending_date, :presence => true
|
18
|
+
property :ipn_notificaiton_url
|
19
|
+
property :max_amount_per_payment, :numericality => true
|
20
|
+
property :max_number_of_payments, :numericality => { :integer_only => true }
|
21
|
+
property :max_number_of_payments_per_period, :numericality => { :integer_only => true }
|
22
|
+
property :max_total_amount_of_all_payments, :presence => true, :numericality => true
|
23
|
+
property :memo
|
24
|
+
property :payment_period, :inclusion => { :in => PAYMENT_PERIODS }
|
25
|
+
property :pin_type, :inclusion => { :in => PIN_TYPES }
|
26
|
+
property :request_envelope, :type => Common::RequestEnvelope, :presence => true
|
27
|
+
property :return_url, :presence => true
|
28
|
+
property :sender_email
|
29
|
+
property :starting_date, :presence => true
|
30
|
+
end
|
31
|
+
|
32
|
+
class Response < Base
|
33
|
+
property :preapproval_key
|
34
|
+
property :response_envelope, :type => Common::ResponseEnvelope
|
35
|
+
property :error, :type => [Common::ErrorData]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Adapt
|
2
|
+
module Methods
|
3
|
+
# Sets payment options
|
4
|
+
class SetPaymentOptions
|
5
|
+
class Request < Base
|
6
|
+
property :pay_key, :presence => true
|
7
|
+
property :request_envelope, :type => Common::RequestEnvelope, :presence => true
|
8
|
+
|
9
|
+
property :initiating_entity do
|
10
|
+
property :institution_customer do
|
11
|
+
property :country_code, :presence => true
|
12
|
+
property :display_name, :presence => true
|
13
|
+
property :email
|
14
|
+
property :first_name, :presence => true
|
15
|
+
property :institution_customer_id, :presence => true
|
16
|
+
property :institution_id, :presence => true
|
17
|
+
property :last_name, :presence => true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
property :display_options do
|
22
|
+
property :email_header_image_url
|
23
|
+
property :email_marketing_image_url
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Response < Base
|
28
|
+
property :response_envelope, :type => Common::ResponseEnvelope
|
29
|
+
property :error, :type => [Common::ErrorData]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
3
|
+
module Adapt
|
4
|
+
class Service
|
5
|
+
METHODS = %w[
|
6
|
+
CancelPreapproval
|
7
|
+
ConvertCurrency
|
8
|
+
ExecutePayment
|
9
|
+
GetPaymentOptions
|
10
|
+
Pay
|
11
|
+
PaymentDetails
|
12
|
+
Preapproval
|
13
|
+
PreapprovalDetails
|
14
|
+
Refund
|
15
|
+
SetPaymentOptions
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
attr_reader :credentials
|
19
|
+
attr_accessor :environment
|
20
|
+
|
21
|
+
def initialize(credentials)
|
22
|
+
@credentials = credentials
|
23
|
+
@environment = :sandbox
|
24
|
+
end
|
25
|
+
|
26
|
+
def defaults
|
27
|
+
{
|
28
|
+
:request_format => 'JSON',
|
29
|
+
:response_format => 'JSON'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def headers
|
34
|
+
{
|
35
|
+
'X-PAYPAL-SECURITY-USERID' => credentials[:username],
|
36
|
+
'X-PAYPAL-SECURITY-PASSWORD' => credentials[:password],
|
37
|
+
'X-PAYPAL-SECURITY-SIGNATURE' => credentials[:signature],
|
38
|
+
'X-PAYPAL-DEVICE-IPADDRESS' => credentials[:ip],
|
39
|
+
'X-PAYPAL-REQUEST-DATA-FORMAT' => defaults[:request_format],
|
40
|
+
'X-PAYPAL-RESPONSE-DATA-FORMAT' => defaults[:response_format],
|
41
|
+
'X-PAYPAL-APPLICATION-ID' => credentials[:application_id]
|
42
|
+
}.tap do |parameters|
|
43
|
+
if credentials[:subject]
|
44
|
+
parameters['X-PAYPAL-SUBJECT'] = credentials[:subject]
|
45
|
+
end
|
46
|
+
|
47
|
+
if credentials[:device]
|
48
|
+
parameters['X-PAYPAL-DEVICE-ID'] = credentials[:device]
|
49
|
+
end
|
50
|
+
|
51
|
+
if credentials[:version]
|
52
|
+
parameters['X-PAYPAL-SERVICE-VERSION'] = credentials[:version]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def endpoint(method)
|
58
|
+
if METHODS.include?(method)
|
59
|
+
root = case environment
|
60
|
+
when :live then LIVE
|
61
|
+
when :beta then BETA
|
62
|
+
else SANDBOX
|
63
|
+
end
|
64
|
+
|
65
|
+
URI.parse([root, method].join('/'))
|
66
|
+
else
|
67
|
+
raise ArgumentError.new("Invalid method: #{method}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def request(method, request={})
|
72
|
+
uri = endpoint(method)
|
73
|
+
|
74
|
+
session = Patron::Session.new.tap do |session|
|
75
|
+
session.timeout = 10
|
76
|
+
session.insecure = true
|
77
|
+
session.base_url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
|
78
|
+
end
|
79
|
+
|
80
|
+
session.post(uri.path, request.to_json, headers)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adapt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Tyler Hunt
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-19 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activemodel
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 3.0.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: patron
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 4
|
46
|
+
- 6
|
47
|
+
version: 0.4.6
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: tzinfo
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - "="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 3
|
61
|
+
- 22
|
62
|
+
version: 0.3.22
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: remarkable_activemodel
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - "="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 4
|
75
|
+
- 0
|
76
|
+
- 0
|
77
|
+
- alpha4
|
78
|
+
version: 4.0.0.alpha4
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - "="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 2
|
91
|
+
- 0
|
92
|
+
- 0
|
93
|
+
- beta
|
94
|
+
- 15
|
95
|
+
version: 2.0.0.beta.15
|
96
|
+
type: :development
|
97
|
+
version_requirements: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: sinatra
|
100
|
+
prerelease: false
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - "="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
segments:
|
107
|
+
- 1
|
108
|
+
- 0
|
109
|
+
version: "1.0"
|
110
|
+
type: :development
|
111
|
+
version_requirements: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: vcr
|
114
|
+
prerelease: false
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - "="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 1
|
122
|
+
- 0
|
123
|
+
- 2
|
124
|
+
version: 1.0.2
|
125
|
+
type: :development
|
126
|
+
version_requirements: *id007
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: webmock
|
129
|
+
prerelease: false
|
130
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - "="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
segments:
|
136
|
+
- 1
|
137
|
+
- 3
|
138
|
+
- 0
|
139
|
+
version: 1.3.0
|
140
|
+
type: :development
|
141
|
+
version_requirements: *id008
|
142
|
+
description:
|
143
|
+
email:
|
144
|
+
executables: []
|
145
|
+
|
146
|
+
extensions: []
|
147
|
+
|
148
|
+
extra_rdoc_files: []
|
149
|
+
|
150
|
+
files:
|
151
|
+
- LICENSE
|
152
|
+
- lib/adapt/base.rb
|
153
|
+
- lib/adapt/common/client_details.rb
|
154
|
+
- lib/adapt/common/error_data.rb
|
155
|
+
- lib/adapt/common/error_parameter.rb
|
156
|
+
- lib/adapt/common/fault_message.rb
|
157
|
+
- lib/adapt/common/phone_number_type.rb
|
158
|
+
- lib/adapt/common/receiver.rb
|
159
|
+
- lib/adapt/common/receiver_list.rb
|
160
|
+
- lib/adapt/common/request_envelope.rb
|
161
|
+
- lib/adapt/common/response_envelope.rb
|
162
|
+
- lib/adapt/common.rb
|
163
|
+
- lib/adapt/methods/cancel_preapproval.rb
|
164
|
+
- lib/adapt/methods/convert_currency.rb
|
165
|
+
- lib/adapt/methods/execute_payment.rb
|
166
|
+
- lib/adapt/methods/get_payment_options.rb
|
167
|
+
- lib/adapt/methods/pay.rb
|
168
|
+
- lib/adapt/methods/payment_details.rb
|
169
|
+
- lib/adapt/methods/preapproval.rb
|
170
|
+
- lib/adapt/methods/preapproval_details.rb
|
171
|
+
- lib/adapt/methods/refund.rb
|
172
|
+
- lib/adapt/methods/set_payment_options.rb
|
173
|
+
- lib/adapt/methods.rb
|
174
|
+
- lib/adapt/service.rb
|
175
|
+
- lib/adapt.rb
|
176
|
+
has_rdoc: true
|
177
|
+
homepage: http://github.com/tylerhunt/adapt
|
178
|
+
licenses: []
|
179
|
+
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
segments:
|
191
|
+
- 0
|
192
|
+
version: "0"
|
193
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
segments:
|
199
|
+
- 0
|
200
|
+
version: "0"
|
201
|
+
requirements: []
|
202
|
+
|
203
|
+
rubyforge_project:
|
204
|
+
rubygems_version: 1.3.7
|
205
|
+
signing_key:
|
206
|
+
specification_version: 3
|
207
|
+
summary: An interface library for the PayPal Adaptive Payments service.
|
208
|
+
test_files: []
|
209
|
+
|