paypal-sdk-rest 1.7.4 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -14
- data/README.md +45 -251
- data/lib/lib.rb +88 -0
- data/lib/paypal/core/access_token.rb +20 -0
- data/lib/paypal/core/paypal_environment.rb +38 -0
- data/lib/paypal/core/paypal_http_client.rb +51 -0
- data/lib/paypal/core/token_requests.rb +40 -0
- data/lib/paypal/core/version.rb +3 -0
- data/lib/v1/billing_agreements/agreement_bill_balance_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_cancel_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_create_request.rb +33 -0
- data/lib/v1/billing_agreements/agreement_execute_request.rb +31 -0
- data/lib/v1/billing_agreements/agreement_get_request.rb +31 -0
- data/lib/v1/billing_agreements/agreement_re_activate_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_set_balance_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_suspend_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_transactions_request.rb +41 -0
- data/lib/v1/billing_agreements/agreement_update_request.rb +35 -0
- data/lib/v1/billing_plans/plan_create_request.rb +33 -0
- data/lib/v1/billing_plans/plan_get_request.rb +31 -0
- data/lib/v1/billing_plans/plan_list_request.rb +49 -0
- data/lib/v1/billing_plans/plan_update_request.rb +35 -0
- data/lib/v1/identity/user_consent.rb +45 -0
- data/lib/v1/identity/userinfo_get_request.rb +33 -0
- data/lib/v1/invoices/invoice_cancel_request.rb +35 -0
- data/lib/v1/invoices/invoice_create_request.rb +33 -0
- data/lib/v1/invoices/invoice_delete_external_payment_request.rb +33 -0
- data/lib/v1/invoices/invoice_delete_external_refund_request.rb +33 -0
- data/lib/v1/invoices/invoice_delete_request.rb +31 -0
- data/lib/v1/invoices/invoice_get_request.rb +31 -0
- data/lib/v1/invoices/invoice_list_request.rb +44 -0
- data/lib/v1/invoices/invoice_next_invoice_number_request.rb +29 -0
- data/lib/v1/invoices/invoice_qr_code_request.rb +46 -0
- data/lib/v1/invoices/invoice_record_payment_request.rb +35 -0
- data/lib/v1/invoices/invoice_record_refund_request.rb +35 -0
- data/lib/v1/invoices/invoice_remind_request.rb +35 -0
- data/lib/v1/invoices/invoice_search_request.rb +33 -0
- data/lib/v1/invoices/invoice_send_request.rb +36 -0
- data/lib/v1/invoices/invoice_update_request.rb +40 -0
- data/lib/v1/invoices/template_create_request.rb +33 -0
- data/lib/v1/invoices/template_delete_request.rb +31 -0
- data/lib/v1/invoices/template_get_request.rb +31 -0
- data/lib/v1/invoices/template_list_request.rb +34 -0
- data/lib/v1/invoices/template_update_request.rb +35 -0
- data/lib/v1/orders/orders_cancel_request.rb +31 -0
- data/lib/v1/orders/orders_create_request.rb +33 -0
- data/lib/v1/orders/orders_get_request.rb +31 -0
- data/lib/v1/orders/orders_pay_request.rb +35 -0
- data/lib/v1/payment_experience/web_profile_create_request.rb +33 -0
- data/lib/v1/payment_experience/web_profile_delete_request.rb +31 -0
- data/lib/v1/payment_experience/web_profile_get_request.rb +31 -0
- data/lib/v1/payment_experience/web_profile_list_request.rb +29 -0
- data/lib/v1/payment_experience/web_profile_partial_update_request.rb +35 -0
- data/lib/v1/payment_experience/web_profile_update_request.rb +35 -0
- data/lib/v1/payments/authorization_capture_request.rb +35 -0
- data/lib/v1/payments/authorization_get_request.rb +31 -0
- data/lib/v1/payments/authorization_reauthorize_request.rb +35 -0
- data/lib/v1/payments/authorization_void_request.rb +31 -0
- data/lib/v1/payments/capture_get_request.rb +31 -0
- data/lib/v1/payments/capture_refund_request.rb +35 -0
- data/lib/v1/payments/order_authorize_request.rb +35 -0
- data/lib/v1/payments/order_capture_request.rb +35 -0
- data/lib/v1/payments/order_get_request.rb +31 -0
- data/lib/v1/payments/order_void_request.rb +31 -0
- data/lib/v1/payments/payment_create_request.rb +33 -0
- data/lib/v1/payments/payment_execute_request.rb +35 -0
- data/lib/v1/payments/payment_get_request.rb +31 -0
- data/lib/v1/payments/payment_list_request.rb +69 -0
- data/lib/v1/payments/payment_update_request.rb +35 -0
- data/lib/v1/payments/refund_get_request.rb +31 -0
- data/lib/v1/payments/sale_get_request.rb +31 -0
- data/lib/v1/payments/sale_refund_request.rb +35 -0
- data/lib/v1/sync/search_get_request.rb +99 -0
- data/lib/v1/vault/credit_card_create_request.rb +33 -0
- data/lib/v1/vault/credit_card_delete_request.rb +31 -0
- data/lib/v1/vault/credit_card_get_request.rb +31 -0
- data/lib/v1/vault/credit_card_list_request.rb +79 -0
- data/lib/v1/vault/credit_card_update_request.rb +35 -0
- data/lib/v1/webhooks/available_event_type_list_request.rb +29 -0
- data/lib/v1/webhooks/event_get_request.rb +31 -0
- data/lib/v1/webhooks/event_list_request.rb +54 -0
- data/lib/v1/webhooks/event_resend_request.rb +35 -0
- data/lib/v1/webhooks/simulate_event_request.rb +33 -0
- data/lib/v1/webhooks/webhook_create_request.rb +33 -0
- data/lib/v1/webhooks/webhook_delete_request.rb +31 -0
- data/lib/v1/webhooks/webhook_get_request.rb +31 -0
- data/lib/v1/webhooks/webhook_list_event_subscriptions_request.rb +31 -0
- data/lib/v1/webhooks/webhook_list_request.rb +34 -0
- data/lib/v1/webhooks/webhook_update_request.rb +35 -0
- data/lib/v1/webhooks/webhook_verify_signature_request.rb +33 -0
- data/spec/integration/test_harness.rb +25 -0
- data/spec/integration/v1/billing_agreements/agreement_create_spec.rb +63 -0
- data/spec/integration/v1/billing_plans/plan_create_spec.rb +12 -0
- data/spec/integration/v1/billing_plans/plan_get_spec.rb +16 -0
- data/spec/integration/v1/billing_plans/plan_helper.rb +71 -0
- data/spec/integration/v1/billing_plans/plan_list_spec.rb +16 -0
- data/spec/integration/v1/billing_plans/plan_update_spec.rb +19 -0
- data/spec/integration/v1/identity/userinfo_get_spec.rb +65 -0
- data/spec/integration/v1/invoices/invoice_cancel_spec.rb +23 -0
- data/spec/integration/v1/invoices/invoice_create_spec.rb +15 -0
- data/spec/integration/v1/invoices/invoice_delete_external_payment_spec.rb +23 -0
- data/spec/integration/v1/invoices/invoice_delete_external_refund_spec.rb +21 -0
- data/spec/integration/v1/invoices/invoice_delete_spec.rb +16 -0
- data/spec/integration/v1/invoices/invoice_get_spec.rb +18 -0
- data/spec/integration/v1/invoices/invoice_helper.rb +171 -0
- data/spec/integration/v1/invoices/invoice_list_spec.rb +20 -0
- data/spec/integration/v1/invoices/invoice_next_invoice_number_spec.rb +14 -0
- data/spec/integration/v1/invoices/invoice_qr_code_spec.rb +18 -0
- data/spec/integration/v1/invoices/invoice_record_payment_spec.rb +14 -0
- data/spec/integration/v1/invoices/invoice_record_refund_spec.rb +14 -0
- data/spec/integration/v1/invoices/invoice_remind_spec.rb +22 -0
- data/spec/integration/v1/invoices/invoice_search_spec.rb +20 -0
- data/spec/integration/v1/invoices/invoice_send_spec.rb +15 -0
- data/spec/integration/v1/invoices/invoice_update_spec.rb +26 -0
- data/spec/integration/v1/invoices/template_create_spec.rb +14 -0
- data/spec/integration/v1/invoices/template_delete_spec.rb +15 -0
- data/spec/integration/v1/invoices/template_get_spec.rb +18 -0
- data/spec/integration/v1/invoices/template_list_spec.rb +15 -0
- data/spec/integration/v1/invoices/template_update_spec.rb +62 -0
- data/spec/integration/v1/orders/orders_cancel_spec.rb +15 -0
- data/spec/integration/v1/orders/orders_create_spec.rb +17 -0
- data/spec/integration/v1/orders/orders_get_spec.rb +18 -0
- data/spec/integration/v1/orders/orders_helper.rb +36 -0
- data/spec/integration/v1/orders/orders_pay_spec.rb +19 -0
- data/spec/integration/v1/payment_experience/pe_helper.rb +35 -0
- data/spec/integration/v1/payment_experience/web_profile_create_spec.rb +20 -0
- data/spec/integration/v1/payment_experience/web_profile_delete_spec.rb +15 -0
- data/spec/integration/v1/payment_experience/web_profile_get_spec.rb +17 -0
- data/spec/integration/v1/payment_experience/web_profile_list_spec.rb +18 -0
- data/spec/integration/v1/payment_experience/web_profile_partial_update_spec.rb +32 -0
- data/spec/integration/v1/payment_experience/web_profile_update_spec.rb +44 -0
- data/spec/integration/v1/payments/authorization_capture_spec.rb +17 -0
- data/spec/integration/v1/payments/authorization_get_spec.rb +18 -0
- data/spec/integration/v1/payments/authorization_reauthorize_spec.rb +26 -0
- data/spec/integration/v1/payments/authorization_void_spec.rb +19 -0
- data/spec/integration/v1/payments/capture_get_spec.rb +20 -0
- data/spec/integration/v1/payments/capture_refund_spec.rb +27 -0
- data/spec/integration/v1/payments/order_authorize_spec.rb +20 -0
- data/spec/integration/v1/payments/order_capture_spec.rb +21 -0
- data/spec/integration/v1/payments/order_get_spec.rb +14 -0
- data/spec/integration/v1/payments/order_void_spec.rb +14 -0
- data/spec/integration/v1/payments/payment_create_spec.rb +13 -0
- data/spec/integration/v1/payments/payment_execute_spec.rb +19 -0
- data/spec/integration/v1/payments/payment_get_spec.rb +17 -0
- data/spec/integration/v1/payments/payment_list_spec.rb +16 -0
- data/spec/integration/v1/payments/payment_update_spec.rb +28 -0
- data/spec/integration/v1/payments/payments_helper.rb +72 -0
- data/spec/integration/v1/payments/refund_get_spec.rb +19 -0
- data/spec/integration/v1/payments/sale_get_spec.rb +18 -0
- data/spec/integration/v1/payments/sale_refund_spec.rb +18 -0
- data/spec/integration/v1/sync/search_get_spec.rb +34 -0
- data/spec/integration/v1/vault/credit_card_create_spec.rb +16 -0
- data/spec/integration/v1/vault/credit_card_delete_spec.rb +16 -0
- data/spec/integration/v1/vault/credit_card_get_spec.rb +17 -0
- data/spec/integration/v1/vault/credit_card_list_spec.rb +18 -0
- data/spec/integration/v1/vault/credit_card_update_spec.rb +26 -0
- data/spec/integration/v1/vault/vault_helper.rb +28 -0
- data/spec/integration/v1/webhooks/available_event_type_list_spec.rb +16 -0
- data/spec/integration/v1/webhooks/webhook_create_spec.rb +12 -0
- data/spec/integration/v1/webhooks/webhook_delete_spec.rb +13 -0
- data/spec/integration/v1/webhooks/webhook_get_spec.rb +16 -0
- data/spec/integration/v1/webhooks/webhook_helper.rb +43 -0
- data/spec/integration/v1/webhooks/webhook_list_event_subscriptions_spec.rb +16 -0
- data/spec/integration/v1/webhooks/webhook_list_spec.rb +15 -0
- data/spec/integration/v1/webhooks/webhook_update_spec.rb +29 -0
- data/spec/integration/v1/webhooks/webhook_verify_signature_spec.rb +20 -0
- data/spec/spec_helper.rb +97 -28
- data/spec/unit/paypal_http_client_spec.rb +264 -0
- metadata +250 -120
- data/Rakefile +0 -15
- data/data/DigiCertHighAssuranceEVRootCA.pem +0 -23
- data/data/DigiCertSHA2ExtendedValidationServerCA.pem +0 -28
- data/data/paypal.crt +0 -171
- data/lib/generators/paypal/sdk/USAGE +0 -3
- data/lib/generators/paypal/sdk/install_generator.rb +0 -17
- data/lib/generators/paypal/sdk/templates/paypal.rb +0 -2
- data/lib/generators/paypal/sdk/templates/paypal.yml +0 -29
- data/lib/paypal-sdk-core.rb +0 -38
- data/lib/paypal-sdk-rest.rb +0 -2
- data/lib/paypal-sdk/core/api.rb +0 -20
- data/lib/paypal-sdk/core/api/base.rb +0 -169
- data/lib/paypal-sdk/core/api/data_types/array_with_block.rb +0 -44
- data/lib/paypal-sdk/core/api/data_types/base.rb +0 -225
- data/lib/paypal-sdk/core/api/data_types/enum.rb +0 -26
- data/lib/paypal-sdk/core/api/data_types/simple_types.rb +0 -52
- data/lib/paypal-sdk/core/api/ipn.rb +0 -66
- data/lib/paypal-sdk/core/api/rest.rb +0 -177
- data/lib/paypal-sdk/core/authentication.rb +0 -66
- data/lib/paypal-sdk/core/config.rb +0 -253
- data/lib/paypal-sdk/core/credential.rb +0 -16
- data/lib/paypal-sdk/core/credential/base.rb +0 -27
- data/lib/paypal-sdk/core/credential/certificate.rb +0 -32
- data/lib/paypal-sdk/core/credential/signature.rb +0 -22
- data/lib/paypal-sdk/core/credential/third_party/subject.rb +0 -25
- data/lib/paypal-sdk/core/credential/third_party/token.rb +0 -39
- data/lib/paypal-sdk/core/exceptions.rb +0 -112
- data/lib/paypal-sdk/core/logging.rb +0 -50
- data/lib/paypal-sdk/core/openid_connect.rb +0 -140
- data/lib/paypal-sdk/core/openid_connect/api.rb +0 -50
- data/lib/paypal-sdk/core/openid_connect/data_types.rb +0 -73
- data/lib/paypal-sdk/core/openid_connect/get_api.rb +0 -28
- data/lib/paypal-sdk/core/openid_connect/request_data_type.rb +0 -52
- data/lib/paypal-sdk/core/openid_connect/set_api.rb +0 -36
- data/lib/paypal-sdk/core/util.rb +0 -11
- data/lib/paypal-sdk/core/util/http_helper.rb +0 -171
- data/lib/paypal-sdk/core/util/oauth_signature.rb +0 -64
- data/lib/paypal-sdk/core/util/ordered_hash.rb +0 -165
- data/lib/paypal-sdk/rest.rb +0 -39
- data/lib/paypal-sdk/rest/api.rb +0 -23
- data/lib/paypal-sdk/rest/data_types.rb +0 -2597
- data/lib/paypal-sdk/rest/error_hash.rb +0 -39
- data/lib/paypal-sdk/rest/get_api.rb +0 -20
- data/lib/paypal-sdk/rest/request_data_type.rb +0 -53
- data/lib/paypal-sdk/rest/set_api.rb +0 -42
- data/lib/paypal-sdk/rest/version.rb +0 -7
- data/spec/README.md +0 -22
- data/spec/config/cacert.pem +0 -171
- data/spec/config/cert_key.pem +0 -33
- data/spec/config/paypal.yml +0 -35
- data/spec/config/sample_data.yml +0 -3
- data/spec/core/api/data_type_spec.rb +0 -289
- data/spec/core/api/rest_spec.rb +0 -211
- data/spec/core/config_spec.rb +0 -192
- data/spec/core/logging_spec.rb +0 -28
- data/spec/core/openid_connect_spec.rb +0 -153
- data/spec/invoice_examples_spec.rb +0 -38
- data/spec/payments_examples_spec.rb +0 -437
- data/spec/payouts_examples_spec.rb +0 -74
- data/spec/rest/data_types_spec.rb +0 -62
- data/spec/rest/error_hash_spec.rb +0 -83
- data/spec/subscription_examples_spec.rb +0 -227
- data/spec/support/sample_data.rb +0 -5
- data/spec/web_profile_examples_spec.rb +0 -106
- data/spec/webhooks_examples_spec.rb +0 -93
data/spec/core/api/rest_spec.rb
DELETED
@@ -1,211 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PayPal::SDK::Core::API::REST do
|
4
|
-
|
5
|
-
module PayPalRest
|
6
|
-
class API < PayPal::SDK::Core::API::REST
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def create_api(*args)
|
11
|
-
api = PayPalRest::API.new(*args)
|
12
|
-
@log_file ||= File.open("spec/log/rest_http.log", "w")
|
13
|
-
api.http.set_debug_output(@log_file)
|
14
|
-
api
|
15
|
-
end
|
16
|
-
|
17
|
-
before :all do
|
18
|
-
@api = create_api("v1/payments/", :with_authentication)
|
19
|
-
@vault_api = create_api("v1/vault/", :with_authentication)
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "Configuration" do
|
23
|
-
it "create api with prefix" do
|
24
|
-
api = create_api("v1/payments")
|
25
|
-
expect(api.uri.path).to eql "/v1/payments"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "service endpoint for sandbox" do
|
29
|
-
api = create_api
|
30
|
-
expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
|
31
|
-
expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
|
32
|
-
api = create_api( :mode => "sandbox" )
|
33
|
-
expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
|
34
|
-
expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
|
35
|
-
api = create_api( :mode => :sandbox )
|
36
|
-
expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
|
37
|
-
expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
|
38
|
-
api = create_api( :mode => "invalid" )
|
39
|
-
expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
|
40
|
-
expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
|
41
|
-
api = create_api( :mode => nil )
|
42
|
-
expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
|
43
|
-
expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "service endpoint for live" do
|
47
|
-
api = create_api( :mode => "live" )
|
48
|
-
expect(api.service_endpoint).to eql "https://api.paypal.com"
|
49
|
-
expect(api.token_endpoint).to eql "https://api.paypal.com"
|
50
|
-
api = create_api( :mode => :live )
|
51
|
-
expect(api.service_endpoint).to eql "https://api.paypal.com"
|
52
|
-
expect(api.token_endpoint).to eql "https://api.paypal.com"
|
53
|
-
end
|
54
|
-
|
55
|
-
it "override service endpoint" do
|
56
|
-
api = create_api( :rest_endpoint => "https://testing.api.paypal.com" )
|
57
|
-
expect(api.service_endpoint).to eql "https://testing.api.paypal.com"
|
58
|
-
expect(api.token_endpoint).to eql "https://testing.api.paypal.com"
|
59
|
-
api = create_api( :endpoint => "https://testing.api.paypal.com" )
|
60
|
-
expect(api.service_endpoint).to eql "https://testing.api.paypal.com"
|
61
|
-
expect(api.token_endpoint).to eql "https://testing.api.paypal.com"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "override token endpoint" do
|
65
|
-
api = create_api( :rest_token_endpoint => "https://testing.api.paypal.com" )
|
66
|
-
expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
|
67
|
-
expect(api.token_endpoint).to eql "https://testing.api.paypal.com"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "Validation" do
|
72
|
-
it "Invalid client_id and client_secret" do
|
73
|
-
api = create_api(:with_authentication, :client_id => "XYZ", :client_secret => "ABC")
|
74
|
-
expect {
|
75
|
-
api.token
|
76
|
-
}.to raise_error PayPal::SDK::Core::Exceptions::UnauthorizedAccess
|
77
|
-
end
|
78
|
-
|
79
|
-
it "Should handle expired token" do
|
80
|
-
old_token = @api.token
|
81
|
-
@api.token_hash[:expires_in] = 0
|
82
|
-
new_token = @api.token
|
83
|
-
expect(@api.token_hash[:expires_in]).not_to eql 0
|
84
|
-
end
|
85
|
-
|
86
|
-
it "Get token" do
|
87
|
-
expect(@api.token).not_to be_nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "Success request", :integration => true do
|
92
|
-
|
93
|
-
it "Create Payment" do
|
94
|
-
response = @api.post("payment", {
|
95
|
-
"intent" => "sale",
|
96
|
-
"payer" => {
|
97
|
-
"payment_method" => "credit_card",
|
98
|
-
"funding_instruments" => [{
|
99
|
-
"credit_card" => {
|
100
|
-
"type" => "visa",
|
101
|
-
"number" => "4567516310777851",
|
102
|
-
"expire_month" => "11", "expire_year" => "2018",
|
103
|
-
"first_name" => "Joe", "last_name" => "Shopper" }}]},
|
104
|
-
"transactions" => [{
|
105
|
-
"amount" => {
|
106
|
-
"total" => "7.47",
|
107
|
-
"currency" => "USD" }}]})
|
108
|
-
expect(response["error"]).to be_nil
|
109
|
-
end
|
110
|
-
|
111
|
-
it "List Payments" do
|
112
|
-
response = @api.get("payment", { "count" => 10 })
|
113
|
-
expect(response["error"]).to be_nil
|
114
|
-
expect(response["count"]).not_to be_nil
|
115
|
-
end
|
116
|
-
|
117
|
-
it "Execute Payment"
|
118
|
-
|
119
|
-
it "Create FundingInstrument" do
|
120
|
-
new_funding_instrument = @vault_api.post("credit-card", {
|
121
|
-
"type" => "visa",
|
122
|
-
"number" => "4111111111111111",
|
123
|
-
"expire_month" => "11", "expire_year" => "2018",
|
124
|
-
"cvv2" => "874",
|
125
|
-
"first_name" => "Joe", "last_name" => "Shopper" })
|
126
|
-
expect(new_funding_instrument["error"]).to be_nil
|
127
|
-
expect(new_funding_instrument["id"]).not_to be_nil
|
128
|
-
|
129
|
-
funding_instrument = @vault_api.get("credit-card/#{new_funding_instrument["id"]}")
|
130
|
-
expect(funding_instrument["error"]).to be_nil
|
131
|
-
expect(funding_instrument["id"]).to eql new_funding_instrument["id"]
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
describe "Failure request", :integration => true do
|
137
|
-
it "Invalid Resource ID" do
|
138
|
-
expect {
|
139
|
-
response = @api.get("payment/PAY-1234")
|
140
|
-
}.to raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
|
141
|
-
end
|
142
|
-
|
143
|
-
it "Invalid parameters" do
|
144
|
-
response = @api.post("payment")
|
145
|
-
expect(response["error"]["name"]).to eql "VALIDATION_ERROR"
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "format response" do
|
150
|
-
before :each do
|
151
|
-
@response = instance_double(Net::HTTPResponse)
|
152
|
-
allow(@response).to receive(:code) { "200" }
|
153
|
-
allow(@response).to receive(:content_type) { "application/json" }
|
154
|
-
end
|
155
|
-
|
156
|
-
it "parses empty object JSON correctly" do
|
157
|
-
allow(@response).to receive(:body) { "{}" }
|
158
|
-
payload = {
|
159
|
-
:response => @response
|
160
|
-
}
|
161
|
-
|
162
|
-
formatted_response = @api.format_response(payload)
|
163
|
-
expect(formatted_response).to_not be_nil
|
164
|
-
expect(formatted_response[:data]).to eq({})
|
165
|
-
end
|
166
|
-
|
167
|
-
it "parses empty string JSON correctly" do
|
168
|
-
allow(@response).to receive(:body) { '""' }
|
169
|
-
payload = {
|
170
|
-
:response => @response
|
171
|
-
}
|
172
|
-
|
173
|
-
formatted_response = @api.format_response(payload)
|
174
|
-
expect(formatted_response).to_not be_nil
|
175
|
-
expect(formatted_response[:data]).to eq("")
|
176
|
-
end
|
177
|
-
|
178
|
-
it "parses whitespace body correctly" do
|
179
|
-
allow(@response).to receive(:body) { ' ' }
|
180
|
-
payload = {
|
181
|
-
:response => @response
|
182
|
-
}
|
183
|
-
|
184
|
-
formatted_response = @api.format_response(payload)
|
185
|
-
expect(formatted_response).to_not be_nil
|
186
|
-
expect(formatted_response[:data]).to eq({})
|
187
|
-
end
|
188
|
-
|
189
|
-
it "parses nil body correctly" do
|
190
|
-
allow(@response).to receive(:body) { nil }
|
191
|
-
payload = {
|
192
|
-
:response => @response
|
193
|
-
}
|
194
|
-
|
195
|
-
formatted_response = @api.format_response(payload)
|
196
|
-
expect(formatted_response).to_not be_nil
|
197
|
-
expect(formatted_response[:data]).to eq({})
|
198
|
-
end
|
199
|
-
|
200
|
-
it "parses with whitespace around JSON correctly" do
|
201
|
-
allow(@response).to receive(:body) { ' { "test": "value" } ' }
|
202
|
-
payload = {
|
203
|
-
:response => @response
|
204
|
-
}
|
205
|
-
|
206
|
-
formatted_response = @api.format_response(payload)
|
207
|
-
expect(formatted_response).to_not be_nil
|
208
|
-
expect(formatted_response[:data]).to eq({ "test" => "value" })
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
data/spec/core/config_spec.rb
DELETED
@@ -1,192 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PayPal::SDK::Core::Config do
|
4
|
-
|
5
|
-
Config = PayPal::SDK::Core::Config
|
6
|
-
|
7
|
-
it "load configuration file and default environment" do
|
8
|
-
expect {
|
9
|
-
Config.load("spec/config/paypal.yml", "test")
|
10
|
-
expect(Config.default_environment).to eql "test"
|
11
|
-
}.not_to raise_error
|
12
|
-
end
|
13
|
-
|
14
|
-
it "Set default environment" do
|
15
|
-
begin
|
16
|
-
backup_default_environment = Config.default_environment
|
17
|
-
Config.default_environment = "new_env"
|
18
|
-
expect(Config.default_environment).to eql "new_env"
|
19
|
-
ensure
|
20
|
-
Config.default_environment = backup_default_environment
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "Set configurations" do
|
25
|
-
begin
|
26
|
-
backup_configurations = Config.configurations
|
27
|
-
Config.configurations = { Config.default_environment => { :username => "direct", :password => "direct" } }
|
28
|
-
expect(Config.config.username).to eql "direct"
|
29
|
-
expect(Config.config.password).to eql "direct"
|
30
|
-
expect(Config.config.signature).to be_nil
|
31
|
-
ensure
|
32
|
-
Config.configurations = backup_configurations
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "Configure with parameters" do
|
37
|
-
begin
|
38
|
-
backup_configurations = Config.configurations
|
39
|
-
Config.configurations = nil
|
40
|
-
Config.configure( :username => "Testing" )
|
41
|
-
expect(Config.config.username).to eql "Testing"
|
42
|
-
expect(Config.config.app_id).to be_nil
|
43
|
-
ensure
|
44
|
-
Config.configurations = backup_configurations
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "Configure with block" do
|
49
|
-
begin
|
50
|
-
backup_configurations = Config.configurations
|
51
|
-
Config.configurations = nil
|
52
|
-
Config.configure do |config|
|
53
|
-
config.username = "Testing"
|
54
|
-
end
|
55
|
-
expect(Config.config.username).to eql "Testing"
|
56
|
-
expect(Config.config.app_id).to be_nil
|
57
|
-
ensure
|
58
|
-
Config.configurations = backup_configurations
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "Configure with default values" do
|
63
|
-
begin
|
64
|
-
backup_configurations = Config.configurations
|
65
|
-
default_config = Config.config
|
66
|
-
Config.configure do |config|
|
67
|
-
config.username = "Testing"
|
68
|
-
end
|
69
|
-
expect(Config.config.username).to eql "Testing"
|
70
|
-
expect(Config.config.app_id).not_to be_nil
|
71
|
-
expect(Config.config.app_id).to eql default_config.app_id
|
72
|
-
ensure
|
73
|
-
Config.configurations = backup_configurations
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
it "validate configuration" do
|
78
|
-
config = Config.new( :username => "XYZ")
|
79
|
-
expect {
|
80
|
-
config.required!(:username)
|
81
|
-
}.not_to raise_error
|
82
|
-
expect {
|
83
|
-
config.required!(:password)
|
84
|
-
}.to raise_error "Required configuration(password)"
|
85
|
-
expect {
|
86
|
-
config.required!(:username, :password)
|
87
|
-
}.to raise_error "Required configuration(password)"
|
88
|
-
expect {
|
89
|
-
config.required!(:password, :signature)
|
90
|
-
}.to raise_error "Required configuration(password, signature)"
|
91
|
-
end
|
92
|
-
|
93
|
-
it "return default environment configuration" do
|
94
|
-
expect(Config.config).to be_a Config
|
95
|
-
end
|
96
|
-
|
97
|
-
it "return configuration based on environment" do
|
98
|
-
expect(Config.config(:development)).to be_a Config
|
99
|
-
end
|
100
|
-
|
101
|
-
it "override default configuration" do
|
102
|
-
override_configuration = { :username => "test.example.com", :app_id => "test"}
|
103
|
-
config = Config.config(override_configuration)
|
104
|
-
|
105
|
-
expect(config.username).to eql(override_configuration[:username])
|
106
|
-
expect(config.app_id).to eql(override_configuration[:app_id])
|
107
|
-
end
|
108
|
-
|
109
|
-
it "get cached config" do
|
110
|
-
expect(Config.config(:test)).to eql Config.config(:test)
|
111
|
-
expect(Config.config(:test)).not_to eql Config.config(:development)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should raise error on invalid environment" do
|
115
|
-
expect {
|
116
|
-
Config.config(:invalid_env)
|
117
|
-
}.to raise_error "Configuration[invalid_env] NotFound"
|
118
|
-
end
|
119
|
-
|
120
|
-
it "set logger" do
|
121
|
-
require 'logger'
|
122
|
-
my_logger = Logger.new(STDERR)
|
123
|
-
Config.logger = my_logger
|
124
|
-
expect(Config.logger).to eql my_logger
|
125
|
-
end
|
126
|
-
|
127
|
-
it "Access PayPal::SDK methods" do
|
128
|
-
expect(PayPal::SDK.configure).to eql PayPal::SDK::Core::Config.config
|
129
|
-
expect(PayPal::SDK.logger).to eql PayPal::SDK::Core::Config.logger
|
130
|
-
PayPal::SDK.logger = PayPal::SDK.logger
|
131
|
-
expect(PayPal::SDK.logger).to eql PayPal::SDK::Core::Config.logger
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "include Configuration" do
|
135
|
-
class TestConfig
|
136
|
-
include PayPal::SDK::Core::Configuration
|
137
|
-
end
|
138
|
-
|
139
|
-
it "Get default configuration" do
|
140
|
-
test_object = TestConfig.new
|
141
|
-
expect(test_object.config).to be_a Config
|
142
|
-
end
|
143
|
-
|
144
|
-
it "Change environment" do
|
145
|
-
test_object = TestConfig.new
|
146
|
-
test_object.set_config("test")
|
147
|
-
expect(test_object.config).to eql Config.config("test")
|
148
|
-
expect(test_object.config).not_to eql Config.config("development")
|
149
|
-
end
|
150
|
-
|
151
|
-
it "Override environment configuration" do
|
152
|
-
test_object = TestConfig.new
|
153
|
-
test_object.set_config("test", :username => "test")
|
154
|
-
expect(test_object.config).not_to eql Config.config("test")
|
155
|
-
end
|
156
|
-
|
157
|
-
it "Override default/current configuration" do
|
158
|
-
test_object = TestConfig.new
|
159
|
-
test_object.set_config( :username => "test")
|
160
|
-
expect(test_object.config.username).to eql "test"
|
161
|
-
test_object.set_config( :password => "test")
|
162
|
-
expect(test_object.config.password).to eql "test"
|
163
|
-
expect(test_object.config.username).to eql "test"
|
164
|
-
end
|
165
|
-
|
166
|
-
it "Append ssl_options" do
|
167
|
-
test_object = TestConfig.new
|
168
|
-
test_object.set_config( :ssl_options => { :ca_file => "test_path" } )
|
169
|
-
expect(test_object.config.ssl_options[:ca_file]).to eql "test_path"
|
170
|
-
test_object.set_config( :ssl_options => { :verify_mode => 1 } )
|
171
|
-
expect(test_object.config.ssl_options[:verify_mode]).to eql 1
|
172
|
-
expect(test_object.config.ssl_options[:ca_file]).to eql "test_path"
|
173
|
-
end
|
174
|
-
|
175
|
-
it "Set configuration without loading configuration File" do
|
176
|
-
backup_configurations = Config.configurations
|
177
|
-
begin
|
178
|
-
Config.configurations = nil
|
179
|
-
test_object = TestConfig.new
|
180
|
-
expect {
|
181
|
-
test_object.config
|
182
|
-
}.to raise_error
|
183
|
-
test_object.set_config( :username => "test" )
|
184
|
-
expect(test_object.config).to be_a Config
|
185
|
-
ensure
|
186
|
-
Config.configurations = backup_configurations
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
end
|
data/spec/core/logging_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'stringio'
|
3
|
-
|
4
|
-
describe PayPal::SDK::Core::Logging do
|
5
|
-
Logging = PayPal::SDK::Core::Logging
|
6
|
-
|
7
|
-
class TestLogging
|
8
|
-
include Logging
|
9
|
-
end
|
10
|
-
|
11
|
-
before :each do
|
12
|
-
@logger_file = StringIO.new
|
13
|
-
Logging.logger = Logger.new(@logger_file)
|
14
|
-
@test_logging = TestLogging.new
|
15
|
-
end
|
16
|
-
|
17
|
-
it "get logger object" do
|
18
|
-
expect(@test_logging.logger).to be_a Logger
|
19
|
-
end
|
20
|
-
|
21
|
-
it "write message to logger" do
|
22
|
-
test_message = "Example log message!!!"
|
23
|
-
@test_logging.logger.info(test_message)
|
24
|
-
@logger_file.rewind
|
25
|
-
expect(@logger_file.read).to match test_message
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PayPal::SDK::OpenIDConnect do
|
4
|
-
OpenIDConnect = PayPal::SDK::OpenIDConnect
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
OpenIDConnect.set_config( :client_id => "client_id", :openid_redirect_uri => "http://google.com" )
|
8
|
-
end
|
9
|
-
|
10
|
-
it "Validate user_agent" do
|
11
|
-
expect(OpenIDConnect::API.user_agent).to match "PayPalSDK/openid-connect-ruby"
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "generate_authorize_url" do
|
15
|
-
|
16
|
-
it "generate autorize_url" do
|
17
|
-
url = OpenIDConnect::Tokeninfo.authorize_url
|
18
|
-
expect(url).to match "client_id=client_id"
|
19
|
-
expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://google.com")}")
|
20
|
-
expect(url).to match "scope=openid"
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "sandbox" do
|
24
|
-
before do
|
25
|
-
PayPal::SDK.configure(:mode => "sandbox")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "generates a sandbox authorize url" do
|
29
|
-
url = OpenIDConnect::Tokeninfo.authorize_url
|
30
|
-
expect(url).to match "sandbox.paypal.com"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "Override authorize_url params" do
|
36
|
-
url = OpenIDConnect.authorize_url(
|
37
|
-
:client_id => "new_client_id",
|
38
|
-
:redirect_uri => "http://example.com",
|
39
|
-
:scope => "openid profile")
|
40
|
-
expect(url).to match "client_id=new_client_id"
|
41
|
-
expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://example.com")}")
|
42
|
-
expect(url).to match Regexp.escape("scope=#{CGI.escape("openid profile")}")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "Generate logout_url" do
|
46
|
-
url = OpenIDConnect.logout_url
|
47
|
-
expect(url).to match "logout=true"
|
48
|
-
expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://google.com")}")
|
49
|
-
expect(url).not_to match "id_token"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "Override logout_url params" do
|
53
|
-
url = OpenIDConnect.logout_url({
|
54
|
-
:redirect_uri => "http://example.com",
|
55
|
-
:id_token => "testing" })
|
56
|
-
expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://example.com")}")
|
57
|
-
expect(url).to match "id_token=testing"
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "Validation" do
|
61
|
-
it "Create token" do
|
62
|
-
expect{
|
63
|
-
tokeninfo = OpenIDConnect::Tokeninfo.create("invalid-autorize-code")
|
64
|
-
}.to raise_error PayPal::SDK::Core::Exceptions::BadRequest
|
65
|
-
end
|
66
|
-
|
67
|
-
it "Refresh token" do
|
68
|
-
expect{
|
69
|
-
tokeninfo = OpenIDConnect::Tokeninfo.refresh("invalid-refresh-token")
|
70
|
-
}.to raise_error PayPal::SDK::Core::Exceptions::BadRequest
|
71
|
-
end
|
72
|
-
|
73
|
-
it "Get userinfo" do
|
74
|
-
expect{
|
75
|
-
userinfo = OpenIDConnect::Userinfo.get("invalid-access-token")
|
76
|
-
}.to raise_error PayPal::SDK::Core::Exceptions::UnauthorizedAccess
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "Tokeninfo" do
|
81
|
-
before do
|
82
|
-
@tokeninfo = OpenIDConnect::Tokeninfo.new( :access_token => "test_access_token",
|
83
|
-
:refresh_token => "test_refresh_token",
|
84
|
-
:id_token => "test_id_token" )
|
85
|
-
end
|
86
|
-
|
87
|
-
it "create" do
|
88
|
-
allow(OpenIDConnect::Tokeninfo.api).to receive_messages( :post => { :access_token => "access_token" } )
|
89
|
-
tokeninfo = OpenIDConnect::Tokeninfo.create("authorize_code")
|
90
|
-
expect(tokeninfo).to be_a OpenIDConnect::Tokeninfo
|
91
|
-
expect(tokeninfo.access_token).to eql "access_token"
|
92
|
-
end
|
93
|
-
|
94
|
-
it "refresh" do
|
95
|
-
allow(@tokeninfo.api).to receive_messages( :post => { :access_token => "new_access_token" } )
|
96
|
-
expect(@tokeninfo.access_token).to eql "test_access_token"
|
97
|
-
@tokeninfo.refresh
|
98
|
-
expect(@tokeninfo.access_token).to eql "new_access_token"
|
99
|
-
end
|
100
|
-
|
101
|
-
it "userinfo" do
|
102
|
-
allow(@tokeninfo.api).to receive_messages( :post => { :name => "Testing" } )
|
103
|
-
userinfo = @tokeninfo.userinfo
|
104
|
-
expect(userinfo).to be_a OpenIDConnect::Userinfo
|
105
|
-
expect(userinfo.name).to eql "Testing"
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "logout_url" do
|
109
|
-
it "Generate logout_url" do
|
110
|
-
url = @tokeninfo.logout_url
|
111
|
-
expect(url).to match "id_token=test_id_token"
|
112
|
-
expect(url).to match "logout=true"
|
113
|
-
expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://google.com")}")
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "sandbox" do
|
117
|
-
before do
|
118
|
-
PayPal::SDK.configure(:mode => "sandbox")
|
119
|
-
end
|
120
|
-
|
121
|
-
it "generates a sandbox logout url" do
|
122
|
-
url = @tokeninfo.logout_url
|
123
|
-
expect(url).to match "sandbox.paypal.com"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "Userinfo" do
|
130
|
-
it "get" do
|
131
|
-
allow(OpenIDConnect::Userinfo.api).to receive_messages( :post => { :name => "Testing" } )
|
132
|
-
|
133
|
-
userinfo = OpenIDConnect::Userinfo.get("access_token")
|
134
|
-
userinfo = OpenIDConnect::Userinfo.new( { :name => "Testing" } )
|
135
|
-
expect(userinfo).to be_a OpenIDConnect::Userinfo
|
136
|
-
expect(userinfo.name).to eql "Testing"
|
137
|
-
|
138
|
-
userinfo = OpenIDConnect::Userinfo.get( :access_token => "access_token" )
|
139
|
-
expect(userinfo).to be_a OpenIDConnect::Userinfo
|
140
|
-
expect(userinfo.name).to eql "Testing"
|
141
|
-
end
|
142
|
-
|
143
|
-
it "get", :integration => true do
|
144
|
-
api = PayPal::SDK::REST::API.new
|
145
|
-
access_token = api.token_hash()
|
146
|
-
userinfo = OpenIDConnect::Userinfo.get( access_token )
|
147
|
-
expect(userinfo).to be_a OpenIDConnect::Userinfo
|
148
|
-
expect(userinfo.email).to eql "jaypatel512-facilitator@hotmail.com"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
|
-
end
|