paypal_adaptive 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -92,6 +92,9 @@ If you don't set ssl_cert_file then paypal_adaptive will check for certificates
92
92
  this location exists, otherwise falling back to the cacert.pem file included with paypal_adaptive.
93
93
 
94
94
  ## Changelog
95
+ 0.2.4
96
+ Support for embedded payments. Issue #21 thanks rafaelivan. Shipping address, wrapper methods has return response object. Issue #22 thanks tsmango.
97
+
95
98
  0.2.3
96
99
  Using bundler for gem creation. Moved all code to paypal_adaptive dir. Added ExecutePayment call to request. Thanks Roger Neel.
97
100
 
@@ -26,63 +26,56 @@ module PaypalAdaptive
26
26
  end
27
27
 
28
28
  def pay(data)
29
- raise NoDataError unless data
29
+ wrap_post(data, "/AdaptivePayments/Pay")
30
+ end
30
31
 
31
- response_data = call_api(data, "/AdaptivePayments/Pay")
32
- PaypalAdaptive::Response.new(response_data, @env)
32
+ def payment_details(data)
33
+ wrap_post(data, "/AdaptivePayments/PaymentDetails")
33
34
  end
34
35
 
35
36
  def set_payment_options(data)
36
- raise NoDataError unless data
37
-
38
- response_data = call_api(data, "/AdaptivePayments/SetPaymentOptions")
39
- PaypalAdaptive::Response.new(response_data, @env)
37
+ wrap_post(data, "/AdaptivePayments/SetPaymentOptions")
40
38
  end
41
39
 
42
- def payment_details(data)
43
- raise NoDataError unless data
40
+ def get_payment_options(data)
41
+ wrap_post(data, "/AdaptivePayments/GetPaymentOptions")
42
+ end
44
43
 
45
- call_api(data, "/AdaptivePayments/PaymentDetails")
44
+ def get_shipping_addresses(data)
45
+ wrap_post(data, "/AdaptivePayments/GetShippingAddresses")
46
46
  end
47
47
 
48
48
  def preapproval(data)
49
- raise NoDataError unless data
50
-
51
- response_data = call_api(data, "/AdaptivePayments/Preapproval")
52
- PaypalAdaptive::Response.new(response_data, @env)
49
+ wrap_post(data, "/AdaptivePayments/Preapproval")
53
50
  end
54
51
 
55
52
  def preapproval_details(data)
56
- raise NoDataError unless data
57
-
58
- call_api(data, "/AdaptivePayments/PreapprovalDetails")
53
+ wrap_post(data, "/AdaptivePayments/PreapprovalDetails")
59
54
  end
60
55
 
61
56
  def cancel_preapproval(data)
62
- raise NoDataError unless data
63
-
64
- call_api(data, "/AdaptivePayments/CancelPreapproval")
57
+ wrap_post(data, "/AdaptivePayments/CancelPreapproval")
65
58
  end
66
59
 
67
60
  def convert_currency(data)
68
- raise NoDataError unless data
69
-
70
- call_api(data, "/AdaptivePayments/ConvertCurrency")
61
+ wrap_post(data, "/AdaptivePayments/ConvertCurrency")
71
62
  end
72
63
 
73
64
  def refund(data)
74
- raise NoDataError unless data
75
-
76
- call_api(data, "/AdaptivePayments/Refund")
65
+ wrap_post(data, "/AdaptivePayments/Refund")
77
66
  end
78
67
 
79
68
  def execute_payment(data)
69
+ wrap_post(data, "/AdaptivePayments/ExecutePayment")
70
+ end
71
+
72
+ def wrap_post(data, path)
80
73
  raise NoDataError unless data
81
74
 
82
- call_api(data, "/AdaptivePayments/ExecutePayment")
75
+ PaypalAdaptive::Response.new(post(data, path), @env)
83
76
  end
84
77
 
85
- def call_api(data, path)
78
+ def post(data, path)
86
79
  #hack fix: JSON.unparse doesn't work in Rails 2.3.5; only {}.to_json does..
87
80
  api_request_data = JSON.unparse(data) rescue data.to_json
88
81
  url = URI.parse @@api_base_url
@@ -27,8 +27,14 @@ module PaypalAdaptive
27
27
  end
28
28
  end
29
29
 
30
- def approve_paypal_payment_url
31
- self['payKey'].nil? ? nil : "#{@@paypal_base_url}/webscr?cmd=_ap-payment&paykey=#{self['payKey']}"
30
+ def approve_paypal_payment_url(type=nil)
31
+ if self['payKey'].nil?
32
+ return nil
33
+ elsif ['mini', 'embedded'].include?(type.to_s)
34
+ return "#{@@paypal_base_url}/webapps/adaptivepayment/flow/pay?expType=#{type.to_s}&paykey=#{self['payKey']}"
35
+ end
36
+
37
+ "#{@@paypal_base_url}/webscr?cmd=_ap-payment&paykey=#{self['payKey']}"
32
38
  end
33
39
 
34
40
  def preapproval_paypal_payment_url
@@ -1,4 +1,4 @@
1
1
  module PaypalAdaptive
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
4
4
 
@@ -0,0 +1,7 @@
1
+ {
2
+ "payKey": "REPLACE-WITH-VALID-PAY-KEY",
3
+
4
+ "requestEnvelope": {
5
+ "errorLanguage": "en_US"
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "payKey": "REPLACE-WITH-VALID-PAY-KEY",
3
+
4
+ "requestEnvelope": {
5
+ "errorLanguage": "en_US"
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "payKey": "REPLACE-WITH-VALID-PAY-KEY",
3
+
4
+ "requestEnvelope": {
5
+ "errorLanguage": "en_US"
6
+ }
7
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "payKey": "REPLACE-WITH-VALID-PAY-KEY",
3
+
4
+ "senderOptions": {
5
+ "requireShippingAddressSelection": "true"
6
+ },
7
+
8
+ "receiverOptions": {
9
+ "invoiceData": {
10
+ "item": [
11
+ {
12
+ "identifier": "1",
13
+ "name": "Sample Product",
14
+ "itemCount": "1",
15
+ "itemPrice": "10.00",
16
+ "price": "10.00"
17
+ }
18
+ ],
19
+ "totalShipping": "0.00"
20
+ },
21
+ "receiver": {
22
+ "email": "testpp_1261697850_per@nextsprocket.com"
23
+ }
24
+ },
25
+
26
+ "requestEnvelope": {
27
+ "errorLanguage": "en_US"
28
+ }
29
+ }
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ class GetShippingAddressesTest < Test::Unit::TestCase
4
+ def setup
5
+ @pay_key = nil
6
+ @pay_request = PaypalAdaptive::Request.new("test")
7
+ end
8
+
9
+ def test_get_shipping_addresses
10
+ puts "-------"
11
+ puts "get shipping addresses"
12
+
13
+ # /Pay
14
+ data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_simple_pay_request_1.json")
15
+
16
+ data = read_json_file(data_filepath)
17
+ data["actionType"] = "CREATE"
18
+
19
+ pp_response = @pay_request.pay(data)
20
+ @pay_key = pp_response['payKey']
21
+
22
+ unless pp_response.success?
23
+ puts pp_response.errors
24
+ end
25
+
26
+ assert pp_response.success?
27
+
28
+ # /SetPaymentOptions
29
+ data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_set_payment_options_request.json")
30
+
31
+ data = read_json_file(data_filepath)
32
+ data["payKey"] = @pay_key
33
+
34
+ pp_response = @pay_request.set_payment_options(data)
35
+
36
+ unless pp_response.success?
37
+ puts pp_response.errors
38
+ end
39
+
40
+ assert pp_response.success?
41
+
42
+ # /GetShippingAddresses
43
+ data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_get_shipping_addresses_request.json")
44
+
45
+ data = read_json_file(data_filepath)
46
+ data["key"] = @pay_key
47
+
48
+ pp_response = @pay_request.get_shipping_addresses(data)
49
+
50
+ unless pp_response.success?
51
+ puts pp_response.errors
52
+ end
53
+
54
+ assert pp_response.success?
55
+ end
56
+
57
+ def read_json_file(filepath)
58
+ File.open(filepath, "rb"){|f| JSON.parse(f.read)}
59
+ end
60
+ end
@@ -73,10 +73,6 @@ class PayRequestTest < Test::Unit::TestCase
73
73
  assert pp_response.success? == false
74
74
  end
75
75
 
76
- def test_set_payment_options
77
- #TODO
78
- end
79
-
80
76
  def test_preapproval
81
77
  #TODO
82
78
  end
@@ -2,18 +2,35 @@ require 'test_helper'
2
2
 
3
3
  class PaymentDetailsTest < Test::Unit::TestCase
4
4
  def setup
5
+ @pay_key = nil
5
6
  @pay_request = PaypalAdaptive::Request.new("test")
6
- @payment_details_request = PaypalAdaptive::Request.new("test")
7
7
  end
8
-
8
+
9
9
  def test_payment_details
10
10
  puts "-------"
11
11
  puts "payment details"
12
+
13
+ # /Pay
12
14
  data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_chain_pay_request.json")
13
15
 
14
16
  data = read_json_file(data_filepath)
17
+
15
18
  pp_response = @pay_request.pay(data)
16
- puts "redirect url to\n #{pp_response.approve_paypal_payment_url}"
19
+ @pay_key = pp_response['payKey']
20
+
21
+ unless pp_response.success?
22
+ puts pp_response.errors
23
+ end
24
+
25
+ assert pp_response.success?
26
+
27
+ # /PaymentDetails
28
+ data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_payment_details_request.json")
29
+
30
+ data = read_json_file(data_filepath)
31
+ data["payKey"] = @pay_key
32
+
33
+ pp_response = @pay_request.payment_details(data)
17
34
 
18
35
  unless pp_response.success?
19
36
  puts pp_response.errors
@@ -21,14 +38,10 @@ class PaymentDetailsTest < Test::Unit::TestCase
21
38
 
22
39
  assert pp_response.success?
23
40
 
24
- data = {"requestEnvelope"=>{"errorLanguage"=>"en_US"}, "payKey" => pp_response['payKey']}
25
-
26
- response = @payment_details_request.payment_details(data)
27
- assert_equal 'CREATED', response['status']
41
+ assert_equal 'CREATED', pp_response['status']
28
42
  end
29
43
 
30
44
  def read_json_file(filepath)
31
45
  File.open(filepath, "rb"){|f| JSON.parse(f.read)}
32
46
  end
33
-
34
47
  end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class PaymentOptionsTest < Test::Unit::TestCase
4
+ def setup
5
+ @pay_key = nil
6
+ @pay_request = PaypalAdaptive::Request.new("test")
7
+ end
8
+
9
+ def test_payment_options
10
+ puts "-------"
11
+ puts "set payment options"
12
+
13
+ # /Pay
14
+ data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_simple_pay_request_1.json")
15
+
16
+ data = read_json_file(data_filepath)
17
+ data["actionType"] = "CREATE"
18
+
19
+ pp_response = @pay_request.pay(data)
20
+ @pay_key = pp_response['payKey']
21
+
22
+ unless pp_response.success?
23
+ puts pp_response.errors
24
+ end
25
+
26
+ assert pp_response.success?
27
+
28
+ # /SetPaymentOptions
29
+ data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_set_payment_options_request.json")
30
+
31
+ data = read_json_file(data_filepath)
32
+ data["payKey"] = @pay_key
33
+
34
+ pp_response = @pay_request.set_payment_options(data)
35
+
36
+ unless pp_response.success?
37
+ puts pp_response.errors
38
+ end
39
+
40
+ assert pp_response.success?
41
+
42
+ puts "-------"
43
+ puts "get payment options"
44
+
45
+ # /GetPaymentOptions
46
+ data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_get_payment_options_request.json")
47
+
48
+ data = read_json_file(data_filepath)
49
+ data["payKey"] = @pay_key
50
+
51
+ pp_response = @pay_request.get_payment_options(data)
52
+
53
+ unless pp_response.success?
54
+ puts pp_response.errors
55
+ end
56
+
57
+ assert pp_response.success?
58
+
59
+ assert_equal pp_response["senderOptions"]["requireShippingAddressSelection"], "true"
60
+ assert_equal pp_response["receiverOptions"].first["invoiceData"]["item"].first["identifier"], "1"
61
+ assert_equal pp_response["receiverOptions"].first["invoiceData"]["item"].first["name"], "Sample Product"
62
+ assert_equal pp_response["receiverOptions"].first["invoiceData"]["item"].first["itemCount"], "1"
63
+ assert_equal pp_response["receiverOptions"].first["invoiceData"]["item"].first["itemPrice"], "10.00"
64
+ assert_equal pp_response["receiverOptions"].first["invoiceData"]["item"].first["price"], "10.00"
65
+ assert_equal pp_response["receiverOptions"].first["invoiceData"]["totalShipping"], "0.00"
66
+ end
67
+
68
+ def read_json_file(filepath)
69
+ File.open(filepath, "rb"){|f| JSON.parse(f.read)}
70
+ end
71
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal_adaptive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-10 00:00:00.000000000Z
12
+ date: 2011-10-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70366761922980 !ruby/object:Gem::Requirement
16
+ requirement: &70330139945400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70366761922980
24
+ version_requirements: *70330139945400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jsonschema
27
- requirement: &70366761921940 !ruby/object:Gem::Requirement
27
+ requirement: &70330139944900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70366761921940
35
+ version_requirements: *70330139944900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70366761920820 !ruby/object:Gem::Requirement
38
+ requirement: &70330139944440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0.8'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70366761920820
46
+ version_requirements: *70330139944440
47
47
  description: Lightweight wrapper for Paypal's Adaptive Payments API
48
48
  email:
49
49
  - tommy.chheng@gmail.com
@@ -73,14 +73,20 @@ files:
73
73
  - test/data/invalid_preapproval.json
74
74
  - test/data/invalid_simple_pay_request_1.json
75
75
  - test/data/valid_chain_pay_request.json
76
+ - test/data/valid_get_payment_options_request.json
77
+ - test/data/valid_get_shipping_addresses_request.json
76
78
  - test/data/valid_parallel_pay_request.json
79
+ - test/data/valid_payment_details_request.json
77
80
  - test/data/valid_preapproval.json
81
+ - test/data/valid_set_payment_options_request.json
78
82
  - test/data/valid_simple_pay_request_1.json
79
83
  - test/test_helper.rb
80
84
  - test/unit/config_test.rb
85
+ - test/unit/get_shipping_addresses_test.rb
81
86
  - test/unit/pay_request_schema_test.rb
82
87
  - test/unit/pay_request_test.rb
83
88
  - test/unit/payment_details_test.rb
89
+ - test/unit/payment_options_test.rb
84
90
  - test/unit/preapproval_test.rb
85
91
  homepage: http://github.com/tc/paypal_adaptive
86
92
  licenses: []
@@ -112,12 +118,18 @@ test_files:
112
118
  - test/data/invalid_preapproval.json
113
119
  - test/data/invalid_simple_pay_request_1.json
114
120
  - test/data/valid_chain_pay_request.json
121
+ - test/data/valid_get_payment_options_request.json
122
+ - test/data/valid_get_shipping_addresses_request.json
115
123
  - test/data/valid_parallel_pay_request.json
124
+ - test/data/valid_payment_details_request.json
116
125
  - test/data/valid_preapproval.json
126
+ - test/data/valid_set_payment_options_request.json
117
127
  - test/data/valid_simple_pay_request_1.json
118
128
  - test/test_helper.rb
119
129
  - test/unit/config_test.rb
130
+ - test/unit/get_shipping_addresses_test.rb
120
131
  - test/unit/pay_request_schema_test.rb
121
132
  - test/unit/pay_request_test.rb
122
133
  - test/unit/payment_details_test.rb
134
+ - test/unit/payment_options_test.rb
123
135
  - test/unit/preapproval_test.rb