express-checkout 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ module Express
2
+ module Payment
3
+ class Recurring::Summary < Base
4
+ attr_optional :next_billing_date, :cycles_completed, :cycles_remaining, :outstanding_balance, :failed_count, :last_payment_date, :last_payment_amount
5
+
6
+ def numeric_attribute?(key)
7
+ super || [:outstanding_balance, :failed_count].include?(key)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,67 @@
1
+ module Express
2
+ module Payment
3
+ class Request < Base
4
+ attr_optional :action, :currency_code, :description, :notify_url, :billing_type, :billing_agreement_description, :billing_agreement_id, :request_id, :seller_id, :invoice_number, :custom
5
+ attr_accessor :amount, :items, :custom_fields
6
+
7
+ def initialize(attributes = {})
8
+ @amount = if attributes[:amount].is_a?(Common::Amount)
9
+ attributes[:amount]
10
+ else
11
+ Common::Amount.new(
12
+ :total => attributes[:amount],
13
+ :tax => attributes[:tax_amount],
14
+ :shipping => attributes[:shipping_amount]
15
+ )
16
+ end
17
+ @items = []
18
+ Array(attributes[:items]).each do |item_attrs|
19
+ @items << Item.new(item_attrs)
20
+ end
21
+ @custom_fields = attributes[:custom_fields] || {}
22
+ super
23
+ end
24
+
25
+ def to_params(index = 0)
26
+ params = {
27
+ :"PAYMENTREQUEST_#{index}_PAYMENTACTION" => self.action,
28
+ :"PAYMENTREQUEST_#{index}_AMT" => Util.formatted_amount(self.amount.total),
29
+ :"PAYMENTREQUEST_#{index}_TAXAMT" => Util.formatted_amount(self.amount.tax),
30
+ :"PAYMENTREQUEST_#{index}_SHIPPINGAMT" => Util.formatted_amount(self.amount.shipping),
31
+ :"PAYMENTREQUEST_#{index}_CURRENCYCODE" => self.currency_code,
32
+ :"PAYMENTREQUEST_#{index}_DESC" => self.description,
33
+ :"PAYMENTREQUEST_#{index}_INVNUM" => self.invoice_number,
34
+ :"PAYMENTREQUEST_#{index}_CUSTOM" => self.custom,
35
+ # NOTE:
36
+ # notify_url works only when DoExpressCheckoutPayment called.
37
+ # recurring payment doesn't support dynamic notify_url.
38
+ :"PAYMENTREQUEST_#{index}_NOTIFYURL" => self.notify_url,
39
+ :"L_BILLINGTYPE#{index}" => self.billing_type,
40
+ :"L_BILLINGAGREEMENTDESCRIPTION#{index}" => self.billing_agreement_description,
41
+ # FOR PARALLEL PAYMENT
42
+ :"PAYMENTREQUEST_#{index}_PAYMENTREQUESTID" => self.request_id,
43
+ :"PAYMENTREQUEST_#{index}_SELLERPAYPALACCOUNTID" => self.seller_id
44
+ }.delete_if do |k, v|
45
+ v.blank?
46
+ end
47
+ if self.items.present?
48
+ params[:"PAYMENTREQUEST_#{index}_ITEMAMT"] = Util.formatted_amount(self.items_amount)
49
+ self.items.each_with_index do |item, item_index|
50
+ params.merge! item.to_params(index, item_index)
51
+ end
52
+ end
53
+ self.custom_fields.each do |key, value|
54
+ field = key.to_s.upcase.gsub("{N}", index.to_s).to_sym
55
+ params[field] = value
56
+ end
57
+ params
58
+ end
59
+
60
+ def items_amount
61
+ self.items.sum do |item|
62
+ item.quantity * BigDecimal.new(item.amount.to_s)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,26 @@
1
+ module Express
2
+ module Payment
3
+ class Request::Item < Base
4
+ attr_optional :name, :description, :amount, :number, :quantity, :category, :url
5
+
6
+ def initialize(attributes = {})
7
+ super
8
+ @quantity ||= 1
9
+ end
10
+
11
+ def to_params(parent_index, index = 0)
12
+ {
13
+ :"L_PAYMENTREQUEST_#{parent_index}_NAME#{index}" => self.name,
14
+ :"L_PAYMENTREQUEST_#{parent_index}_DESC#{index}" => self.description,
15
+ :"L_PAYMENTREQUEST_#{parent_index}_AMT#{index}" => Util.formatted_amount(self.amount),
16
+ :"L_PAYMENTREQUEST_#{parent_index}_NUMBER#{index}" => self.number,
17
+ :"L_PAYMENTREQUEST_#{parent_index}_QTY#{index}" => self.quantity,
18
+ :"L_PAYMENTREQUEST_#{parent_index}_ITEMCATEGORY#{index}" => self.category,
19
+ :"L_PAYMENTREQUEST_#{parent_index}_ITEMURL#{index}" => self.url
20
+ }.delete_if do |k, v|
21
+ v.blank?
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,73 @@
1
+ module Express
2
+ module Payment
3
+ class Response < Base
4
+ attr_accessor :amount, :ship_to, :bill_to, :description, :note, :items, :notify_url, :insurance_option_offered, :currency_code, :short_message, :long_message, :error_code, :severity_code, :ack, :transaction_id, :billing_agreement_id, :request_id, :seller_id
5
+
6
+ def initialize(attributes = {})
7
+ attrs = attributes.dup
8
+ @amount = Common::Amount.new(
9
+ :total => attrs.delete(:AMT),
10
+ :item => attrs.delete(:ITEMAMT),
11
+ :handing => attrs.delete(:HANDLINGAMT),
12
+ :insurance => attrs.delete(:INSURANCEAMT),
13
+ :ship_disc => attrs.delete(:SHIPDISCAMT),
14
+ :shipping => attrs.delete(:SHIPPINGAMT),
15
+ :tax => attrs.delete(:TAXAMT)
16
+ )
17
+ @ship_to = Payment::Response::Address.new(
18
+ :name => attrs.delete(:SHIPTONAME),
19
+ :zip => attrs.delete(:SHIPTOZIP),
20
+ :street => attrs.delete(:SHIPTOSTREET),
21
+ :street2 => attrs.delete(:SHIPTOSTREET2),
22
+ :city => attrs.delete(:SHIPTOCITY),
23
+ :state => attrs.delete(:SHIPTOSTATE),
24
+ :country_code => attrs.delete(:SHIPTOCOUNTRYCODE),
25
+ :country_name => attrs.delete(:SHIPTOCOUNTRYNAME)
26
+ )
27
+ @bill_to = Payment::Response::Address.new(
28
+ :owner => attrs.delete(:ADDRESSID),
29
+ :status => attrs.delete(:ADDRESSSTATUS),
30
+ :name => attrs.delete(:BILLINGNAME),
31
+ :zip => attrs.delete(:ZIP),
32
+ :street => attrs.delete(:STREET),
33
+ :street2 => attrs.delete(:STREET2),
34
+ :city => attrs.delete(:CITY),
35
+ :state => attrs.delete(:STATE),
36
+ :country_code => attrs.delete(:COUNTRY)
37
+ )
38
+ @description = attrs.delete(:DESC)
39
+ @note = attrs.delete(:NOTETEXT)
40
+ @notify_url = attrs.delete(:NOTIFYURL)
41
+ @insurance_option_offered = attrs.delete(:INSURANCEOPTIONOFFERED) == 'true'
42
+ @currency_code = attrs.delete(:CURRENCYCODE)
43
+ @short_message = attrs.delete(:SHORTMESSAGE)
44
+ @long_message = attrs.delete(:LONGMESSAGE)
45
+ @error_code = attrs.delete(:ERRORCODE)
46
+ @severity_code = attrs.delete(:SEVERITYCODE)
47
+ @ack = attrs.delete(:ACK)
48
+ @transaction_id = attrs.delete(:TRANSACTIONID)
49
+ @billing_agreement_id = attrs.delete(:BILLINGAGREEMENTID)
50
+ @request_id = attrs.delete(:PAYMENTREQUESTID)
51
+ @seller_id = attrs.delete(:SELLERPAYPALACCOUNTID)
52
+
53
+ # items
54
+ items = []
55
+ attrs.keys.each do |_attr_|
56
+ key, index = _attr_.to_s.scan(/^(.+?)(\d+)$/).flatten
57
+ if index
58
+ items[index.to_i] ||= {}
59
+ items[index.to_i][key.to_sym] = attrs.delete(:"#{key}#{index}")
60
+ end
61
+ end
62
+ @items = items.collect do |_attr_|
63
+ Item.new(_attr_)
64
+ end
65
+
66
+ # warn ignored params
67
+ attrs.each do |key, value|
68
+ Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,7 @@
1
+ module Express
2
+ module Payment
3
+ class Response::Address < Base
4
+ attr_optional :owner, :status, :name, :zip, :street, :street2, :city, :state, :country_code, :country_name
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ module Express
2
+ module Payment
3
+ class Response::Info < Base
4
+ cattr_reader :attribute_mapping
5
+ @@attribute_mapping = {
6
+ :ACK => :ack,
7
+ :CURRENCYCODE => :currency_code,
8
+ :ERRORCODE => :error_code,
9
+ :ORDERTIME => :order_time,
10
+ :PAYMENTSTATUS => :payment_status,
11
+ :PAYMENTTYPE => :payment_type,
12
+ :PENDINGREASON => :pending_reason,
13
+ :PROTECTIONELIGIBILITY => :protection_eligibility,
14
+ :PROTECTIONELIGIBILITYTYPE => :protection_eligibility_type,
15
+ :REASONCODE => :reason_code,
16
+ :RECEIPTID => :receipt_id,
17
+ :SECUREMERCHANTACCOUNTID => :secure_merchant_account_id,
18
+ :TRANSACTIONID => :transaction_id,
19
+ :TRANSACTIONTYPE => :transaction_type,
20
+ :PAYMENTREQUESTID => :request_id,
21
+ :SELLERPAYPALACCOUNTID => :seller_id,
22
+ :EXCHANGERATE => :exchange_rate
23
+ }
24
+ attr_accessor *@@attribute_mapping.values
25
+ attr_accessor :amount
26
+
27
+ def initialize(attributes = {})
28
+ attrs = attributes.dup
29
+ @@attribute_mapping.each do |key, value|
30
+ self.send "#{value}=", attrs.delete(key)
31
+ end
32
+ @amount = Common::Amount.new(
33
+ :total => attrs.delete(:AMT),
34
+ :fee => attrs.delete(:FEEAMT),
35
+ :tax => attrs.delete(:TAXAMT)
36
+ )
37
+
38
+ # warn ignored params
39
+ attrs.each do |key, value|
40
+ Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ module Express
2
+ module Payment
3
+ class Response::Item < Base
4
+ cattr_reader :attribute_mapping
5
+ @@attribute_mapping = {
6
+ :NAME => :name,
7
+ :DESC => :description,
8
+ :QTY => :quantity,
9
+ :NUMBER => :number,
10
+ :ITEMCATEGORY => :category,
11
+ :ITEMWIDTHVALUE => :width,
12
+ :ITEMHEIGHTVALUE => :height,
13
+ :ITEMLENGTHVALUE => :length,
14
+ :ITEMWEIGHTVALUE => :weight,
15
+ :SHIPPINGAMT => :shipping,
16
+ :HANDLINGAMT => :handling,
17
+ :CURRENCYCODE => :currency
18
+
19
+ }
20
+ attr_accessor *@@attribute_mapping.values
21
+ attr_accessor :amount
22
+
23
+ def initialize(attributes = {})
24
+ attrs = attributes.dup
25
+ @@attribute_mapping.each do |key, value|
26
+ self.send "#{value}=", attrs.delete(key)
27
+ end
28
+ @quantity = @quantity.to_i
29
+ @amount = Common::Amount.new(
30
+ :total => attrs.delete(:AMT),
31
+ :tax => attrs.delete(:TAXAMT)
32
+ )
33
+
34
+ # warn ignored params
35
+ attrs.each do |key, value|
36
+ Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ module Express
2
+ module Payment
3
+ class Response::Payer < Base
4
+ attr_optional :identifier, :status, :first_name, :last_name, :email, :company
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Express
2
+ module Payment
3
+ class Response::Reference < Base
4
+ attr_required :identifier
5
+ attr_optional :description, :status
6
+ attr_accessor :info
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Express
2
+ module Payment
3
+ class Response::Refund < Base
4
+ attr_optional :transaction_id
5
+ attr_accessor :amount
6
+
7
+ def initialize(attributes = {})
8
+ super
9
+ @amount = Common::Amount.new(attributes[:amount])
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Express
2
+ module Util
3
+ def self.formatted_amount(x)
4
+ # Thanks @nahi ;)
5
+ sprintf "%0.2f", BigDecimal.new(x.to_s).truncate(2)
6
+ end
7
+
8
+ def self.to_numeric(x)
9
+ if x.to_f == x.to_i
10
+ x.to_i
11
+ else
12
+ x.to_f
13
+ end
14
+ end
15
+
16
+ def numeric_attribute?(key)
17
+ !!(key.to_s =~ /(amount|frequency|cycles|paid)/)
18
+ end
19
+
20
+ def ==(other)
21
+ instance_variables.all? do |key|
22
+ instance_variable_get(key) == other.instance_variable_get(key)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Express
2
+ VERSION = "0.0.2"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express-checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wei-Yi Chiu
@@ -10,6 +10,48 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: attr_required
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.5
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -28,16 +70,58 @@ dependencies:
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - ~>
73
+ - - '>='
32
74
  - !ruby/object:Gem::Version
33
- version: '10.0'
75
+ version: '0.8'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - ~>
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - <
102
+ - !ruby/object:Gem::Version
103
+ version: '2.99'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - <
109
+ - !ruby/object:Gem::Version
110
+ version: '2.99'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fakeweb
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
39
123
  - !ruby/object:Gem::Version
40
- version: '10.0'
124
+ version: 1.3.0
41
125
  description: papal express-checkout gem
42
126
  email:
43
127
  - bird1204@gmail.com
@@ -55,8 +139,33 @@ files:
55
139
  - bin/console
56
140
  - bin/setup
57
141
  - express-checkout.gemspec
142
+ - lib/express.rb
143
+ - lib/express/base.rb
58
144
  - lib/express/checkout.rb
59
- - lib/express/checkout/version.rb
145
+ - lib/express/checkout/request.rb
146
+ - lib/express/checkout/response.rb
147
+ - lib/express/exception.rb
148
+ - lib/express/exception/api_error.rb
149
+ - lib/express/exception/http_error.rb
150
+ - lib/express/ipn.rb
151
+ - lib/express/nvp/request.rb
152
+ - lib/express/nvp/response.rb
153
+ - lib/express/payment/common/amount.rb
154
+ - lib/express/payment/recurring.rb
155
+ - lib/express/payment/recurring/activation.rb
156
+ - lib/express/payment/recurring/billing.rb
157
+ - lib/express/payment/recurring/summary.rb
158
+ - lib/express/payment/request.rb
159
+ - lib/express/payment/request/item.rb
160
+ - lib/express/payment/response.rb
161
+ - lib/express/payment/response/address.rb
162
+ - lib/express/payment/response/info.rb
163
+ - lib/express/payment/response/item.rb
164
+ - lib/express/payment/response/payer.rb
165
+ - lib/express/payment/response/reference.rb
166
+ - lib/express/payment/response/refund.rb
167
+ - lib/express/util.rb
168
+ - lib/express/version.rb
60
169
  homepage: https://github.com/bird1204
61
170
  licenses:
62
171
  - MIT