paypal-sdk-rest 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +12 -12
- data/README.md +181 -180
- data/Rakefile +9 -9
- data/lib/paypal-sdk-rest.rb +2 -2
- data/lib/paypal-sdk/rest.rb +38 -38
- data/lib/paypal-sdk/rest/api.rb +23 -23
- data/lib/paypal-sdk/rest/data_types.rb +878 -459
- data/lib/paypal-sdk/rest/error_hash.rb +39 -39
- data/lib/paypal-sdk/rest/get_api.rb +20 -20
- data/lib/paypal-sdk/rest/request_data_type.rb +56 -56
- data/lib/paypal-sdk/rest/set_api.rb +42 -42
- data/lib/paypal-sdk/rest/version.rb +7 -7
- data/spec/config/cacert.pem +171 -171
- data/spec/config/paypal.yml +8 -8
- data/spec/invoice_examples_spec.rb +38 -0
- data/spec/log/http.log +71 -0
- data/spec/payments_examples_spec.rb +275 -272
- data/spec/spec_helper.rb +24 -24
- metadata +27 -30
data/spec/config/paypal.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
test: &default
|
2
|
-
client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
|
3
|
-
client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
|
4
|
-
mode: sandbox
|
5
|
-
|
6
|
-
development:
|
7
|
-
<<: *default
|
8
|
-
|
1
|
+
test: &default
|
2
|
+
client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
|
3
|
+
client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
|
4
|
+
mode: sandbox
|
5
|
+
|
6
|
+
development:
|
7
|
+
<<: *default
|
8
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Invoice" do
|
4
|
+
|
5
|
+
InvoiceAttributes = {
|
6
|
+
"merchant_info" => {
|
7
|
+
"email" => "PPX.DevNet-facilitator@gmail.com"
|
8
|
+
},
|
9
|
+
"billing_info" => [ { "email" => "example@example.com" } ],
|
10
|
+
"items" => [
|
11
|
+
{
|
12
|
+
"name" => "Sutures",
|
13
|
+
"quantity" => 100,
|
14
|
+
"unit_price" => {
|
15
|
+
"currency" => "USD",
|
16
|
+
"value" => 5
|
17
|
+
}
|
18
|
+
}
|
19
|
+
],
|
20
|
+
"note" => "Medical Invoice 16 Jul, 2013 PST"
|
21
|
+
}
|
22
|
+
|
23
|
+
it "create invoice" do
|
24
|
+
invoice = PayPal::SDK::REST::Invoice.new(InvoiceAttributes)
|
25
|
+
invoice.create.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "list invoice" do
|
29
|
+
history = PayPal::SDK::REST::Invoice.get_all( :total_count_required =>true )
|
30
|
+
history.total_count.should_not be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "get invoice" do
|
34
|
+
invoice = PayPal::SDK::REST::Invoice.find("INV2-P6VJ-36HG-BBVT-M2MA")
|
35
|
+
invoice.should be_a PayPal::SDK::REST::Invoice
|
36
|
+
invoice.id.should eql "INV2-P6VJ-36HG-BBVT-M2MA"
|
37
|
+
end
|
38
|
+
end
|
data/spec/log/http.log
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
opening connection to api.sandbox.paypal.com:443...
|
2
|
+
opened
|
3
|
+
starting SSL for api.sandbox.paypal.com:443...
|
4
|
+
SSL established
|
5
|
+
<- "POST /v1/invoicing/invoices HTTP/1.1\r\nAuthorization: Bearer 2.RUg7qbhqxLBDae7Si-exTRs8ztl0Tv1FWMAnd0XVo\r\nContent-Type: application/json\r\nUser-Agent: PayPalSDK/rest-sdk-ruby 0.6.1 (paypal-sdk-core 0.2.8; ruby 2.1.1p76-x86_64-darwin12.0)\r\nPaypal-Request-Id: 3f420816-6ba8-4831-be95-6337e8eeb209\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nHost: api.sandbox.paypal.com\r\nContent-Length: 243\r\n\r\n"
|
6
|
+
<- "{\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"items\":[{\"name\":\"Sutures\",\"quantity\":100.0,\"unit_price\":{\"currency\":\"USD\",\"value\":\"5\"}}],\"note\":\"Medical Invoice 16 Jul, 2013 PST\"}"
|
7
|
+
-> "HTTP/1.1 201 Created\r\n"
|
8
|
+
-> "Server: Apache-Coyote/1.1\r\n"
|
9
|
+
-> "PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=331\r\n"
|
10
|
+
-> "Paypal-Debug-Id: 31e03665acd13\r\n"
|
11
|
+
-> "Date: Fri, 04 Apr 2014 09:03:36 GMT\r\n"
|
12
|
+
-> "Location: https://api.sandbox.paypal.com/v1/invoicing/invoices/INV2-QZ3V-GKZS-MJNP-HGBQ\r\n"
|
13
|
+
-> "Content-Type: application/json\r\n"
|
14
|
+
-> "Transfer-Encoding: chunked\r\n"
|
15
|
+
-> "\r\n"
|
16
|
+
-> "1c6\r\n"
|
17
|
+
reading 454 bytes...
|
18
|
+
-> "{\"id\":\"INV2-QZ3V-GKZS-MJNP-HGBQ\",\"number\":\"0008\",\"status\":\"DRAFT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"items\":[{\"name\":\"Sutures\",\"quantity\":100.0,\"unit_price\":{\"currency\":\"USD\",\"value\":\"5.00\"}}],\"invoice_date\":\"2014-04-04 PDT\",\"tax_calculated_after_discount\":false,\"tax_inclusive\":false,\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"}}"
|
19
|
+
read 454 bytes
|
20
|
+
reading 2 bytes...
|
21
|
+
-> "\r\n"
|
22
|
+
read 2 bytes
|
23
|
+
-> "0\r\n"
|
24
|
+
-> "\r\n"
|
25
|
+
Conn keep-alive
|
26
|
+
opening connection to api.sandbox.paypal.com:443...
|
27
|
+
opened
|
28
|
+
starting SSL for api.sandbox.paypal.com:443...
|
29
|
+
SSL established
|
30
|
+
<- "GET /v1/invoicing/invoices/?total_count_required=true HTTP/1.1\r\nAuthorization: Bearer 2.RUg7qbhqxLBDae7Si-exTRs8ztl0Tv1FWMAnd0XVo\r\nContent-Type: application/json\r\nUser-Agent: PayPalSDK/rest-sdk-ruby 0.6.1 (paypal-sdk-core 0.2.8; ruby 2.1.1p76-x86_64-darwin12.0)\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nHost: api.sandbox.paypal.com\r\n\r\n"
|
31
|
+
-> "HTTP/1.1 200 OK\r\n"
|
32
|
+
-> "Server: Apache-Coyote/1.1\r\n"
|
33
|
+
-> "PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=331\r\n"
|
34
|
+
-> "Paypal-Debug-Id: 246eb331af4bd\r\n"
|
35
|
+
-> "Date: Fri, 04 Apr 2014 09:03:38 GMT\r\n"
|
36
|
+
-> "Content-Type: application/json\r\n"
|
37
|
+
-> "Transfer-Encoding: chunked\r\n"
|
38
|
+
-> "\r\n"
|
39
|
+
-> "f1c\r\n"
|
40
|
+
reading 3868 bytes...
|
41
|
+
-> "{\"total_count\":8,\"invoices\":[{\"id\":\"INV2-QZ3V-GKZS-MJNP-HGBQ\",\"number\":\"0008\",\"status\":\"DRAFT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\"},\"invoice_date\":\"2014-04-04 PDT\",\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-04 02:03:36 PDT\"}},{\"id\":\"INV2-KDSB-LFC9-7AH9-TP92\",\"number\":\"0007\",\"status\":\"DRAFT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\"},\"invoice_date\":\"2014-04-04 PDT\",\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-04 01:57:19 PDT\"}},{\"id\":\"INV2-YADT-86G3-KMHM-LV8B\",\"number\":\"0006\",\"status\":\"DRAFT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\"},\"invoice_date\":\"2014-04-04 PDT\",\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-04 01:55:44 PDT\"}},{\"id\":\"INV2-GH3A-3DWB-FCJZ-P97Q\",\"number\":\"0005\",\"status\":\"DRAFT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\",\"first_name\":\"Sally\",\"last_name\":\"Patient\",\"business_name\":\"Not applicable\"},\"invoice_date\":\"2014-04-03 PDT\",\"payment_term\":{\"due_date\":\"2014-05-18 PDT\"},\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-03 23:49:20 PDT\"}},{\"id\":\"INV2-9CAH-K5G7-2JPL-G4B4\",\"number\":\"0004\",\"status\":\"SENT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\",\"first_name\":\"Sally\",\"last_name\":\"Patient\",\"business_name\":\"Not applicable\"},\"invoice_date\":\"2014-04-03 PDT\",\"payment_term\":{\"due_date\":\"2014-05-18 PDT\"},\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-03 23:15:03 PDT\"}},{\"id\":\"INV2-CJL7-PF4G-BLQF-5FWG\",\"number\":\"0003\",\"status\":\"CANCELLED\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\",\"first_name\":\"Sally\",\"last_name\":\"Patient\",\"business_name\":\"Not applicable\"},\"invoice_date\":\"2014-04-03 PDT\",\"payment_term\":{\"due_date\":\"2014-05-18 PDT\"},\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-03 23:11:40 PDT\"}},{\"id\":\"INV2-VHEH-7Q5J-NV6F-RM6V\",\"number\":\"0002\",\"status\":\"SENT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\",\"first_name\":\"Sally\",\"last_name\":\"Patient\",\"business_name\":\"Not applicable\"},\"invoice_date\":\"2014-04-03 PDT\",\"payment_term\":{\"due_date\":\"2014-05-18 PDT\"},\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-03 22:52:23 PDT\"}},{\"id\":\"INV2-P6VJ-36HG-BBVT-M2MA\",\"number\":\"0001\",\"status\":\"SENT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\"},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"email\":\"example@example.com\",\"first_name\":\"Sally\",\"last_name\":\"Patient\",\"business_name\":\"Not applicable\"},\"invoice_date\":\"2014-04-03 PDT\",\"payment_term\":{\"due_date\":\"2014-05-18 PDT\"},\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-03 22:30:15 PDT\"}}]}"
|
42
|
+
read 3868 bytes
|
43
|
+
reading 2 bytes...
|
44
|
+
-> "\r\n"
|
45
|
+
read 2 bytes
|
46
|
+
-> "0\r\n"
|
47
|
+
-> "\r\n"
|
48
|
+
Conn keep-alive
|
49
|
+
opening connection to api.sandbox.paypal.com:443...
|
50
|
+
opened
|
51
|
+
starting SSL for api.sandbox.paypal.com:443...
|
52
|
+
SSL established
|
53
|
+
<- "GET /v1/invoicing/invoices/INV2-P6VJ-36HG-BBVT-M2MA HTTP/1.1\r\nAuthorization: Bearer 2.RUg7qbhqxLBDae7Si-exTRs8ztl0Tv1FWMAnd0XVo\r\nContent-Type: application/json\r\nUser-Agent: PayPalSDK/rest-sdk-ruby 0.6.1 (paypal-sdk-core 0.2.8; ruby 2.1.1p76-x86_64-darwin12.0)\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nHost: api.sandbox.paypal.com\r\n\r\n"
|
54
|
+
-> "HTTP/1.1 200 OK\r\n"
|
55
|
+
-> "Server: Apache-Coyote/1.1\r\n"
|
56
|
+
-> "PROXY_SERVER_INFO: host=slcsbjava4.slc.paypal.com;threadId=238\r\n"
|
57
|
+
-> "Paypal-Debug-Id: 64e62266afe5c\r\n"
|
58
|
+
-> "Date: Fri, 04 Apr 2014 09:03:40 GMT\r\n"
|
59
|
+
-> "Content-Type: application/json\r\n"
|
60
|
+
-> "Transfer-Encoding: chunked\r\n"
|
61
|
+
-> "\r\n"
|
62
|
+
-> "461\r\n"
|
63
|
+
reading 1121 bytes...
|
64
|
+
-> "{\"id\":\"INV2-P6VJ-36HG-BBVT-M2MA\",\"number\":\"0001\",\"status\":\"SENT\",\"merchant_info\":{\"email\":\"PPX.DevNet-facilitator@gmail.com\",\"first_name\":\"Dennis\",\"last_name\":\"Doctor\",\"business_name\":\"Medical Professionals, LLC\",\"phone\":{\"country_code\":\"1\",\"national_number\":\"5032141716\"},\"address\":{\"line1\":\"1234 Main St.\",\"city\":\"Portland\",\"state\":\"OR\",\"postal_code\":\"97217\",\"country_code\":\"US\"}},\"billing_info\":[{\"email\":\"example@example.com\"}],\"shipping_info\":{\"first_name\":\"Sally\",\"last_name\":\"Patient\",\"business_name\":\"Not applicable\",\"address\":{\"line1\":\"1234 Broad St.\",\"city\":\"Portland\",\"state\":\"OR\",\"postal_code\":\"97216\",\"country_code\":\"US\"}},\"items\":[{\"name\":\"Sutures\",\"quantity\":100.0,\"unit_price\":{\"currency\":\"USD\",\"value\":\"5.00\"}}],\"invoice_date\":\"2014-04-03 PDT\",\"payment_term\":{\"term_type\":\"NET_45\",\"due_date\":\"2014-05-18 PDT\"},\"tax_calculated_after_discount\":false,\"tax_inclusive\":false,\"note\":\"Medical Invoice 16 Jul, 2013 PST\",\"total_amount\":{\"currency\":\"USD\",\"value\":\"500.00\"},\"metadata\":{\"created_date\":\"2014-04-03 22:30:15 PDT\",\"first_sent_date\":\"2014-04-03 22:48:22 PDT\",\"last_sent_date\":\"2014-04-03 22:48:22 PDT\"}}"
|
65
|
+
read 1121 bytes
|
66
|
+
reading 2 bytes...
|
67
|
+
-> "\r\n"
|
68
|
+
read 2 bytes
|
69
|
+
-> "0\r\n"
|
70
|
+
-> "\r\n"
|
71
|
+
Conn keep-alive
|
@@ -1,272 +1,275 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Payments" do
|
4
|
-
|
5
|
-
PaymentAttributes = {
|
6
|
-
"intent" => "sale",
|
7
|
-
"payer" => {
|
8
|
-
"payment_method" => "credit_card",
|
9
|
-
"funding_instruments" => [ {
|
10
|
-
"credit_card" => {
|
11
|
-
"type" => "visa",
|
12
|
-
"number" => "4417119669820331",
|
13
|
-
"expire_month" => "11", "expire_year" => "2018",
|
14
|
-
"cvv2" => "874",
|
15
|
-
"first_name" => "Joe", "last_name" => "Shopper",
|
16
|
-
"billing_address" => {
|
17
|
-
"line1" => "52 N Main ST",
|
18
|
-
"city" => "Johnstown",
|
19
|
-
"state" => "OH",
|
20
|
-
"postal_code" => "43210", "country_code" => "US" } } } ] },
|
21
|
-
"transactions" => [ {
|
22
|
-
"amount" => {
|
23
|
-
"total" => "1.00",
|
24
|
-
"currency" => "USD" },
|
25
|
-
"description" => "This is the payment transaction description." } ] }
|
26
|
-
|
27
|
-
|
28
|
-
it "Validate user-agent" do
|
29
|
-
PayPal::SDK::REST::API.user_agent.should match "PayPalSDK/rest-sdk-ruby"
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "Examples" do
|
33
|
-
describe "REST" do
|
34
|
-
it "Modifiy global configuration" do
|
35
|
-
backup_config = PayPal::SDK::REST.api.config
|
36
|
-
PayPal::SDK::REST.set_config( :client_id => "XYZ" )
|
37
|
-
PayPal::SDK::REST.api.config.client_id.should eql "XYZ"
|
38
|
-
PayPal::SDK::REST.set_config(backup_config)
|
39
|
-
PayPal::SDK::REST.api.config.client_id.should_not eql "XYZ"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "Payment" do
|
44
|
-
it "Create" do
|
45
|
-
payment = Payment.new(PaymentAttributes)
|
46
|
-
# Create
|
47
|
-
payment.create
|
48
|
-
payment.error.should be_nil
|
49
|
-
payment.id.should_not be_nil
|
50
|
-
end
|
51
|
-
|
52
|
-
it "Create with request_id" do
|
53
|
-
payment = Payment.new(PaymentAttributes)
|
54
|
-
payment.create
|
55
|
-
payment.error.should be_nil
|
56
|
-
|
57
|
-
request_id = payment.request_id
|
58
|
-
|
59
|
-
new_payment = Payment.new(PaymentAttributes.merge( :request_id => request_id ))
|
60
|
-
new_payment.create
|
61
|
-
new_payment.error.should be_nil
|
62
|
-
|
63
|
-
payment.id.should eql new_payment.id
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
it "Create with token" do
|
68
|
-
api = API.new
|
69
|
-
payment = Payment.new(PaymentAttributes.merge( :token => api.token ))
|
70
|
-
Payment.api.should_not eql payment.api
|
71
|
-
payment.create
|
72
|
-
payment.error.should be_nil
|
73
|
-
payment.id.should_not be_nil
|
74
|
-
end
|
75
|
-
|
76
|
-
it "Create with client_id and client_secret" do
|
77
|
-
api = API.new
|
78
|
-
payment = Payment.new(PaymentAttributes.merge( :client_id => api.config.client_id, :client_secret => api.config.client_secret))
|
79
|
-
Payment.api.should_not eql payment.api
|
80
|
-
payment.create
|
81
|
-
payment.error.should be_nil
|
82
|
-
payment.id.should_not be_nil
|
83
|
-
end
|
84
|
-
|
85
|
-
it "List" do
|
86
|
-
payment_history = Payment.all( "count" => 5 )
|
87
|
-
payment_history.error.should be_nil
|
88
|
-
payment_history.count.should eql 5
|
89
|
-
end
|
90
|
-
|
91
|
-
it "Find" do
|
92
|
-
payment_history = Payment.all( "count" => 1 )
|
93
|
-
payment = Payment.find(payment_history.payments[0].id)
|
94
|
-
payment.error.should be_nil
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "Validation" do
|
98
|
-
|
99
|
-
it "Create with empty values" do
|
100
|
-
payment = Payment.new
|
101
|
-
payment.create.should be_false
|
102
|
-
end
|
103
|
-
|
104
|
-
it "Find with invalid ID" do
|
105
|
-
lambda {
|
106
|
-
payment = Payment.find("Invalid")
|
107
|
-
}.should raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
|
108
|
-
end
|
109
|
-
|
110
|
-
it "Find with nil" do
|
111
|
-
lambda{
|
112
|
-
payment = Payment.find(nil)
|
113
|
-
}.should raise_error ArgumentError
|
114
|
-
end
|
115
|
-
|
116
|
-
it "Find with empty string" do
|
117
|
-
lambda{
|
118
|
-
payment = Payment.find("")
|
119
|
-
}.should raise_error ArgumentError
|
120
|
-
end
|
121
|
-
|
122
|
-
it "Find record with expired token" do
|
123
|
-
lambda {
|
124
|
-
Payment.api.token
|
125
|
-
Payment.api.token.sub!(/^/, "Expired")
|
126
|
-
Payment.all(:count => 1)
|
127
|
-
}.should_not raise_error
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "instance method" do
|
132
|
-
|
133
|
-
it "Execute" do
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
refund =
|
160
|
-
refund.error.should be_nil
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
@
|
203
|
-
@
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
"
|
225
|
-
"
|
226
|
-
"
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
"
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
credit_card
|
236
|
-
credit_card.
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
credit_card.
|
255
|
-
|
256
|
-
|
257
|
-
credit_card.
|
258
|
-
credit_card.error
|
259
|
-
|
260
|
-
credit_card.error.
|
261
|
-
credit_card.error
|
262
|
-
|
263
|
-
credit_card.error.details[
|
264
|
-
|
265
|
-
credit_card.error
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Payments" do
|
4
|
+
|
5
|
+
PaymentAttributes = {
|
6
|
+
"intent" => "sale",
|
7
|
+
"payer" => {
|
8
|
+
"payment_method" => "credit_card",
|
9
|
+
"funding_instruments" => [ {
|
10
|
+
"credit_card" => {
|
11
|
+
"type" => "visa",
|
12
|
+
"number" => "4417119669820331",
|
13
|
+
"expire_month" => "11", "expire_year" => "2018",
|
14
|
+
"cvv2" => "874",
|
15
|
+
"first_name" => "Joe", "last_name" => "Shopper",
|
16
|
+
"billing_address" => {
|
17
|
+
"line1" => "52 N Main ST",
|
18
|
+
"city" => "Johnstown",
|
19
|
+
"state" => "OH",
|
20
|
+
"postal_code" => "43210", "country_code" => "US" } } } ] },
|
21
|
+
"transactions" => [ {
|
22
|
+
"amount" => {
|
23
|
+
"total" => "1.00",
|
24
|
+
"currency" => "USD" },
|
25
|
+
"description" => "This is the payment transaction description." } ] }
|
26
|
+
|
27
|
+
|
28
|
+
it "Validate user-agent" do
|
29
|
+
PayPal::SDK::REST::API.user_agent.should match "PayPalSDK/rest-sdk-ruby"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Examples" do
|
33
|
+
describe "REST" do
|
34
|
+
it "Modifiy global configuration" do
|
35
|
+
backup_config = PayPal::SDK::REST.api.config
|
36
|
+
PayPal::SDK::REST.set_config( :client_id => "XYZ" )
|
37
|
+
PayPal::SDK::REST.api.config.client_id.should eql "XYZ"
|
38
|
+
PayPal::SDK::REST.set_config(backup_config)
|
39
|
+
PayPal::SDK::REST.api.config.client_id.should_not eql "XYZ"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Payment" do
|
44
|
+
it "Create" do
|
45
|
+
payment = Payment.new(PaymentAttributes)
|
46
|
+
# Create
|
47
|
+
payment.create
|
48
|
+
payment.error.should be_nil
|
49
|
+
payment.id.should_not be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "Create with request_id" do
|
53
|
+
payment = Payment.new(PaymentAttributes)
|
54
|
+
payment.create
|
55
|
+
payment.error.should be_nil
|
56
|
+
|
57
|
+
request_id = payment.request_id
|
58
|
+
|
59
|
+
new_payment = Payment.new(PaymentAttributes.merge( :request_id => request_id ))
|
60
|
+
new_payment.create
|
61
|
+
new_payment.error.should be_nil
|
62
|
+
|
63
|
+
payment.id.should eql new_payment.id
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
it "Create with token" do
|
68
|
+
api = API.new
|
69
|
+
payment = Payment.new(PaymentAttributes.merge( :token => api.token ))
|
70
|
+
Payment.api.should_not eql payment.api
|
71
|
+
payment.create
|
72
|
+
payment.error.should be_nil
|
73
|
+
payment.id.should_not be_nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it "Create with client_id and client_secret" do
|
77
|
+
api = API.new
|
78
|
+
payment = Payment.new(PaymentAttributes.merge( :client_id => api.config.client_id, :client_secret => api.config.client_secret))
|
79
|
+
Payment.api.should_not eql payment.api
|
80
|
+
payment.create
|
81
|
+
payment.error.should be_nil
|
82
|
+
payment.id.should_not be_nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "List" do
|
86
|
+
payment_history = Payment.all( "count" => 5 )
|
87
|
+
payment_history.error.should be_nil
|
88
|
+
payment_history.count.should eql 5
|
89
|
+
end
|
90
|
+
|
91
|
+
it "Find" do
|
92
|
+
payment_history = Payment.all( "count" => 1 )
|
93
|
+
payment = Payment.find(payment_history.payments[0].id)
|
94
|
+
payment.error.should be_nil
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "Validation" do
|
98
|
+
|
99
|
+
it "Create with empty values" do
|
100
|
+
payment = Payment.new
|
101
|
+
payment.create.should be_false
|
102
|
+
end
|
103
|
+
|
104
|
+
it "Find with invalid ID" do
|
105
|
+
lambda {
|
106
|
+
payment = Payment.find("Invalid")
|
107
|
+
}.should raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
|
108
|
+
end
|
109
|
+
|
110
|
+
it "Find with nil" do
|
111
|
+
lambda{
|
112
|
+
payment = Payment.find(nil)
|
113
|
+
}.should raise_error ArgumentError
|
114
|
+
end
|
115
|
+
|
116
|
+
it "Find with empty string" do
|
117
|
+
lambda{
|
118
|
+
payment = Payment.find("")
|
119
|
+
}.should raise_error ArgumentError
|
120
|
+
end
|
121
|
+
|
122
|
+
it "Find record with expired token" do
|
123
|
+
lambda {
|
124
|
+
Payment.api.token
|
125
|
+
Payment.api.token.sub!(/^/, "Expired")
|
126
|
+
Payment.all(:count => 1)
|
127
|
+
}.should_not raise_error
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "instance method" do
|
132
|
+
|
133
|
+
it "Execute" do
|
134
|
+
pending "Test with capybara"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "Sale" do
|
141
|
+
before :each do
|
142
|
+
@payment = Payment.new(PaymentAttributes)
|
143
|
+
@payment.create
|
144
|
+
@payment.should be_success
|
145
|
+
end
|
146
|
+
|
147
|
+
it "Find" do
|
148
|
+
sale = Sale.find(@payment.transactions[0].related_resources[0].sale.id)
|
149
|
+
sale.error.should be_nil
|
150
|
+
sale.should be_a Sale
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "instance method" do
|
154
|
+
it "Refund" do
|
155
|
+
sale = @payment.transactions[0].related_resources[0].sale
|
156
|
+
refund = sale.refund( :amount => { :total => "1.00", :currency => "USD" } )
|
157
|
+
refund.error.should be_nil
|
158
|
+
|
159
|
+
refund = Refund.find(refund.id)
|
160
|
+
refund.error.should be_nil
|
161
|
+
refund.should be_a Refund
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "Authorize" do
|
167
|
+
before :each do
|
168
|
+
@payment = Payment.new(PaymentAttributes.merge( "intent" => "authorize" ))
|
169
|
+
@payment.create
|
170
|
+
@payment.error.should be_nil
|
171
|
+
end
|
172
|
+
|
173
|
+
it "Find" do
|
174
|
+
authorize = Authorization.find(@payment.transactions[0].related_resources[0].authorization.id)
|
175
|
+
authorize.error.should be_nil
|
176
|
+
authorize.should be_a Authorization
|
177
|
+
end
|
178
|
+
|
179
|
+
it "Capture" do
|
180
|
+
authorize = @payment.transactions[0].related_resources[0].authorization
|
181
|
+
capture = authorize.capture({:amount => { :currency => "USD", :total => "1.00" } })
|
182
|
+
capture.error.should be_nil
|
183
|
+
end
|
184
|
+
|
185
|
+
it "Void" do
|
186
|
+
authorize = @payment.transactions[0].related_resources[0].authorization
|
187
|
+
authorize.void()
|
188
|
+
authorize.error.should be_nil
|
189
|
+
end
|
190
|
+
|
191
|
+
it "Reauthorization" do
|
192
|
+
authorize = Authorization.find("7GH53639GA425732B");
|
193
|
+
authorize.amount = { :currency => "USD", :total => "1.00" }
|
194
|
+
authorize.reauthorize()
|
195
|
+
authorize.error.should_not be_nil
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "Capture" do
|
200
|
+
before :each do
|
201
|
+
@payment = Payment.new(PaymentAttributes.merge( "intent" => "authorize" ))
|
202
|
+
@payment.create
|
203
|
+
@payment.error.should be_nil
|
204
|
+
authorize = @payment.transactions[0].related_resources[0].authorization
|
205
|
+
@capture = authorize.capture({:amount => { :currency => "USD", :total => "1.00" } })
|
206
|
+
@capture.error.should be_nil
|
207
|
+
end
|
208
|
+
|
209
|
+
it "Find" do
|
210
|
+
capture = Capture.find(@capture.id)
|
211
|
+
capture.error.should be_nil
|
212
|
+
capture.should be_a Capture
|
213
|
+
end
|
214
|
+
|
215
|
+
it "Refund" do
|
216
|
+
refund = @capture.refund({})
|
217
|
+
refund.error.should be_nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "CreditCard" do
|
222
|
+
it "Create" do
|
223
|
+
credit_card = CreditCard.new({
|
224
|
+
"type" => "visa",
|
225
|
+
"number" => "4417119669820331",
|
226
|
+
"expire_month" => "11", "expire_year" => "2018",
|
227
|
+
"cvv2" => "874",
|
228
|
+
"first_name" => "Joe", "last_name" => "Shopper",
|
229
|
+
"billing_address" => {
|
230
|
+
"line1" => "52 N Main ST",
|
231
|
+
"city" => "Johnstown",
|
232
|
+
"state" => "OH",
|
233
|
+
"postal_code" => "43210", "country_code" => "US" }})
|
234
|
+
credit_card.create
|
235
|
+
credit_card.error.should be_nil
|
236
|
+
credit_card.id.should_not be_nil
|
237
|
+
|
238
|
+
credit_card = CreditCard.find(credit_card.id)
|
239
|
+
credit_card.should be_a CreditCard
|
240
|
+
credit_card.error.should be_nil
|
241
|
+
end
|
242
|
+
|
243
|
+
it "Delete" do
|
244
|
+
credit_card = CreditCard.new({
|
245
|
+
"type" => "visa",
|
246
|
+
"number" => "4417119669820331",
|
247
|
+
"expire_month" => "11", "expire_year" => "2018" })
|
248
|
+
credit_card.create.should be_true
|
249
|
+
credit_card.delete.should be_true
|
250
|
+
end
|
251
|
+
|
252
|
+
describe "Validation" do
|
253
|
+
it "Create" do
|
254
|
+
credit_card = CreditCard.new({
|
255
|
+
"type" => "visa",
|
256
|
+
"number" => "4111111111111111" })
|
257
|
+
credit_card.create
|
258
|
+
credit_card.error.should_not be_nil
|
259
|
+
|
260
|
+
credit_card.error.name.should eql "VALIDATION_ERROR"
|
261
|
+
credit_card.error["name"].should eql "VALIDATION_ERROR"
|
262
|
+
|
263
|
+
credit_card.error.details[0].field.should eql "expire_year"
|
264
|
+
credit_card.error.details[0].issue.should eql "Required field missing"
|
265
|
+
credit_card.error.details[1].field.should eql "expire_month"
|
266
|
+
credit_card.error.details[1].issue.should eql "Required field missing"
|
267
|
+
|
268
|
+
credit_card.error["details"][0]["issue"].should eql "Required field missing"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
end
|