paypal-express 0.0.4 → 0.0.5

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.0.4
1
+ 0.0.5
data/lib/paypal.rb CHANGED
@@ -11,6 +11,10 @@ module Paypal
11
11
  :production => 'https://www.paypal.com/cgi-bin/webscr',
12
12
  :sandbox => 'https://www.sandbox.paypal.com/cgi-bin/webscr'
13
13
  }
14
+ POPUP_ENDPOINT = {
15
+ :production => 'https://www.paypal.com/incontext',
16
+ :sandbox => 'https://www.sandbox.paypal.com/incontext'
17
+ }
14
18
 
15
19
  def self.endpoint
16
20
  if sandbox?
@@ -19,6 +23,13 @@ module Paypal
19
23
  Paypal::ENDPOINT[:production]
20
24
  end
21
25
  end
26
+ def self.popup_endpoint
27
+ if sandbox?
28
+ Paypal::POPUP_ENDPOINT[:sandbox]
29
+ else
30
+ Paypal::POPUP_ENDPOINT[:production]
31
+ end
32
+ end
22
33
 
23
34
  def self.log(message, mode = :info)
24
35
  self.logger.send mode, message
@@ -51,11 +62,12 @@ require 'paypal/base'
51
62
  require 'paypal/ipn'
52
63
  require 'paypal/nvp/request'
53
64
  require 'paypal/nvp/response'
65
+ require 'paypal/payment/common/amount'
54
66
  require 'paypal/express/request'
55
67
  require 'paypal/express/response'
56
68
  require 'paypal/payment/request'
69
+ require 'paypal/payment/request/item'
57
70
  require 'paypal/payment/response'
58
- require 'paypal/payment/response/amount'
59
71
  require 'paypal/payment/response/info'
60
72
  require 'paypal/payment/response/payer'
61
73
  require 'paypal/payment/response/ship_to'
@@ -15,6 +15,12 @@ module Paypal
15
15
  endpoint.to_s
16
16
  end
17
17
 
18
+ def popup_uri
19
+ endpoint = URI.parse Paypal.popup_endpoint
20
+ endpoint.query = {:token => self.token}.to_query
21
+ endpoint.to_s
22
+ end
23
+
18
24
  private
19
25
 
20
26
  def query
@@ -27,7 +27,7 @@ module Paypal
27
27
  @shipping_options_is_default = attrs.delete(:SHIPPINGOPTIONISDEFAULT) == 'true'
28
28
  @success_page_redirect_requested = attrs.delete(:SUCCESSPAGEREDIRECTREQUESTED) == 'true'
29
29
  @insurance_option_selected = attrs.delete(:INSURANCEOPTIONSELECTED) == 'true'
30
- @amount = Payment::Response::Amount.new(
30
+ @amount = Payment::Common::Amount.new(
31
31
  :total => attrs.delete(:AMT),
32
32
  :handing => attrs.delete(:HANDLINGAMT),
33
33
  :insurance => attrs.delete(:INSURANCEAMT),
@@ -0,0 +1,13 @@
1
+ module Paypal
2
+ module Payment
3
+ module Common
4
+ class Amount < Base
5
+ attr_optional :total, :fee, :handing, :insurance, :ship_disc, :shipping, :tax
6
+
7
+ def numeric_attribute?(key)
8
+ true
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,10 +5,10 @@ module Paypal
5
5
  attr_accessor :amount
6
6
 
7
7
  def initialize(attributes = {})
8
- @amount = if attributes[:amount].is_a?(Response::Amount)
8
+ @amount = if attributes[:amount].is_a?(Common::Amount)
9
9
  attributes[:amount]
10
10
  else
11
- Response::Amount.new(
11
+ Common::Amount.new(
12
12
  :total => attributes[:amount],
13
13
  :tax => attributes[:tax_amount],
14
14
  :shipping => attributes[:shipping_amount]
@@ -2,9 +2,18 @@ module Paypal
2
2
  module Payment
3
3
  class Request < Base
4
4
  attr_optional :amount, :action, :currency_code, :description, :notify_url, :billing_type, :billing_agreement_description
5
+ attr_accessor :items
6
+
7
+ def initialize(attributes = {})
8
+ @items = []
9
+ Array(attributes[:items]).each do |item_attrs|
10
+ @items << Item.new(item_attrs)
11
+ end
12
+ super
13
+ end
5
14
 
6
15
  def to_params(index = 0)
7
- {
16
+ params = {
8
17
  :"PAYMENTREQUEST_#{index}_PAYMENTACTION" => self.action,
9
18
  :"PAYMENTREQUEST_#{index}_AMT" => Util.formatted_amount(self.amount),
10
19
  :"PAYMENTREQUEST_#{index}_CURRENCYCODE" => self.currency_code,
@@ -18,6 +27,10 @@ module Paypal
18
27
  }.delete_if do |k, v|
19
28
  v.blank?
20
29
  end
30
+ self.items.each_with_index do |item, item_index|
31
+ params.merge! item.to_params(index, item_index)
32
+ end
33
+ params
21
34
  end
22
35
  end
23
36
  end
@@ -0,0 +1,19 @@
1
+ module Paypal
2
+ module Payment
3
+ class Request::Item < Base
4
+ attr_optional :name, :description, :amount, :quantity, :category
5
+
6
+ def to_params(parent_index, index = 0)
7
+ {
8
+ :"L_PAYMENTREQUEST_#{parent_index}_NAME#{index}" => self.name,
9
+ :"L_PAYMENTREQUEST_#{parent_index}_DESC#{index}" => self.description,
10
+ :"L_PAYMENTREQUEST_#{parent_index}_AMT#{index}" => Util.formatted_amount(self.amount),
11
+ :"L_PAYMENTREQUEST_#{parent_index}_QTY#{index}" => self.quantity,
12
+ :"L_PAYMENTREQUEST_#{parent_index}_ITEMCATEGORY#{index}" => self.category
13
+ }.delete_if do |k, v|
14
+ v.blank?
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,7 +5,7 @@ module Paypal
5
5
 
6
6
  def initialize(attributes = {})
7
7
  attrs = attributes.dup
8
- @amount = Amount.new(
8
+ @amount = Common::Amount.new(
9
9
  :total => attrs.delete(:AMT),
10
10
  :handing => attrs.delete(:HANDLINGAMT),
11
11
  :insurance => attrs.delete(:INSURANCEAMT),
@@ -24,7 +24,7 @@ module Paypal
24
24
  @@attribute_mapping.each do |key, value|
25
25
  self.send "#{value}=", attrs.delete(key)
26
26
  end
27
- @amount = Response::Amount.new(
27
+ @amount = Common::Amount.new(
28
28
  :total => attrs.delete(:AMT),
29
29
  :fee => attrs.delete(:FEEAMT),
30
30
  :tax => attrs.delete(:TAXAMT)
@@ -53,4 +53,19 @@ describe Paypal::Express::Response do
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ describe '#popup_uri' do
58
+ it 'should return express-checkout popup endpoint with token' do
59
+ fake_response 'SetExpressCheckout/success'
60
+ instance.popup_uri.should == 'https://www.paypal.com/incontext?token=EC-5YJ90598G69065317'
61
+ end
62
+
63
+ it 'should support sandbox mode' do
64
+ sandbox_mode do
65
+ fake_response 'SetExpressCheckout/success'
66
+ instance.popup_uri.should == 'https://www.sandbox.paypal.com/incontext?token=EC-5YJ90598G69065317'
67
+ end
68
+ end
69
+ end
70
+
56
71
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
- describe Paypal::Payment::Response::Amount do
3
+ describe Paypal::Payment::Common::Amount do
4
4
  let :keys do
5
- Paypal::Payment::Response::Amount.optional_attributes
5
+ Paypal::Payment::Common::Amount.optional_attributes
6
6
  end
7
7
 
8
8
  describe '.new' do
9
9
  it 'should not allow nil for attributes' do
10
- amount = Paypal::Payment::Response::Amount.new
10
+ amount = Paypal::Payment::Common::Amount.new
11
11
  keys.each do |key|
12
12
  amount.send(key).should == 0
13
13
  end
@@ -18,7 +18,7 @@ describe Paypal::Payment::Response::Amount do
18
18
  attributes = keys.inject({}) do |attributes, key|
19
19
  attributes.merge!(key => "100")
20
20
  end
21
- amount = Paypal::Payment::Response::Amount.new attributes
21
+ amount = Paypal::Payment::Common::Amount.new attributes
22
22
  keys.each do |key|
23
23
  amount.send(key).should == 100
24
24
  end
@@ -27,7 +27,7 @@ describe Paypal::Payment::Response::Amount do
27
27
  attributes = keys.inject({}) do |attributes, key|
28
28
  attributes.merge!(key => "10.25")
29
29
  end
30
- amount = Paypal::Payment::Response::Amount.new attributes
30
+ amount = Paypal::Payment::Common::Amount.new attributes
31
31
  keys.each do |key|
32
32
  amount.send(key).should == 10.25
33
33
  end
@@ -18,7 +18,7 @@ describe Paypal::Payment::Recurring do
18
18
  :aggregate_optional_amount => '0',
19
19
  :final_payment_date => '1970-01-01T00:00:00Z',
20
20
  :billing => {
21
- :amount => Paypal::Payment::Response::Amount.new(
21
+ :amount => Paypal::Payment::Common::Amount.new(
22
22
  :total => '1000',
23
23
  :shipping => '0',
24
24
  :tax => '0'
@@ -0,0 +1,25 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Payment::Request::Item do
4
+ let :instance do
5
+ Paypal::Payment::Request::Item.new(
6
+ :name => 'Name',
7
+ :description => 'Description',
8
+ :amount => 10,
9
+ :quantity => 5,
10
+ :category => :Digital
11
+ )
12
+ end
13
+
14
+ describe '#to_params' do
15
+ it 'should handle Recurring Profile activation parameters' do
16
+ instance.to_params(1).should == {
17
+ :L_PAYMENTREQUEST_1_NAME0 => 'Name',
18
+ :L_PAYMENTREQUEST_1_DESC0 => 'Description',
19
+ :L_PAYMENTREQUEST_1_AMT0 => '10.00',
20
+ :L_PAYMENTREQUEST_1_QTY0 => 5,
21
+ :L_PAYMENTREQUEST_1_ITEMCATEGORY0 => :Digital
22
+ }
23
+ end
24
+ end
25
+ end
@@ -6,7 +6,12 @@ describe Paypal::Payment::Request do
6
6
  :amount => 10,
7
7
  :currency_code => :JPY,
8
8
  :description => 'Instant Payment Request',
9
- :notify_url => 'http://merchant.example.com/notify'
9
+ :notify_url => 'http://merchant.example.com/notify',
10
+ :items => [{
11
+ :name => 'Item1',
12
+ :description => 'Awesome Item!',
13
+ :amount => 10
14
+ }]
10
15
  )
11
16
  end
12
17
 
@@ -39,7 +44,10 @@ describe Paypal::Payment::Request do
39
44
  :PAYMENTREQUEST_0_AMT => "10.00",
40
45
  :PAYMENTREQUEST_0_CURRENCYCODE => :JPY,
41
46
  :PAYMENTREQUEST_0_DESC => "Instant Payment Request",
42
- :PAYMENTREQUEST_0_NOTIFYURL => "http://merchant.example.com/notify"
47
+ :PAYMENTREQUEST_0_NOTIFYURL => "http://merchant.example.com/notify",
48
+ :L_PAYMENTREQUEST_0_NAME0 => "Item1",
49
+ :L_PAYMENTREQUEST_0_DESC0 => "Awesome Item!",
50
+ :L_PAYMENTREQUEST_0_AMT0 => "10.00"
43
51
  }
44
52
  end
45
53
 
@@ -33,7 +33,7 @@ describe Paypal::Payment::Response::Info do
33
33
  attribute_mapping.values.each do |key|
34
34
  from_symbol_uppercase.send(key).should_not be_nil
35
35
  end
36
- from_symbol_uppercase.amount.should == Paypal::Payment::Response::Amount.new(
36
+ from_symbol_uppercase.amount.should == Paypal::Payment::Common::Amount.new(
37
37
  :total => 14,
38
38
  :fee => 0.85
39
39
  )
@@ -54,7 +54,7 @@ describe Paypal::Payment::Response::Info do
54
54
  attribute_mapping.values.each do |key|
55
55
  from_symbol_lowercase.send(key).should be_nil
56
56
  end
57
- from_symbol_lowercase.amount.should == Paypal::Payment::Response::Amount.new
57
+ from_symbol_lowercase.amount.should == Paypal::Payment::Common::Amount.new
58
58
  end
59
59
  end
60
60
 
@@ -69,7 +69,7 @@ describe Paypal::Payment::Response::Info do
69
69
  attribute_mapping.values.each do |key|
70
70
  from_string.send(key).should be_nil
71
71
  end
72
- from_string.amount.should == Paypal::Payment::Response::Amount.new
72
+ from_string.amount.should == Paypal::Payment::Common::Amount.new
73
73
  end
74
74
  end
75
75
 
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
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-02-23 00:00:00 +09:00
18
+ date: 2011-02-24 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -166,13 +166,14 @@ files:
166
166
  - lib/paypal/ipn.rb
167
167
  - lib/paypal/nvp/request.rb
168
168
  - lib/paypal/nvp/response.rb
169
+ - lib/paypal/payment/common/amount.rb
169
170
  - lib/paypal/payment/recurring.rb
170
171
  - lib/paypal/payment/recurring/activation.rb
171
172
  - lib/paypal/payment/recurring/billing.rb
172
173
  - lib/paypal/payment/recurring/summary.rb
173
174
  - lib/paypal/payment/request.rb
175
+ - lib/paypal/payment/request/item.rb
174
176
  - lib/paypal/payment/response.rb
175
- - lib/paypal/payment/response/amount.rb
176
177
  - lib/paypal/payment/response/info.rb
177
178
  - lib/paypal/payment/response/payer.rb
178
179
  - lib/paypal/payment/response/ship_to.rb
@@ -200,10 +201,11 @@ files:
200
201
  - spec/paypal/ipn_spec.rb
201
202
  - spec/paypal/nvp/request_spec.rb
202
203
  - spec/paypal/nvp/response_spec.rb
204
+ - spec/paypal/payment/common/amount_spec.rb
203
205
  - spec/paypal/payment/recurring/activation_spec.rb
204
206
  - spec/paypal/payment/recurring_spec.rb
207
+ - spec/paypal/payment/request/item_spec.rb
205
208
  - spec/paypal/payment/request_spec.rb
206
- - spec/paypal/payment/response/amount_spec.rb
207
209
  - spec/paypal/payment/response/info_spec.rb
208
210
  - spec/paypal/payment/response/payer_spec.rb
209
211
  - spec/paypal/payment/response/ship_to_spec.rb
@@ -268,10 +270,11 @@ test_files:
268
270
  - spec/paypal/ipn_spec.rb
269
271
  - spec/paypal/nvp/request_spec.rb
270
272
  - spec/paypal/nvp/response_spec.rb
273
+ - spec/paypal/payment/common/amount_spec.rb
271
274
  - spec/paypal/payment/recurring/activation_spec.rb
272
275
  - spec/paypal/payment/recurring_spec.rb
276
+ - spec/paypal/payment/request/item_spec.rb
273
277
  - spec/paypal/payment/request_spec.rb
274
- - spec/paypal/payment/response/amount_spec.rb
275
278
  - spec/paypal/payment/response/info_spec.rb
276
279
  - spec/paypal/payment/response/payer_spec.rb
277
280
  - spec/paypal/payment/response/ship_to_spec.rb
@@ -1,11 +0,0 @@
1
- module Paypal
2
- module Payment
3
- class Response::Amount < Base
4
- attr_optional :total, :fee, :handing, :insurance, :ship_disc, :shipping, :tax
5
-
6
- def numeric_attribute?(key)
7
- true
8
- end
9
- end
10
- end
11
- end