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
@@ -1,74 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Payouts", :integration => true do
|
4
|
-
|
5
|
-
PayoutVenmoAttributes = {
|
6
|
-
:sender_batch_header => {
|
7
|
-
:sender_batch_id => SecureRandom.hex(8)
|
8
|
-
},
|
9
|
-
:items => [
|
10
|
-
{
|
11
|
-
:recipient_type => 'PHONE',
|
12
|
-
:amount => {
|
13
|
-
:value => '1.0',
|
14
|
-
:currency => 'USD'
|
15
|
-
},
|
16
|
-
:note => 'Thanks for your patronage!',
|
17
|
-
:sender_item_id => '2014031400023',
|
18
|
-
:receiver => '5551232368',
|
19
|
-
:recipient_wallet => 'VENMO'
|
20
|
-
}
|
21
|
-
]
|
22
|
-
}
|
23
|
-
|
24
|
-
PayoutAttributes = {
|
25
|
-
:sender_batch_header => {
|
26
|
-
:sender_batch_id => SecureRandom.hex(8),
|
27
|
-
:email_subject => 'You have a Payout!'
|
28
|
-
},
|
29
|
-
:items => [
|
30
|
-
{
|
31
|
-
:recipient_type => 'EMAIL',
|
32
|
-
:amount => {
|
33
|
-
:value => '1.0',
|
34
|
-
:currency => 'USD'
|
35
|
-
},
|
36
|
-
:note => 'Thanks for your patronage!',
|
37
|
-
:sender_item_id => '2014031400023',
|
38
|
-
:receiver => 'shirt-supplier-one@mail.com'
|
39
|
-
}
|
40
|
-
]
|
41
|
-
}
|
42
|
-
|
43
|
-
it "create venmo payout" do
|
44
|
-
$payout = PayPal::SDK::REST::Payout.new(PayoutVenmoAttributes)
|
45
|
-
$payout_batch = $payout.create
|
46
|
-
expect($payout_batch).to be_truthy
|
47
|
-
end
|
48
|
-
|
49
|
-
it "create payout sync" do
|
50
|
-
$payout = PayPal::SDK::REST::Payout.new(PayoutAttributes)
|
51
|
-
$payout_batch = $payout.create(true)
|
52
|
-
expect($payout_batch).to be_truthy
|
53
|
-
end
|
54
|
-
|
55
|
-
it "get payout batch status" do
|
56
|
-
$result = PayPal::SDK::REST::Payout.get($payout_batch.batch_header.payout_batch_id)
|
57
|
-
expect($result).to be_a PayPal::SDK::REST::PayoutBatch
|
58
|
-
expect($payout_batch.batch_header.payout_batch_id).to eql $result.batch_header.payout_batch_id
|
59
|
-
end
|
60
|
-
|
61
|
-
it "get payout item status" do
|
62
|
-
$payout_item_details= PayoutItem.get($payout_batch.items[0].payout_item_id)
|
63
|
-
expect($payout_item_details).to be_a PayPal::SDK::REST::PayoutItemDetails
|
64
|
-
expect($payout_item_details.payout_item_id).to eql $payout_batch.items[0].payout_item_id
|
65
|
-
end
|
66
|
-
|
67
|
-
it "cancel unclaimed payouts" do
|
68
|
-
$payout_item_details= PayoutItem.cancel($payout_batch.items[0].payout_item_id)
|
69
|
-
expect($payout_item_details).to be_a PayPal::SDK::REST::PayoutItemDetails
|
70
|
-
expect($payout_item_details.payout_item_id).to eql $payout_batch.items[0].payout_item_id
|
71
|
-
expect($payout_item_details.transaction_status).to eql 'RETURNED'
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module PayPal::SDK::REST::DataTypes
|
2
|
-
describe Base do
|
3
|
-
let(:error_object) {
|
4
|
-
{
|
5
|
-
"name" => "INVALID_EXPERIENCE_PROFILE_ID",
|
6
|
-
"message" => "The requested experience profile ID was not found",
|
7
|
-
"information_link" => "https://developer.paypal.com/docs/api/#INVALID_EXPERIENCE_PROFILE_ID",
|
8
|
-
"debug_id" => "1562931a79fd2"
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
|
-
context '#raise_error!' do
|
13
|
-
context 'when there is error' do
|
14
|
-
subject { described_class.new(error: error_object) }
|
15
|
-
|
16
|
-
it 'raises error on request with all API information' do
|
17
|
-
expect { subject.raise_error! }
|
18
|
-
.to raise_error { |err|
|
19
|
-
expect(err).to be_a(PayPal::SDK::Core::Exceptions::UnsuccessfulApiCall)
|
20
|
-
expect(err.message).to eq("The requested experience profile ID was not found")
|
21
|
-
expect(err.api_error).to eq(error_object)
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when there is no error' do
|
27
|
-
subject { described_class.new(error: nil) }
|
28
|
-
|
29
|
-
it { expect { subject.raise_error! }.not_to raise_error }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context '.raise_on_api_error' do
|
34
|
-
let(:klass) {
|
35
|
-
Class.new(described_class) do
|
36
|
-
def some_call
|
37
|
-
end
|
38
|
-
|
39
|
-
raise_on_api_error :some_call
|
40
|
-
end
|
41
|
-
}
|
42
|
-
|
43
|
-
subject { klass.new }
|
44
|
-
|
45
|
-
context 'when call is successful' do
|
46
|
-
before {
|
47
|
-
expect(subject).to receive(:some_call).and_return(true)
|
48
|
-
}
|
49
|
-
it { expect { subject.some_call! }.not_to raise_error }
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'when call is unsuccessful' do
|
53
|
-
before {
|
54
|
-
expect(subject).to receive(:some_call).and_return(false)
|
55
|
-
expect(subject).to receive(:error).twice.and_return(error_object)
|
56
|
-
}
|
57
|
-
|
58
|
-
it { expect { subject.some_call! }.to raise_error(PayPal::SDK::Core::Exceptions::UnsuccessfulApiCall) }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
module PayPal::SDK::REST
|
2
|
-
describe ErrorHash do
|
3
|
-
it 'converts Hashes to ErrorHashes' do
|
4
|
-
hash = ErrorHash.convert({
|
5
|
-
nested_hash: { bing: 'bong' },
|
6
|
-
empty_array: [],
|
7
|
-
array_with_hashes: [
|
8
|
-
{ foo: 'boo' },
|
9
|
-
{ biz: 'boz' }
|
10
|
-
],
|
11
|
-
array_without_hashes: [1, 2, 3],
|
12
|
-
nilly: nil,
|
13
|
-
stringy: 'cheese'
|
14
|
-
})
|
15
|
-
|
16
|
-
expect(hash).to be_a(ErrorHash)
|
17
|
-
expect(hash.nested_hash).to be_a(ErrorHash)
|
18
|
-
expect(hash.empty_array).to eq([])
|
19
|
-
expect(hash.array_with_hashes[0]).to be_a(ErrorHash)
|
20
|
-
expect(hash.array_with_hashes[1]).to be_a(ErrorHash)
|
21
|
-
expect(hash.array_without_hashes).to eq([1, 2, 3])
|
22
|
-
expect(hash.nilly).to be_nil
|
23
|
-
expect(hash.stringy).to eq('cheese')
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'can access string keys as properties, strings, or symbols' do
|
27
|
-
hash = ErrorHash.convert({ 'foo' => 5 })
|
28
|
-
hash['boo'] = 'grue'
|
29
|
-
|
30
|
-
expect(hash.foo).to eq(5)
|
31
|
-
expect(hash['foo']).to eq(5)
|
32
|
-
expect(hash[:foo]).to eq(5)
|
33
|
-
expect(hash.boo).to eq('grue')
|
34
|
-
expect(hash['boo']).to eq('grue')
|
35
|
-
expect(hash[:boo]).to eq('grue')
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'can access symbol keys as properties, strings, or symbols' do
|
39
|
-
hash = ErrorHash.convert({ :foo => 5 })
|
40
|
-
hash[:boo] = 'grue'
|
41
|
-
|
42
|
-
expect(hash.foo).to eq(5)
|
43
|
-
expect(hash['foo']).to eq(5)
|
44
|
-
expect(hash[:foo]).to eq(5)
|
45
|
-
expect(hash.boo).to eq('grue')
|
46
|
-
expect(hash['boo']).to eq('grue')
|
47
|
-
expect(hash[:boo]).to eq('grue')
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'converts Hashes to ErrorHashes on assignment' do
|
51
|
-
hash = ErrorHash.new
|
52
|
-
hash['foo'] = { bing: 'bong' }
|
53
|
-
|
54
|
-
expect(hash['foo']).to be_a(ErrorHash)
|
55
|
-
expect(hash['foo'].bing).to eq('bong')
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'converts Hashes inside of Arrays to ErrorHashes on assignment' do
|
59
|
-
hash = ErrorHash.new
|
60
|
-
hash['foo'] = [{ bing: 'bong' }]
|
61
|
-
|
62
|
-
expect(hash['foo'][0]).to be_a(ErrorHash)
|
63
|
-
expect(hash['foo'][0].bing).to eq('bong')
|
64
|
-
end
|
65
|
-
|
66
|
-
it "doesn't convert Hashes inside of Arrays if the first element of the array isn't a Hash" do
|
67
|
-
hash = ErrorHash.new
|
68
|
-
hash['foo'] = [100, { bing: 'bong' }]
|
69
|
-
|
70
|
-
expect(hash['foo'][1]).to be_a(Hash)
|
71
|
-
expect(hash['foo'][1]).not_to be_a(ErrorHash)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'gets and sets numbers and strings' do
|
75
|
-
hash = ErrorHash.new
|
76
|
-
hash['foo'] = 123
|
77
|
-
hash['boo'] = 'baa'
|
78
|
-
|
79
|
-
expect(hash['foo']).to eq(123)
|
80
|
-
expect(hash['boo']).to eq('baa')
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,227 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Subscription" do
|
4
|
-
|
5
|
-
PlanAttributes = {
|
6
|
-
"name" => "T-Shirt of the Month Club Plan",
|
7
|
-
"description" => "Template creation.",
|
8
|
-
"type" => "fixed",
|
9
|
-
"payment_definitions" => [
|
10
|
-
{
|
11
|
-
"name" => "Regular Payments",
|
12
|
-
"type" => "REGULAR",
|
13
|
-
"frequency" => "MONTH",
|
14
|
-
"frequency_interval" => "2",
|
15
|
-
"amount" => {
|
16
|
-
"value" => "100",
|
17
|
-
"currency" => "USD"
|
18
|
-
},
|
19
|
-
"cycles" => "12",
|
20
|
-
"charge_models" => [
|
21
|
-
{
|
22
|
-
"type" => "SHIPPING",
|
23
|
-
"amount" => {
|
24
|
-
"value" => "10",
|
25
|
-
"currency" => "USD"
|
26
|
-
}
|
27
|
-
},
|
28
|
-
{
|
29
|
-
"type" => "TAX",
|
30
|
-
"amount" => {
|
31
|
-
"value" => "12",
|
32
|
-
"currency" => "USD"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
]
|
36
|
-
}
|
37
|
-
],
|
38
|
-
"merchant_preferences" => {
|
39
|
-
"setup_fee" => {
|
40
|
-
"value" => "1",
|
41
|
-
"currency" => "USD"
|
42
|
-
},
|
43
|
-
"return_url" => "http://www.return.com",
|
44
|
-
"cancel_url" => "http://www.cancel.com",
|
45
|
-
"auto_bill_amount" => "YES",
|
46
|
-
"initial_fail_amount_action" => "CONTINUE",
|
47
|
-
"max_fail_attempts" => "0"
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
AgreementAttributes = {
|
52
|
-
"name" => "T-Shirt of the Month Club Agreement",
|
53
|
-
"description" => "Agreement for T-Shirt of the Month Club Plan",
|
54
|
-
"start_date" => "2015-02-19T00:37:04Z",
|
55
|
-
"payer" => {
|
56
|
-
"payment_method" => "paypal"
|
57
|
-
},
|
58
|
-
"shipping_address" => {
|
59
|
-
"line1" => "111 First Street",
|
60
|
-
"city" => "Saratoga",
|
61
|
-
"state" => "CA",
|
62
|
-
"postal_code" => "95070",
|
63
|
-
"country_code" => "US"
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
describe "BillingPlan", :integration => true do
|
68
|
-
it "Create" do
|
69
|
-
# create access token and then create a plan
|
70
|
-
$api = API.new
|
71
|
-
plan = Plan.new(PlanAttributes.merge( :token => $api.token ))
|
72
|
-
expect(Plan.api).not_to eql plan.api
|
73
|
-
plan.create
|
74
|
-
|
75
|
-
# make sure the transaction was successful
|
76
|
-
$plan_id = plan.id
|
77
|
-
expect(plan.error).to be_nil
|
78
|
-
expect(plan.id).not_to be_nil
|
79
|
-
end
|
80
|
-
|
81
|
-
it "Update" do
|
82
|
-
# create a new plan to update
|
83
|
-
plan = Plan.new(PlanAttributes)
|
84
|
-
expect(plan.create).to be_truthy
|
85
|
-
|
86
|
-
# set up a patch request
|
87
|
-
patch = Patch.new
|
88
|
-
patch.op = "replace"
|
89
|
-
patch.path = "/";
|
90
|
-
patch.value = { :state => "ACTIVE" }
|
91
|
-
|
92
|
-
# the patch request should be successful
|
93
|
-
expect(plan.update( patch )).to be_truthy
|
94
|
-
end
|
95
|
-
|
96
|
-
it "List" do
|
97
|
-
# list all billing plans
|
98
|
-
plan_list = Plan.all
|
99
|
-
expect(plan_list.error).to be_nil
|
100
|
-
expect(plan_list.plans.count).to be > 1
|
101
|
-
end
|
102
|
-
|
103
|
-
it "Delete" do
|
104
|
-
# create a plan to delete
|
105
|
-
plan = Plan.new(PlanAttributes.merge( :token => $api.token ))
|
106
|
-
plan.create
|
107
|
-
plan_id = plan.id
|
108
|
-
|
109
|
-
# construct a patch object that will be used for deletion
|
110
|
-
patch = Patch.new
|
111
|
-
patch.op = "replace"
|
112
|
-
patch.path = "/"
|
113
|
-
patch.value = { "state" => "DELETED" }
|
114
|
-
|
115
|
-
# send delete request
|
116
|
-
plan.update(patch)
|
117
|
-
|
118
|
-
# make sure the plan has been deleted
|
119
|
-
plan = Plan.find(plan_id)
|
120
|
-
expect(plan.id).not_to eq plan_id
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "BillingAgreement", :integration => true do
|
125
|
-
|
126
|
-
it "Create" do
|
127
|
-
# first, create an active plan to be added to agreement
|
128
|
-
api = API.new
|
129
|
-
plan = Plan.new(PlanAttributes)
|
130
|
-
expect(plan.create).to be_truthy
|
131
|
-
|
132
|
-
# first, create an agreement
|
133
|
-
$agreement = Agreement.new(AgreementAttributes)
|
134
|
-
$agreement.plan = Plan.new( :id => "P-1K47639161110773GYDKTWIA" )
|
135
|
-
$agreement.shipping_address = nil
|
136
|
-
|
137
|
-
# verify newly created agreement
|
138
|
-
expect($agreement.create).to be_truthy
|
139
|
-
expect($agreement.id).to be_nil
|
140
|
-
expect($agreement.token).not_to be_nil
|
141
|
-
expect($agreement.name).to eq("T-Shirt of the Month Club Agreement")
|
142
|
-
end
|
143
|
-
|
144
|
-
#####################################
|
145
|
-
# The following tests are disabled due to them requiring an active billing agreement or buyer's approval.
|
146
|
-
# Most of them require an agreement ID, which is returned after executing agreement.
|
147
|
-
# And agreement execution requires buyer's approval.
|
148
|
-
#####################################
|
149
|
-
|
150
|
-
xit "Execute" do
|
151
|
-
# Use this call to execute an agreement after the buyer approves it.
|
152
|
-
expect($agreement.execute).to be_truthy
|
153
|
-
end
|
154
|
-
|
155
|
-
xit "Get" do
|
156
|
-
# this call needs an agreement ID of the agreement to be retrieved
|
157
|
-
agreement = Agreement.find($agreement.id)
|
158
|
-
expect(agreement.id).to eq($agreement.id)
|
159
|
-
expect(agreement.description).to eq("Agreement for T-Shirt of the Month Club Plan")
|
160
|
-
expect(agreement.start_date).to eq("2015-02-19T00:37:04Z")
|
161
|
-
expect(agreement.plan).not_to be_nil
|
162
|
-
end
|
163
|
-
|
164
|
-
xit "Update" do
|
165
|
-
# get the agreement to update
|
166
|
-
api = API.new
|
167
|
-
plan = Plan.new(PlanAttributes)
|
168
|
-
expect(plan.create).to be_truthy
|
169
|
-
|
170
|
-
# first, create an agreement
|
171
|
-
agreement = Agreement.new(AgreementAttributes)
|
172
|
-
agreement.plan = Plan.new( :id => "P-1K47639161110773GYDKTWIA" )
|
173
|
-
expect(agreement.create).to be_truthy
|
174
|
-
|
175
|
-
|
176
|
-
# create an update for the agreement
|
177
|
-
random_string = (0...8).map { (65 + rand(26)).chr }.join
|
178
|
-
patch = Patch.new
|
179
|
-
patch.op = "replace"
|
180
|
-
patch.path = "/"
|
181
|
-
patch.value = { "description" => random_string }
|
182
|
-
|
183
|
-
# send update request
|
184
|
-
response = agreement.update(patch)
|
185
|
-
|
186
|
-
# verify the agreement update was successful
|
187
|
-
expect(response).to be_truthy
|
188
|
-
updated_agreement = Agreement.get($agreement.id)
|
189
|
-
expect(updated_agreement.id).to eq($agreement.id)
|
190
|
-
expect(random_string).to eq(updated_agreement.description)
|
191
|
-
end
|
192
|
-
|
193
|
-
xit "Suspend" do
|
194
|
-
# set the id of an active agreement here
|
195
|
-
agreement_id = ""
|
196
|
-
agreement = Agreement.find(agreement_id)
|
197
|
-
|
198
|
-
state_descriptor = AgreementStateDescriptor.new( :note => "Suspending the agreement" )
|
199
|
-
expect( agreement.suspend(state_descriptor) ).to be_truthy
|
200
|
-
end
|
201
|
-
|
202
|
-
xit "Reactivate" do
|
203
|
-
# set the id of a suspended agreement here
|
204
|
-
agreement_id = ""
|
205
|
-
agreement = Agreement.find(agreement_id)
|
206
|
-
|
207
|
-
state_descriptor = AgreementStateDescriptor.new( :note => "Re-activating the agreement" )
|
208
|
-
expect( agreement.re_activate(state_descriptor) ).to be_truthy
|
209
|
-
end
|
210
|
-
|
211
|
-
xit "Search" do
|
212
|
-
transactions = Agreement.transactions($agreement.id, "2015-01-01", "2015-01-10")
|
213
|
-
expect(transactions).not_to be_nil
|
214
|
-
expect(transactions.agreement_transaction_list).not_to be_empty
|
215
|
-
end
|
216
|
-
|
217
|
-
xit "Cancel" do
|
218
|
-
# set the id of an agreement here
|
219
|
-
agreement_id = ""
|
220
|
-
agreement = Agreement.find(agreement_id)
|
221
|
-
|
222
|
-
state_descriptor = AgreementStateDescriptor.new( :note => "Cancelling the agreement" )
|
223
|
-
expect( agreement.cancel(state_descriptor) ).to be_truthy
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
end
|