paypal-express 0.2.3 → 0.2.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/lib/paypal.rb CHANGED
@@ -71,6 +71,7 @@ require 'paypal/payment/request'
71
71
  require 'paypal/payment/request/item'
72
72
  require 'paypal/payment/response'
73
73
  require 'paypal/payment/response/info'
74
+ require 'paypal/payment/response/item'
74
75
  require 'paypal/payment/response/payer'
75
76
  require 'paypal/payment/response/ship_to'
76
77
  require 'paypal/payment/recurring'
@@ -11,13 +11,15 @@ module Paypal
11
11
  :CORRELATIONID => :colleration_id,
12
12
  :COUNTRYCODE => :country_code,
13
13
  :CURRENCYCODE => :currency_code,
14
+ :DESC => :description,
14
15
  :TIMESTAMP => :timestamp,
15
16
  :TOKEN => :token,
17
+ :NOTIFYURL => :notify_url,
16
18
  :VERSION => :version
17
19
  }
18
20
  attr_accessor *@@attribute_mapping.values
19
21
  attr_accessor :shipping_options_is_default, :success_page_redirect_requested, :insurance_option_selected
20
- attr_accessor :amount, :ship_to, :payer, :recurring, :payment_responses, :payment_info
22
+ attr_accessor :amount, :description, :ship_to, :payer, :recurring, :payment_responses, :payment_info, :items
21
23
 
22
24
  def initialize(attributes = {})
23
25
  attrs = attributes.dup
@@ -29,6 +31,7 @@ module Paypal
29
31
  @insurance_option_selected = attrs.delete(:INSURANCEOPTIONSELECTED) == 'true'
30
32
  @amount = Payment::Common::Amount.new(
31
33
  :total => attrs.delete(:AMT),
34
+ :item => attrs.delete(:ITEMAMT),
32
35
  :handing => attrs.delete(:HANDLINGAMT),
33
36
  :insurance => attrs.delete(:INSURANCEAMT),
34
37
  :ship_disc => attrs.delete(:SHIPDISCAMT),
@@ -61,7 +64,7 @@ module Paypal
61
64
  # NOTE:
62
65
  # CreateRecurringPaymentsProfile returns PROFILESTATUS
63
66
  # GetRecurringPaymentsProfileDetails returns STATUS
64
- :description => attrs.delete(:DESC),
67
+ :description => @description,
65
68
  :status => attrs.delete(:STATUS) || attrs.delete(:PROFILESTATUS),
66
69
  :start_date => attrs.delete(:PROFILESTARTDATE),
67
70
  :name => attrs.delete(:SUBSCRIBERNAME),
@@ -107,12 +110,16 @@ module Paypal
107
110
 
108
111
  # payment_responses
109
112
  payment_responses = []
110
- attrs.keys.each do |attribute|
111
- prefix, index, key = attribute.to_s.split('_')
112
- case prefix
113
- when 'PAYMENTREQUEST', 'PAYMENTREQUESTINFO'
113
+ attrs.keys.each do |_attr_|
114
+ prefix, index, key = case _attr_.to_s
115
+ when /^PAYMENTREQUEST/, /^PAYMENTREQUESTINFO/
116
+ _attr_.to_s.split('_')
117
+ when /^L_PAYMENTREQUEST/
118
+ _attr_.to_s.split('_')[1..-1]
119
+ end
120
+ if prefix
114
121
  payment_responses[index.to_i] ||= {}
115
- payment_responses[index.to_i][key.to_sym] = attrs.delete(attribute)
122
+ payment_responses[index.to_i][key.to_sym] ||= attrs.delete(_attr_)
116
123
  end
117
124
  end
118
125
  @payment_responses = payment_responses.collect do |_attrs_|
@@ -132,6 +139,19 @@ module Paypal
132
139
  Payment::Response::Info.new _attrs_
133
140
  end
134
141
 
142
+ # payment_info
143
+ items = []
144
+ attrs.keys.each do |_attr_|
145
+ key, index = _attr_.to_s.scan(/^L_(.+)(\d)$/).flatten
146
+ if index
147
+ items[index.to_i] ||= {}
148
+ items[index.to_i][key.to_sym] = attrs.delete(_attr_)
149
+ end
150
+ end
151
+ @items = items.collect do |_attrs_|
152
+ Payment::Response::Item.new _attrs_
153
+ end
154
+
135
155
  # remove duplicated parameters
136
156
  attrs.delete(:SHIPTOCOUNTRY) # NOTE: Same with SHIPTOCOUNTRYCODE
137
157
 
@@ -142,4 +162,4 @@ module Paypal
142
162
  end
143
163
  end
144
164
  end
145
- end
165
+ end
@@ -2,7 +2,7 @@ module Paypal
2
2
  module Payment
3
3
  module Common
4
4
  class Amount < Base
5
- attr_optional :total, :fee, :handing, :insurance, :ship_disc, :shipping, :tax
5
+ attr_optional :total, :item, :fee, :handing, :insurance, :ship_disc, :shipping, :tax
6
6
 
7
7
  def numeric_attribute?(key)
8
8
  true
@@ -1,12 +1,13 @@
1
1
  module Paypal
2
2
  module Payment
3
3
  class Response < Base
4
- attr_accessor :amount, :ship_to, :insurance_option_offered, :currency_code, :error_code
4
+ attr_accessor :amount, :ship_to, :description, :items, :notify_url, :insurance_option_offered, :currency_code, :error_code
5
5
 
6
6
  def initialize(attributes = {})
7
7
  attrs = attributes.dup
8
8
  @amount = Common::Amount.new(
9
9
  :total => attrs.delete(:AMT),
10
+ :item => attrs.delete(:ITEMAMT),
10
11
  :handing => attrs.delete(:HANDLINGAMT),
11
12
  :insurance => attrs.delete(:INSURANCEAMT),
12
13
  :ship_disc => attrs.delete(:SHIPDISCAMT),
@@ -22,10 +23,25 @@ module Paypal
22
23
  :country_code => attrs.delete(:SHIPTOCOUNTRYCODE),
23
24
  :country_name => attrs.delete(:SHIPTOCOUNTRYNAME)
24
25
  )
26
+ @description = attrs.delete(:DESC)
27
+ @notify_url = attrs.delete(:NOTIFYURL)
25
28
  @insurance_option_offered = attrs.delete(:INSURANCEOPTIONOFFERED) == 'true'
26
29
  @currency_code = attrs.delete(:CURRENCYCODE)
27
30
  @error_code = attrs.delete(:ERRORCODE)
28
31
 
32
+ # items
33
+ items = []
34
+ attrs.keys.each do |_attr_|
35
+ key, index = _attr_.to_s.scan(/^(.+)(\d)$/).flatten
36
+ if index
37
+ items[index.to_i] ||= {}
38
+ items[index.to_i][key.to_sym] = attrs.delete(:"#{key}#{index}")
39
+ end
40
+ end
41
+ @items = items.collect do |_attr_|
42
+ Item.new(_attr_)
43
+ end
44
+
29
45
  # warn ignored params
30
46
  attrs.each do |key, value|
31
47
  Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
@@ -0,0 +1,36 @@
1
+ module Paypal
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
+ :ITEMCATEGORY => :category,
10
+ :ITEMWIDTHVALUE => :width,
11
+ :ITEMHEIGHTVALUE => :height,
12
+ :ITEMLENGTHVALUE => :length,
13
+ :ITEMWEIGHTVALUE => :weight
14
+ }
15
+ attr_accessor *@@attribute_mapping.values
16
+ attr_accessor :amount
17
+
18
+ def initialize(attributes = {})
19
+ attrs = attributes.dup
20
+ @@attribute_mapping.each do |key, value|
21
+ self.send "#{value}=", attrs.delete(key)
22
+ end
23
+ @quantity = @quantity.to_i
24
+ @amount = Common::Amount.new(
25
+ :total => attrs.delete(:AMT),
26
+ :tax => attrs.delete(:TAXAMT)
27
+ )
28
+
29
+ # warn ignored params
30
+ attrs.each do |key, value|
31
+ Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1 +1 @@
1
- TOKEN=EC%2d99G324856K8277846&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2011%2d02%2d08T07%3a14%3a29Z&CORRELATIONID=e4e63a7a94b02&ACK=Success&VERSION=66%2e0&BUILD=1721431&EMAIL=valid_1296805890_per%40matake%2ejp&PAYERID=PRT3TZ6MCBCNC&PAYERSTATUS=verified&FIRSTNAME=Test&LASTNAME=User&COUNTRYCODE=US&SHIPTONAME=Test%20User&SHIPTOSTREET=1%20Main%20St&SHIPTOCITY=San%20Jose&SHIPTOSTATE=CA&SHIPTOZIP=95131&SHIPTOCOUNTRYCODE=US&SHIPTOCOUNTRYNAME=United%20States&ADDRESSSTATUS=Confirmed&CURRENCYCODE=USD&AMT=14%2e00&SHIPPINGAMT=0%2e00&HANDLINGAMT=0%2e00&TAXAMT=0%2e00&INSURANCEAMT=0%2e00&SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_AMT=14%2e00&PAYMENTREQUEST_0_SHIPPINGAMT=0%2e00&PAYMENTREQUEST_0_HANDLINGAMT=0%2e00&PAYMENTREQUEST_0_TAXAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEAMT=0%2e00&PAYMENTREQUEST_0_SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_SHIPTONAME=Test%20User&PAYMENTREQUEST_0_SHIPTOSTREET=1%20Main%20St&PAYMENTREQUEST_0_SHIPTOCITY=San%20Jose&PAYMENTREQUEST_0_SHIPTOSTATE=CA&PAYMENTREQUEST_0_SHIPTOZIP=95131&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US&PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME=United%20States&PAYMENTREQUESTINFO_0_ERRORCODE=0
1
+ TOKEN=EC%2d7HG122968U843864S&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2011%2d04%2d12T03%3a51%3a58Z&CORRELATIONID=6a0a92ea79ac3&ACK=Success&VERSION=69%2e0&BUILD=1824201&EMAIL=buyer_1297999636_per%40cerego%2ecom&PAYERID=9RWDTMRKKHQ8S&PAYERSTATUS=verified&FIRSTNAME=Test&LASTNAME=User&COUNTRYCODE=US&CURRENCYCODE=JPY&AMT=10&ITEMAMT=10&SHIPPINGAMT=0&HANDLINGAMT=0&TAXAMT=0&DESC=Instant%20Payment%20Request&NOTIFYURL=http%3a%2f%2fmerchant%2eexample%2ecom%2fnotify&INSURANCEAMT=0&SHIPDISCAMT=0&L_NAME0=Item1&L_QTY0=1&L_TAXAMT0=0&L_AMT0=10&L_DESC0=Item1%20Desc&L_ITEMWEIGHTVALUE0=%20%20%200%2e00000&L_ITEMLENGTHVALUE0=%20%20%200%2e00000&L_ITEMWIDTHVALUE0=%20%20%200%2e00000&L_ITEMHEIGHTVALUE0=%20%20%200%2e00000&L_ITEMCATEGORY0=Digital&PAYMENTREQUEST_0_CURRENCYCODE=JPY&PAYMENTREQUEST_0_AMT=10&PAYMENTREQUEST_0_ITEMAMT=10&PAYMENTREQUEST_0_SHIPPINGAMT=0&PAYMENTREQUEST_0_HANDLINGAMT=0&PAYMENTREQUEST_0_TAXAMT=0&PAYMENTREQUEST_0_DESC=Instant%20Payment%20Request&PAYMENTREQUEST_0_NOTIFYURL=http%3a%2f%2fmerchant%2eexample%2ecom%2fnotify&PAYMENTREQUEST_0_INSURANCEAMT=0&PAYMENTREQUEST_0_SHIPDISCAMT=0&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&L_PAYMENTREQUEST_0_NAME0=Item1&L_PAYMENTREQUEST_0_QTY0=1&L_PAYMENTREQUEST_0_TAXAMT0=0&L_PAYMENTREQUEST_0_AMT0=10&L_PAYMENTREQUEST_0_DESC0=Item1%20Desc&L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0=%20%20%200%2e00000&L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0=%20%20%200%2e00000&L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0=%20%20%200%2e00000&L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0=%20%20%200%2e00000&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital&PAYMENTREQUESTINFO_0_ERRORCODE=0
@@ -62,7 +62,7 @@ describe Paypal::NVP::Response do
62
62
  it 'should handle all attributes' do
63
63
  Paypal.logger.should_not_receive(:warn)
64
64
  response = request.details 'token'
65
- response.payer.identifier.should == 'PRT3TZ6MCBCNC'
65
+ response.payer.identifier.should == '9RWDTMRKKHQ8S'
66
66
  response.payment_responses.size.should == 1
67
67
  response.payment_info.size.should == 0
68
68
  response.payment_responses.first.should be_instance_of(Paypal::Payment::Response)
@@ -3,18 +3,14 @@ require 'spec_helper.rb'
3
3
  describe Paypal::Payment::Request do
4
4
  let :instant_request do
5
5
  Paypal::Payment::Request.new(
6
- :amount => 20.3,
6
+ :amount => 10.25,
7
7
  :currency_code => :JPY,
8
8
  :description => 'Instant Payment Request',
9
9
  :notify_url => 'http://merchant.example.com/notify',
10
10
  :items => [{
11
- :name => 'Item0',
12
- :description => 'Awesome Item!',
13
- :amount => 10.25
14
- }, {
15
11
  :name => 'Item1',
16
12
  :description => 'Awesome Item!',
17
- :amount => 10.05
13
+ :amount => 10.25
18
14
  }]
19
15
  )
20
16
  end
@@ -29,7 +25,7 @@ describe Paypal::Payment::Request do
29
25
 
30
26
  describe '.new' do
31
27
  it 'should handle Instant Payment parameters' do
32
- instant_request.amount.should == 20.3
28
+ instant_request.amount.should == 10.25
33
29
  instant_request.currency_code.should == :JPY
34
30
  instant_request.description.should == 'Instant Payment Request'
35
31
  instant_request.notify_url.should == 'http://merchant.example.com/notify'
@@ -45,19 +41,15 @@ describe Paypal::Payment::Request do
45
41
  describe '#to_params' do
46
42
  it 'should handle Instant Payment parameters' do
47
43
  instant_request.to_params.should == {
48
- :PAYMENTREQUEST_0_AMT => "20.30",
44
+ :PAYMENTREQUEST_0_AMT => "10.25",
49
45
  :PAYMENTREQUEST_0_CURRENCYCODE => :JPY,
50
46
  :PAYMENTREQUEST_0_DESC => "Instant Payment Request",
51
47
  :PAYMENTREQUEST_0_NOTIFYURL => "http://merchant.example.com/notify",
52
- :PAYMENTREQUEST_0_ITEMAMT => "20.30",
53
- :L_PAYMENTREQUEST_0_NAME0 => "Item0",
48
+ :PAYMENTREQUEST_0_ITEMAMT => "10.25",
49
+ :L_PAYMENTREQUEST_0_NAME0 => "Item1",
54
50
  :L_PAYMENTREQUEST_0_DESC0 => "Awesome Item!",
55
51
  :L_PAYMENTREQUEST_0_AMT0 => "10.25",
56
- :L_PAYMENTREQUEST_0_QTY0 => 1,
57
- :L_PAYMENTREQUEST_0_NAME1 => "Item1",
58
- :L_PAYMENTREQUEST_0_DESC1 => "Awesome Item!",
59
- :L_PAYMENTREQUEST_0_AMT1 => "10.05",
60
- :L_PAYMENTREQUEST_0_QTY1 => 1
52
+ :L_PAYMENTREQUEST_0_QTY0 => 1
61
53
  }
62
54
  end
63
55
 
@@ -70,4 +62,4 @@ describe Paypal::Payment::Request do
70
62
  }
71
63
  end
72
64
  end
73
- end
65
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Payment::Response::Info do
4
+ let :attributes do
5
+ {
6
+ :NAME => 'Item Name',
7
+ :DESC => 'Item Description',
8
+ :QTY => '1',
9
+ :ITEMCATEGORY => 'Digital',
10
+ :ITEMWIDTHVALUE => '1.0',
11
+ :ITEMHEIGHTVALUE => '2.0',
12
+ :ITEMLENGTHVALUE => '3.0',
13
+ :ITEMWEIGHTVALUE => '4.0'
14
+ }
15
+ end
16
+
17
+ describe '.new' do
18
+ subject { Paypal::Payment::Response::Item.new(attributes) }
19
+ its(:name) { should == 'Item Name' }
20
+ its(:description) { should == 'Item Description' }
21
+ its(:quantity) { should == 1 }
22
+ its(:category) { should == 'Digital' }
23
+ its(:width) { should == '1.0' }
24
+ its(:height) { should == '2.0' }
25
+ its(:length) { should == '3.0' }
26
+ its(:weight) { should == '4.0' }
27
+
28
+ context 'when non-supported attributes are given' do
29
+ it 'should ignore them and warn' do
30
+ _attr_ = attributes.merge(
31
+ :ignored => 'Ignore me!'
32
+ )
33
+ Paypal.logger.should_receive(:warn).with(
34
+ "Ignored Parameter (Paypal::Payment::Response::Item): ignored=Ignore me!"
35
+ )
36
+ Paypal::Payment::Response::Item.new _attr_
37
+ end
38
+ end
39
+ end
40
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal-express
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - nov matake
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-30 00:00:00 +09:00
18
+ date: 2011-04-12 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -175,6 +175,7 @@ files:
175
175
  - lib/paypal/payment/request/item.rb
176
176
  - lib/paypal/payment/response.rb
177
177
  - lib/paypal/payment/response/info.rb
178
+ - lib/paypal/payment/response/item.rb
178
179
  - lib/paypal/payment/response/payer.rb
179
180
  - lib/paypal/payment/response/ship_to.rb
180
181
  - lib/paypal/util.rb
@@ -207,6 +208,7 @@ files:
207
208
  - spec/paypal/payment/request/item_spec.rb
208
209
  - spec/paypal/payment/request_spec.rb
209
210
  - spec/paypal/payment/response/info_spec.rb
211
+ - spec/paypal/payment/response/item_spec.rb
210
212
  - spec/paypal/payment/response/payer_spec.rb
211
213
  - spec/paypal/payment/response/ship_to_spec.rb
212
214
  - spec/paypal/payment/response_spec.rb
@@ -244,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
246
  requirements: []
245
247
 
246
248
  rubyforge_project:
247
- rubygems_version: 1.5.3
249
+ rubygems_version: 1.5.2
248
250
  signing_key:
249
251
  specification_version: 3
250
252
  summary: PayPal Express Checkout API Client for Instance, Recurring and Digital Goods Payment.
@@ -277,6 +279,7 @@ test_files:
277
279
  - spec/paypal/payment/request/item_spec.rb
278
280
  - spec/paypal/payment/request_spec.rb
279
281
  - spec/paypal/payment/response/info_spec.rb
282
+ - spec/paypal/payment/response/item_spec.rb
280
283
  - spec/paypal/payment/response/payer_spec.rb
281
284
  - spec/paypal/payment/response/ship_to_spec.rb
282
285
  - spec/paypal/payment/response_spec.rb