paypal-sdk-rest 1.7.3 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +5 -14
- data/README.md +48 -243
- data/lib/lib.rb +95 -0
- data/lib/paypal-sdk-rest.rb +1 -2
- 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 +52 -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/customer_disputes/dispute_accept_claim_request.rb +35 -0
- data/lib/v1/customer_disputes/dispute_adjudicate_request.rb +35 -0
- data/lib/v1/customer_disputes/dispute_appeal_request.rb +35 -0
- data/lib/v1/customer_disputes/dispute_get_request.rb +31 -0
- data/lib/v1/customer_disputes/dispute_list_request.rb +59 -0
- data/lib/v1/customer_disputes/dispute_provide_evidence_request.rb +35 -0
- data/lib/v1/customer_disputes/dispute_require_evidence_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 +35 -0
- data/lib/v1/payments/capture_get_request.rb +31 -0
- data/lib/v1/payments/capture_refund_request.rb +39 -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 +35 -0
- data/lib/v1/payments/payment_create_request.rb +37 -0
- data/lib/v1/payments/payment_execute_request.rb +43 -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 +39 -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 +69 -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/customer_disputes/dispute_accept_claim_spec.rb +26 -0
- data/spec/integration/v1/customer_disputes/dispute_adjudicate_spec.rb +24 -0
- data/spec/integration/v1/customer_disputes/dispute_appeal_spec.rb +33 -0
- data/spec/integration/v1/customer_disputes/dispute_get_spec.rb +19 -0
- data/spec/integration/v1/customer_disputes/dispute_list_spec.rb +17 -0
- data/spec/integration/v1/customer_disputes/dispute_provide_evidence_spec.rb +32 -0
- data/spec/integration/v1/customer_disputes/dispute_require_evidence_spec.rb +24 -0
- data/spec/integration/v1/customer_disputes/test_image.png +0 -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 +78 -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 +42 -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/log/http.log +0 -0
- data/spec/log/rest_http.log +0 -0
- data/spec/spec_helper.rb +98 -26
- data/spec/unit/paypal_http_client_spec.rb +272 -0
- metadata +277 -119
- 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/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 -2596
- 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 -49
- 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
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../../test_harness'
|
2
|
+
require_relative './webhook_helper'
|
3
|
+
|
4
|
+
include PayPal::V1::Webhooks
|
5
|
+
|
6
|
+
describe WebhookUpdateRequest do
|
7
|
+
def build_request_body
|
8
|
+
return JSON.parse('{"from":"JTZh8uy7C 4idz4I","op":"hFua8SzJ27wJPh1KUgw","path":"xPyhuQ0fuQzyeKz","value":{}}')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'successfully makes a request' do
|
12
|
+
create_resp = WebhookHelper::create_webhook
|
13
|
+
|
14
|
+
url = 'https://example.com/new'
|
15
|
+
request = WebhookUpdateRequest.new(create_resp.result.id)
|
16
|
+
request.request_body([{
|
17
|
+
:op => 'replace',
|
18
|
+
:path => '/url',
|
19
|
+
:value => url
|
20
|
+
}])
|
21
|
+
|
22
|
+
resp = TestHarness::client.execute(request)
|
23
|
+
expect(resp.status_code).to eq(200)
|
24
|
+
expect(resp.result).not_to be_nil
|
25
|
+
|
26
|
+
get_resp = TestHarness::exec(WebhookGetRequest.new(create_resp.result.id))
|
27
|
+
expect(get_resp.result.url).to eq('https://example.com/new')
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../../test_harness'
|
2
|
+
require_relative './webhook_helper'
|
3
|
+
|
4
|
+
|
5
|
+
include PayPal::V1::Webhooks
|
6
|
+
|
7
|
+
describe WebhookVerifySignatureRequest do
|
8
|
+
def build_request_body
|
9
|
+
return JSON.parse('{ "transmission_id": "d938e770-8046-11e6-8103-6b62a8a99ac4", "transmission_time": "2016-09-21T22:00:46Z", "cert_url": "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-a5cafa77", "auth_algo": "SHA256withRSA", "transmission_sig": "eDOnWUj9FXOnr2naQnrdL7bhgejVSTwRbwbJ0kuk5wAtm2ZYkr7w5BSUDO7e5ZOsqLwN3sPn3RV85Jd9pjHuTlpuXDLYk+l5qiViPbaaC0tLV+8C/zbDjg2WCfvtf2NmFT8CHgPPQAByUqiiTY+RJZPPQC5np7j7WuxcegsJLeWStRAofsDLiSKrzYV3CKZYtNoNnRvYmSFMkYp/5vk4xGcQLeYNV1CC2PyqraZj8HGG6Y+KV4trhreV9VZDn+rPtLDZTbzUohie1LpEy31k2dg+1szpWaGYOz+MRb40U04oD7fD69vghCrDTYs5AsuFM2+WZtsMDmYGI0pxLjn2yw==", "webhook_id": "1JE4291016473214C", "webhook_event": { "id": "WH-9UG43882HX7271132-6E0871324L7949614", "event_version": "1.0", "create_time": "2016-09-21T22:00:45Z", "resource_type": "sale", "event_type": "PAYMENT.SALE.COMPLETED", "summary": "Payment completed for $ 21.0 USD", "resource": { "id": "80F85758S3080410K", "state": "completed", "amount": { "total": "21.00", "currency": "USD", "details": { "subtotal": "17.50", "tax": "1.30", "shipping": "2.20" } }, "payment_mode": "INSTANT_TRANSFER", "protection_eligibility": "ELIGIBLE", "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE", "transaction_fee": { "value": "0.91", "currency": "USD" }, "invoice_number": "57e3028db8d1b", "custom": "", "parent_payment": "PAY-7F371669SL612941HK7RQFDQ", "create_time": "2016-09-21T21:59:02Z", "update_time": "2016-09-21T22:00:06Z", "links": [{ "href": "https://api.sandbox.paypal.com/v1/payments/sale/80F85758S3080410K", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/80F85758S3080410K/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7F371669SL612941HK7RQFDQ", "rel": "parent_payment", "method": "GET" }] }, "links": [{ "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9UG43882HX7271132-6E0871324L7949614", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9UG43882HX7271132-6E0871324L7949614/resend", "rel": "resend", "method": "POST" }] } }')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'successfully makes a request' do
|
13
|
+
request = WebhookVerifySignatureRequest.new()
|
14
|
+
request.request_body(build_request_body)
|
15
|
+
|
16
|
+
resp = TestHarness::client.execute(request)
|
17
|
+
expect(resp.status_code).to eq(200)
|
18
|
+
expect(resp.result).not_to be_nil
|
19
|
+
end
|
20
|
+
end
|
data/spec/log/http.log
ADDED
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,37 +1,109 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
require_relative "../lib/lib.rb"
|
2
|
+
require 'pp'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
8
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
9
|
+
# files.
|
10
|
+
#
|
11
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
12
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
13
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
14
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
15
|
+
# a separate helper file that requires the additional dependencies and performs
|
16
|
+
# the additional setup, and require it from the spec files that actually need
|
17
|
+
# it.
|
18
|
+
#
|
19
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
20
|
+
# users commonly want.
|
21
|
+
#
|
22
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
23
|
+
RSpec.configure do |config|
|
24
|
+
# rspec-expectations config goes here. You can use an alternate
|
25
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
26
|
+
# assertions if you prefer.
|
27
|
+
config.expect_with :rspec do |expectations|
|
28
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
29
|
+
# and `failure_message` of custom matchers include text for helper methods
|
30
|
+
# defined using `chain`, e.g.:
|
31
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
32
|
+
# # => "be bigger than 2 and smaller than 4"
|
33
|
+
# ...rather than:
|
34
|
+
# # => "be bigger than 2"
|
35
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
9
36
|
end
|
10
|
-
end
|
11
37
|
|
12
|
-
|
13
|
-
|
38
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
39
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
40
|
+
config.mock_with :rspec do |mocks|
|
41
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
42
|
+
# a real object. This is generally recommended, and will default to
|
43
|
+
# `true` in RSpec 4.
|
44
|
+
mocks.verify_partial_doubles = true
|
45
|
+
end
|
14
46
|
|
15
|
-
|
47
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
48
|
+
# have no way to turn it off -- the option exists only for backwards
|
49
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
50
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
51
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
52
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
16
53
|
|
17
|
-
|
18
|
-
|
54
|
+
# The settings below are suggested to provide a good initial experience
|
55
|
+
# with RSpec, but feel free to customize to your heart's content.
|
56
|
+
=begin
|
57
|
+
# This allows you to limit a spec run to individual examples or groups
|
58
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
59
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
60
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
61
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
62
|
+
config.filter_run_when_matching :focus
|
19
63
|
|
20
|
-
|
21
|
-
|
22
|
-
|
64
|
+
# Allows RSpec to persist some state between runs in order to support
|
65
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
66
|
+
# you configure your source control system to ignore this file.
|
67
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
23
68
|
|
24
|
-
|
69
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
70
|
+
# recommended. For more details, see:
|
71
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
72
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
73
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
74
|
+
config.disable_monkey_patching!
|
25
75
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
76
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
77
|
+
# be too noisy due to issues in dependencies.
|
78
|
+
config.warnings = true
|
29
79
|
|
30
|
-
RSpec
|
31
|
-
|
32
|
-
|
33
|
-
config.
|
34
|
-
|
80
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
81
|
+
# file, and it's useful to allow more verbose output when running an
|
82
|
+
# individual spec file.
|
83
|
+
if config.files_to_run.one?
|
84
|
+
# Use the documentation formatter for detailed output,
|
85
|
+
# unless a formatter has already been configured
|
86
|
+
# (e.g. via a command-line flag).
|
87
|
+
config.default_formatter = 'doc'
|
88
|
+
end
|
89
|
+
|
90
|
+
# Print the 10 slowest examples and example groups at the
|
91
|
+
# end of the spec run, to help surface which specs are running
|
92
|
+
# particularly slow.
|
93
|
+
config.profile_examples = 10
|
94
|
+
|
95
|
+
# Run specs in random order to surface order dependencies. If you find an
|
96
|
+
# order dependency and want to debug it, you can fix the order by providing
|
97
|
+
# the seed, which is printed after each run.
|
98
|
+
# --seed 1234
|
99
|
+
config.order = :random
|
100
|
+
|
101
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
102
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
103
|
+
# test failures related to randomization by passing the same `--seed` value
|
104
|
+
# as the one that triggered the failure.
|
105
|
+
Kernel.srand config.seed
|
106
|
+
=end
|
35
107
|
end
|
36
108
|
|
37
109
|
WebMock.allow_net_connect!
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require_relative '../../lib/paypal/core/version'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
include WebMock::API
|
5
|
+
|
6
|
+
describe PayPal::PayPalHttpClient do
|
7
|
+
before do
|
8
|
+
WebMock.disable!
|
9
|
+
@environment = PayPal::SandboxEnvironment.new('clientId', 'clientSecret')
|
10
|
+
@httpClient = PayPal::PayPalHttpClient.new(@environment)
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
WebMock.disable!
|
15
|
+
end
|
16
|
+
|
17
|
+
# Helpers
|
18
|
+
def stubAccessToken
|
19
|
+
access_token_json = JSON.generate({
|
20
|
+
:access_token => "simple-access-token",
|
21
|
+
:expires_in => 3600,
|
22
|
+
:token_type => 'Bearer',
|
23
|
+
})
|
24
|
+
|
25
|
+
stub_request(:any, @environment.base_url + "/v1/oauth2/token").
|
26
|
+
to_return(body: access_token_json, status: 200,
|
27
|
+
headers: {'content-type' => "application/json"})
|
28
|
+
end
|
29
|
+
|
30
|
+
def stubRefreshToken
|
31
|
+
access_token_json = JSON.generate({
|
32
|
+
:access_token => "refresh-access-token",
|
33
|
+
:expires_in => 3600,
|
34
|
+
:token_type => 'Bearer',
|
35
|
+
})
|
36
|
+
|
37
|
+
stub_request(:any, @environment.base_url + "/v1/oauth2/token")
|
38
|
+
.to_return(body: access_token_json, status: 200, headers: {'content-type' => "application/json"})
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'execute' do
|
42
|
+
before(:each) do
|
43
|
+
WebMock.enable!
|
44
|
+
end
|
45
|
+
|
46
|
+
after(:each) do
|
47
|
+
WebMock.disable!
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'fetches access token if not yet fetched' do
|
51
|
+
access_token_stub = stubAccessToken
|
52
|
+
|
53
|
+
return_json = JSON.generate({
|
54
|
+
:some_key => "some_value",
|
55
|
+
})
|
56
|
+
|
57
|
+
stub_request(:get, @environment.base_url + "/path")
|
58
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
59
|
+
|
60
|
+
req = OpenStruct.new({:verb => "GET", :path => "/path"})
|
61
|
+
|
62
|
+
resp = @httpClient.execute(req)
|
63
|
+
|
64
|
+
expect(resp.status_code).to eq(200)
|
65
|
+
expect(resp.result.some_key).to eq("some_value")
|
66
|
+
assert_requested(access_token_stub)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'does not fetch access token if not expired and valid' do
|
70
|
+
access_token_stub = stubAccessToken
|
71
|
+
|
72
|
+
return_json = JSON.generate({
|
73
|
+
:some_key => "some_value",
|
74
|
+
})
|
75
|
+
|
76
|
+
response_stub = stub_request(:any, @environment.base_url)
|
77
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
78
|
+
|
79
|
+
req = OpenStruct.new({:verb => "GET", :path => "/"})
|
80
|
+
|
81
|
+
resp = @httpClient.execute(req)
|
82
|
+
|
83
|
+
expect(resp.status_code).to eq(200)
|
84
|
+
expect(resp.result[:some_key]).to eq("some_value")
|
85
|
+
|
86
|
+
resp = @httpClient.execute(req)
|
87
|
+
|
88
|
+
assert_requested(access_token_stub, times: 1)
|
89
|
+
assert_requested(response_stub, times: 2)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'fetches access token if expired' do
|
93
|
+
expired_access_token_json = JSON.generate({
|
94
|
+
:access_token => "expired-access-token",
|
95
|
+
:expires_in => -1,
|
96
|
+
:token_type => 'Bearer',
|
97
|
+
})
|
98
|
+
|
99
|
+
access_token_json = JSON.generate({
|
100
|
+
:access_token => "simple-access-token",
|
101
|
+
:expires_in => 3600,
|
102
|
+
:token_type => 'Bearer',
|
103
|
+
})
|
104
|
+
|
105
|
+
access_token_stub = stub_request(:any, @environment.base_url + "/v1/oauth2/token")
|
106
|
+
.to_return(body: expired_access_token_json, status: 200, headers: {'content-type' => "application/json"})
|
107
|
+
.times(1)
|
108
|
+
.then
|
109
|
+
.to_return(body: access_token_json, status: 200, headers: {'content-type' => "application/json"})
|
110
|
+
|
111
|
+
return_json = JSON.generate({
|
112
|
+
:some_key => "some_value",
|
113
|
+
})
|
114
|
+
|
115
|
+
response_stub = stub_request(:any, @environment.base_url)
|
116
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
117
|
+
|
118
|
+
req = OpenStruct.new({:verb => "GET", :path => "/"})
|
119
|
+
|
120
|
+
resp = @httpClient.execute(req)
|
121
|
+
|
122
|
+
expect(resp.status_code).to eq(200)
|
123
|
+
expect(resp.result[:some_key]).to eq("some_value")
|
124
|
+
|
125
|
+
resp = @httpClient.execute(req)
|
126
|
+
|
127
|
+
assert_requested(access_token_stub, times: 2)
|
128
|
+
assert_requested(response_stub, times: 2)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'fetches access token with refresh token not yet fetched' do
|
132
|
+
@httpClient = PayPal::PayPalHttpClient.new(@environment, "refresh-token")
|
133
|
+
refresh_token_stub = stubRefreshToken
|
134
|
+
|
135
|
+
return_json = JSON.generate({
|
136
|
+
:some_key => "some_value",
|
137
|
+
})
|
138
|
+
|
139
|
+
stub_request(:any, @environment.base_url)
|
140
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
141
|
+
|
142
|
+
req = OpenStruct.new({:verb => "GET", :path => "/"})
|
143
|
+
|
144
|
+
resp = @httpClient.execute(req)
|
145
|
+
|
146
|
+
expect(resp.status_code).to eq(200)
|
147
|
+
expect(resp.result[:some_key]).to eq("some_value")
|
148
|
+
assert_requested(refresh_token_stub)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'fetches access token with refresh token if expired' do
|
152
|
+
@httpClient = PayPal::PayPalHttpClient.new(@environment, "refresh-token")
|
153
|
+
|
154
|
+
expired_access_token_json = JSON.generate({
|
155
|
+
:access_token => "expired-access-token",
|
156
|
+
:expires_in => -1,
|
157
|
+
:token_type => 'Bearer',
|
158
|
+
})
|
159
|
+
|
160
|
+
access_token_json = JSON.generate({
|
161
|
+
:access_token => "refresh-access-token",
|
162
|
+
:expires_in => 3600,
|
163
|
+
:token_type => 'Bearer',
|
164
|
+
})
|
165
|
+
|
166
|
+
access_token_stub = stub_request(:any, @environment.base_url + "/v1/oauth2/token")
|
167
|
+
.to_return(body: expired_access_token_json, status: 200, headers: {'content-type' => "application/json"})
|
168
|
+
.times(1)
|
169
|
+
.then
|
170
|
+
.to_return(body: access_token_json, status: 200, headers: {'content-type' => "application/json"})
|
171
|
+
|
172
|
+
return_json = JSON.generate({
|
173
|
+
:some_key => "some_value",
|
174
|
+
})
|
175
|
+
|
176
|
+
response_stub = stub_request(:any, @environment.base_url)
|
177
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
178
|
+
|
179
|
+
req = OpenStruct.new({:verb => "GET", :path => "/"})
|
180
|
+
|
181
|
+
resp = @httpClient.execute(req)
|
182
|
+
|
183
|
+
expect(resp.status_code).to eq(200)
|
184
|
+
expect(resp.result[:some_key]).to eq("some_value")
|
185
|
+
|
186
|
+
resp = @httpClient.execute(req)
|
187
|
+
|
188
|
+
assert_requested(access_token_stub, times: 2)
|
189
|
+
assert_requested(response_stub, times: 2)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'does not fetch access token if authorization header already present' do
|
193
|
+
@httpClient = PayPal::PayPalHttpClient.new(@environment)
|
194
|
+
|
195
|
+
return_json = JSON.generate({
|
196
|
+
:some_key => "some_value",
|
197
|
+
})
|
198
|
+
|
199
|
+
stub_request(:get, @environment.base_url + "/path")
|
200
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
201
|
+
|
202
|
+
req = OpenStruct.new({:verb => "GET", :path => "/path", :headers => {'Authorization' => 'custom-header-value'}})
|
203
|
+
|
204
|
+
resp = @httpClient.execute(req)
|
205
|
+
|
206
|
+
expect(resp.status_code).to eq(200)
|
207
|
+
expect(resp.result[:some_key]).to eq("some_value")
|
208
|
+
|
209
|
+
expect(WebMock).to have_requested(:get, @environment.base_url + '/path')
|
210
|
+
.with(headers: {'Authorization' => "custom-header-value"})
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'sets Authorization header with access token value' do
|
214
|
+
access_token_stub = stubAccessToken
|
215
|
+
|
216
|
+
return_json = JSON.generate({
|
217
|
+
:some_key => "some_value",
|
218
|
+
})
|
219
|
+
|
220
|
+
stub_request(:get, @environment.base_url + "/path")
|
221
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
222
|
+
|
223
|
+
req = OpenStruct.new({:verb => "GET", :path => "/path"})
|
224
|
+
|
225
|
+
resp = @httpClient.execute(req)
|
226
|
+
|
227
|
+
expect(resp.status_code).to eq(200)
|
228
|
+
expect(resp.result.some_key).to eq("some_value")
|
229
|
+
assert_requested(access_token_stub)
|
230
|
+
|
231
|
+
expect(WebMock).to have_requested(:get, @environment.base_url + '/path')
|
232
|
+
.with(headers: {'Authorization' => "Bearer simple-access-token"})
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'sets User-Agent header properly' do
|
236
|
+
access_token_stub = stubAccessToken
|
237
|
+
|
238
|
+
return_json = JSON.generate({
|
239
|
+
:some_key => "some_value",
|
240
|
+
})
|
241
|
+
|
242
|
+
request_stub = stub_request(:any, @environment.base_url)
|
243
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
244
|
+
|
245
|
+
resp = @httpClient.execute(OpenStruct.new({:verb => "GET", :path => "/"}))
|
246
|
+
|
247
|
+
user_agent_regex = /^PayPalSDK\/rest-sdk-ruby #{PayPal::VERSION} \(paypal-sdk-core .*; ruby [\d\.?]*p\d+-.*;OpenSSL.*\)$/
|
248
|
+
expect(WebMock).to have_requested(:get, @environment.base_url)
|
249
|
+
.with(headers: {'User-Agent' => user_agent_regex})
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'sets Accept-Encoding header to gzip' do
|
253
|
+
access_token_stub = stubAccessToken
|
254
|
+
|
255
|
+
return_json = JSON.generate({
|
256
|
+
:some_key => "some_value",
|
257
|
+
})
|
258
|
+
|
259
|
+
request_stub = stub_request(:any, @environment.base_url)
|
260
|
+
.to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
|
261
|
+
|
262
|
+
req = OpenStruct.new({:verb => "GET", :path => "/"})
|
263
|
+
|
264
|
+
resp = @httpClient.execute(req)
|
265
|
+
|
266
|
+
expect(resp.status_code).to eq(200)
|
267
|
+
expect(resp.result[:some_key]).to eq("some_value")
|
268
|
+
expect(WebMock).to have_requested(:get, @environment.base_url)
|
269
|
+
.with(headers: {'Accept-Encoding' => 'gzip'})
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|