braintree 2.98.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/braintree.gemspec +7 -4
- data/lib/braintree/account_updater_daily_report.rb +4 -4
- data/lib/braintree/ach_mandate.rb +1 -1
- data/lib/braintree/add_on_gateway.rb +1 -1
- data/lib/braintree/address.rb +7 -27
- data/lib/braintree/address_gateway.rb +8 -7
- data/lib/braintree/advanced_search.rb +11 -12
- data/lib/braintree/apple_pay.rb +4 -4
- data/lib/braintree/apple_pay_card.rb +18 -4
- data/lib/braintree/apple_pay_options.rb +4 -4
- data/lib/braintree/authorization_adjustment.rb +4 -4
- data/lib/braintree/base_module.rb +11 -1
- data/lib/braintree/bin_data.rb +10 -3
- data/lib/braintree/client_token.rb +1 -1
- data/lib/braintree/client_token_gateway.rb +4 -3
- data/lib/braintree/configuration.rb +35 -35
- data/lib/braintree/connected_merchant_paypal_status_changed.rb +2 -2
- data/lib/braintree/connected_merchant_status_transitioned.rb +2 -2
- data/lib/braintree/credit_card.rb +40 -86
- data/lib/braintree/credit_card_gateway.rb +58 -44
- data/lib/braintree/credit_card_verification.rb +39 -20
- data/lib/braintree/credit_card_verification_gateway.rb +35 -5
- data/lib/braintree/credit_card_verification_search.rb +2 -2
- data/lib/braintree/customer.rb +23 -88
- data/lib/braintree/customer_gateway.rb +17 -32
- data/lib/braintree/customer_search.rb +2 -2
- data/lib/braintree/descriptor.rb +1 -1
- data/lib/braintree/digest.rb +1 -1
- data/lib/braintree/disbursement.rb +7 -7
- data/lib/braintree/discount_gateway.rb +1 -1
- data/lib/braintree/dispute/evidence.rb +1 -1
- data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
- data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
- data/lib/braintree/dispute/transaction.rb +3 -1
- data/lib/braintree/dispute/transaction_details.rb +1 -1
- data/lib/braintree/dispute.rb +47 -6
- data/lib/braintree/dispute_gateway.rb +5 -10
- data/lib/braintree/dispute_search.rb +8 -4
- data/lib/braintree/document_upload.rb +3 -3
- data/lib/braintree/document_upload_gateway.rb +3 -3
- data/lib/braintree/enriched_customer_data.rb +21 -0
- data/lib/braintree/error_codes.rb +217 -175
- data/lib/braintree/error_result.rb +2 -3
- data/lib/braintree/errors.rb +3 -3
- data/lib/braintree/exceptions.rb +6 -5
- data/lib/braintree/exchange_rate.rb +13 -0
- data/lib/braintree/exchange_rate_quote.rb +24 -0
- data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
- data/lib/braintree/exchange_rate_quote_input.rb +21 -0
- data/lib/braintree/exchange_rate_quote_request.rb +18 -0
- data/lib/braintree/exchange_rate_quote_response.rb +18 -0
- data/lib/braintree/facilitated_details.rb +1 -1
- data/lib/braintree/facilitator_details.rb +1 -1
- data/lib/braintree/gateway.rb +6 -12
- data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +18 -5
- data/lib/braintree/granted_payment_instrument_update.rb +2 -2
- data/lib/braintree/graphql_client.rb +14 -8
- data/lib/braintree/http.rb +9 -10
- data/lib/braintree/local_payment_completed/blik_alias.rb +23 -0
- data/lib/braintree/local_payment_completed.rb +10 -5
- data/lib/braintree/local_payment_expired.rb +21 -0
- data/lib/braintree/local_payment_funded.rb +22 -0
- data/lib/braintree/local_payment_reversed.rb +19 -0
- data/lib/braintree/merchant.rb +4 -4
- data/lib/braintree/merchant_account.rb +3 -3
- data/lib/braintree/merchant_account_gateway.rb +10 -8
- data/lib/braintree/merchant_gateway.rb +1 -1
- data/lib/braintree/meta_checkout_card.rb +89 -0
- data/lib/braintree/meta_checkout_token.rb +88 -0
- data/lib/braintree/modification.rb +4 -4
- data/lib/braintree/oauth_credentials.rb +4 -4
- data/lib/braintree/oauth_gateway.rb +5 -5
- data/lib/braintree/paginated_collection.rb +2 -2
- data/lib/braintree/paginated_result.rb +1 -1
- data/lib/braintree/payment_instrument_type.rb +14 -13
- data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
- data/lib/braintree/payment_method_gateway.rb +52 -22
- data/lib/braintree/payment_method_nonce.rb +12 -7
- data/lib/braintree/payment_method_nonce_details.rb +40 -0
- data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
- data/lib/braintree/payment_method_nonce_gateway.rb +14 -3
- data/lib/braintree/payment_method_parser.rb +4 -7
- data/lib/braintree/paypal_account.rb +3 -2
- data/lib/braintree/paypal_account_gateway.rb +5 -5
- data/lib/braintree/plan.rb +22 -2
- data/lib/braintree/plan_gateway.rb +101 -1
- data/lib/braintree/processor_response_types.rb +3 -3
- data/lib/braintree/resource_collection.rb +10 -5
- data/lib/braintree/revoked_payment_method_metadata.rb +2 -2
- data/lib/braintree/risk_data/liability_shift.rb +22 -0
- data/lib/braintree/risk_data.rb +10 -3
- data/lib/braintree/samsung_pay_card.rb +8 -6
- data/lib/braintree/sepa_direct_debit_account.rb +60 -0
- data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
- data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
- data/lib/braintree/settlement_batch_summary.rb +2 -2
- data/lib/braintree/settlement_batch_summary_gateway.rb +1 -1
- data/lib/braintree/sha256_digest.rb +1 -1
- data/lib/braintree/subscription/status_details.rb +1 -1
- data/lib/braintree/subscription.rb +13 -13
- data/lib/braintree/subscription_gateway.rb +6 -6
- data/lib/braintree/subscription_search.rb +1 -1
- data/lib/braintree/successful_result.rb +5 -4
- data/lib/braintree/test/authentication_id.rb +21 -0
- data/lib/braintree/test/credit_card.rb +9 -10
- data/lib/braintree/test/merchant_account.rb +1 -1
- data/lib/braintree/test/nonce.rb +27 -20
- data/lib/braintree/test/transaction_amounts.rb +2 -3
- data/lib/braintree/test/venmo_sdk.rb +2 -0
- data/lib/braintree/testing_gateway.rb +1 -1
- data/lib/braintree/three_d_secure_info.rb +23 -11
- data/lib/braintree/transaction/address_details.rb +14 -1
- data/lib/braintree/transaction/apple_pay_details.rb +13 -10
- data/lib/braintree/transaction/credit_card_details.rb +8 -1
- data/lib/braintree/transaction/customer_details.rb +3 -2
- data/lib/braintree/transaction/disbursement_details.rb +2 -1
- data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +6 -1
- data/lib/braintree/transaction/installment/adjustment.rb +33 -0
- data/lib/braintree/transaction/installment.rb +28 -0
- data/lib/braintree/transaction/local_payment_details.rb +3 -0
- data/lib/braintree/transaction/meta_checkout_card_details.rb +52 -0
- data/lib/braintree/transaction/meta_checkout_token_details.rb +54 -0
- data/lib/braintree/transaction/package_details.rb +19 -0
- data/lib/braintree/transaction/payment_receipt/card_present_data.rb +36 -0
- data/lib/braintree/transaction/payment_receipt/merchant_address.rb +19 -0
- data/lib/braintree/transaction/payment_receipt.rb +31 -0
- data/lib/braintree/transaction/paypal_details.rb +5 -0
- data/lib/braintree/transaction/samsung_pay_card_details.rb +3 -1
- data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
- data/lib/braintree/transaction/status_details.rb +1 -1
- data/lib/braintree/transaction/subscription_details.rb +3 -1
- data/lib/braintree/transaction/us_bank_account_details.rb +2 -1
- data/lib/braintree/transaction/visa_checkout_card_details.rb +1 -1
- data/lib/braintree/transaction.rb +119 -128
- data/lib/braintree/transaction_gateway.rb +138 -64
- data/lib/braintree/transaction_line_item.rb +14 -11
- data/lib/braintree/transaction_line_item_gateway.rb +1 -1
- data/lib/braintree/transaction_review.rb +18 -0
- data/lib/braintree/transaction_search.rb +11 -7
- data/lib/braintree/unknown_payment_method.rb +2 -2
- data/lib/braintree/us_bank_account.rb +5 -5
- data/lib/braintree/us_bank_account_verification.rb +24 -16
- data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
- data/lib/braintree/us_bank_account_verification_search.rb +1 -1
- data/lib/braintree/util.rb +25 -10
- data/lib/braintree/validation_error.rb +1 -1
- data/lib/braintree/validation_error_collection.rb +3 -3
- data/lib/braintree/venmo_account.rb +4 -4
- data/lib/braintree/venmo_profile_data.rb +25 -0
- data/lib/braintree/version.rb +2 -2
- data/lib/braintree/visa_checkout_card.rb +8 -8
- data/lib/braintree/webhook_notification.rb +55 -33
- data/lib/braintree/webhook_notification_gateway.rb +9 -9
- data/lib/braintree/webhook_testing.rb +1 -1
- data/lib/braintree/webhook_testing_gateway.rb +569 -46
- data/lib/braintree/xml/generator.rb +6 -5
- data/lib/braintree/xml/libxml.rb +1 -1
- data/lib/braintree/xml/parser.rb +24 -37
- data/lib/braintree/xml/rexml.rb +6 -7
- data/lib/braintree/xml.rb +1 -1
- data/lib/braintree.rb +41 -24
- data/lib/ssl/api_braintreegateway_com.ca.crt +401 -168
- data/spec/integration/braintree/add_on_spec.rb +10 -10
- data/spec/integration/braintree/address_spec.rb +101 -178
- data/spec/integration/braintree/advanced_search_spec.rb +93 -93
- data/spec/integration/braintree/apple_pay_spec.rb +12 -12
- data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
- data/spec/integration/braintree/client_api/client_token_spec.rb +279 -62
- data/spec/integration/braintree/client_api/spec_helper.rb +99 -73
- data/spec/integration/braintree/credit_card_spec.rb +522 -821
- data/spec/integration/braintree/credit_card_verification_search_spec.rb +18 -18
- data/spec/integration/braintree/credit_card_verification_spec.rb +219 -30
- data/spec/integration/braintree/customer_search_spec.rb +28 -28
- data/spec/integration/braintree/customer_spec.rb +840 -757
- data/spec/integration/braintree/disbursement_spec.rb +2 -2
- data/spec/integration/braintree/discount_spec.rb +9 -9
- data/spec/integration/braintree/dispute_search_spec.rb +45 -9
- data/spec/integration/braintree/dispute_spec.rb +109 -82
- data/spec/integration/braintree/document_upload_spec.rb +29 -17
- data/spec/integration/braintree/error_codes_spec.rb +3 -3
- data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
- data/spec/integration/braintree/graphql_client_spec.rb +0 -2
- data/spec/integration/braintree/http_spec.rb +31 -33
- data/spec/integration/braintree/merchant_account_spec.rb +155 -156
- data/spec/integration/braintree/merchant_spec.rb +71 -192
- data/spec/integration/braintree/oauth_spec.rb +72 -72
- data/spec/integration/braintree/package_tracking_spec.rb +130 -0
- data/spec/integration/braintree/payment_method_nonce_spec.rb +173 -78
- data/spec/integration/braintree/payment_method_spec.rb +953 -501
- data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +147 -234
- data/spec/integration/braintree/paypal_account_spec.rb +74 -72
- data/spec/integration/braintree/plan_spec.rb +96 -15
- data/spec/integration/braintree/samsung_pay_card_spec.rb +75 -73
- data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +194 -0
- data/spec/integration/braintree/settlement_batch_summary_spec.rb +18 -18
- data/spec/integration/braintree/subscription_spec.rb +507 -513
- data/spec/integration/braintree/test/transaction_amounts_spec.rb +4 -4
- data/spec/integration/braintree/test_transaction_spec.rb +29 -29
- data/spec/integration/braintree/transaction_line_item_spec.rb +12 -6
- data/spec/integration/braintree/transaction_search_spec.rb +410 -217
- data/spec/integration/braintree/transaction_spec.rb +3252 -2102
- data/spec/integration/braintree/transaction_us_bank_account_spec.rb +42 -278
- data/spec/integration/braintree/us_bank_account_spec.rb +36 -36
- data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +25 -25
- data/spec/integration/braintree/us_bank_account_verification_spec.rb +41 -41
- data/spec/integration/braintree/visa_checkout_card_spec.rb +62 -62
- data/spec/integration/spec_helper.rb +22 -7
- data/spec/oauth_test_helper.rb +1 -1
- data/spec/script/httpsd.rb +6 -6
- data/spec/spec_helper.rb +15 -20
- data/spec/unit/braintree/address_spec.rb +9 -17
- data/spec/unit/braintree/apple_pay_card_spec.rb +110 -7
- data/spec/unit/braintree/base_module_spec.rb +4 -4
- data/spec/unit/braintree/client_token_spec.rb +6 -6
- data/spec/unit/braintree/configuration_spec.rb +84 -84
- data/spec/unit/braintree/credentials_parser_spec.rb +6 -6
- data/spec/unit/braintree/credit_card_spec.rb +91 -58
- data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +56 -0
- data/spec/unit/braintree/credit_card_verification_search_spec.rb +10 -10
- data/spec/unit/braintree/credit_card_verification_spec.rb +40 -18
- data/spec/unit/braintree/customer_spec.rb +102 -57
- data/spec/unit/braintree/digest_spec.rb +5 -6
- data/spec/unit/braintree/disbursement_spec.rb +14 -14
- data/spec/unit/braintree/dispute_search_spec.rb +6 -2
- data/spec/unit/braintree/dispute_spec.rb +144 -66
- data/spec/unit/braintree/document_upload_spec.rb +8 -8
- data/spec/unit/braintree/enriched_customer_data_spec.rb +41 -0
- data/spec/unit/braintree/error_result_spec.rb +11 -11
- data/spec/unit/braintree/errors_spec.rb +17 -17
- data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
- data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
- data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
- data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
- data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
- data/spec/unit/braintree/http_spec.rb +19 -17
- data/spec/unit/braintree/local_payment_completed_spec.rb +62 -8
- data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
- data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
- data/spec/unit/braintree/merchant_account_spec.rb +5 -5
- data/spec/unit/braintree/meta_checkout_card_details_spec.rb +60 -0
- data/spec/unit/braintree/meta_checkout_card_spec.rb +60 -0
- data/spec/unit/braintree/meta_checkout_token_details_spec.rb +63 -0
- data/spec/unit/braintree/meta_checkout_token_spec.rb +63 -0
- data/spec/unit/braintree/modification_spec.rb +1 -1
- data/spec/unit/braintree/package_tracking_spec.rb +77 -0
- data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
- data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
- data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
- data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
- data/spec/unit/braintree/payment_method_spec.rb +20 -20
- data/spec/unit/braintree/paypal_account_spec.rb +16 -7
- data/spec/unit/braintree/resource_collection_spec.rb +34 -5
- data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
- data/spec/unit/braintree/risk_data_spec.rb +38 -8
- data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
- data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
- data/spec/unit/braintree/sha256_digest_spec.rb +1 -1
- data/spec/unit/braintree/signature_service_spec.rb +2 -2
- data/spec/unit/braintree/subscription_search_spec.rb +18 -18
- data/spec/unit/braintree/subscription_spec.rb +8 -8
- data/spec/unit/braintree/successful_result_spec.rb +6 -6
- data/spec/unit/braintree/three_d_secure_info_spec.rb +37 -17
- data/spec/unit/braintree/transaction/credit_card_details_spec.rb +22 -6
- data/spec/unit/braintree/transaction/customer_details_spec.rb +3 -2
- data/spec/unit/braintree/transaction/deposit_details_spec.rb +4 -4
- data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
- data/spec/unit/braintree/transaction/local_payment_details_spec.rb +36 -0
- data/spec/unit/braintree/transaction/payment_receipt_spec.rb +73 -0
- data/spec/unit/braintree/transaction/paypal_details_spec.rb +63 -0
- data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
- data/spec/unit/braintree/transaction_gateway_spec.rb +150 -0
- data/spec/unit/braintree/transaction_search_spec.rb +12 -12
- data/spec/unit/braintree/transaction_spec.rb +221 -124
- data/spec/unit/braintree/unknown_payment_method_spec.rb +4 -4
- data/spec/unit/braintree/us_bank_account_spec.rb +2 -2
- data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +7 -7
- data/spec/unit/braintree/us_bank_account_verification_spec.rb +12 -7
- data/spec/unit/braintree/util_spec.rb +78 -44
- data/spec/unit/braintree/validation_error_collection_spec.rb +62 -62
- data/spec/unit/braintree/validation_error_spec.rb +4 -4
- data/spec/unit/braintree/venmo_profile_data_spec.rb +43 -0
- data/spec/unit/braintree/webhook_notification_spec.rb +434 -197
- data/spec/unit/braintree/xml/libxml_spec.rb +5 -5
- data/spec/unit/braintree/xml/parser_spec.rb +27 -22
- data/spec/unit/braintree/xml/rexml_spec.rb +5 -5
- data/spec/unit/braintree/xml_spec.rb +38 -38
- data/spec/unit/braintree_spec.rb +2 -2
- metadata +91 -30
- data/lib/braintree/amex_express_checkout_card.rb +0 -38
- data/lib/braintree/coinbase_account.rb +0 -34
- data/lib/braintree/europe_bank_account.rb +0 -36
- data/lib/braintree/europe_bank_account_gateway.rb +0 -17
- data/lib/braintree/ideal_payment.rb +0 -61
- data/lib/braintree/ideal_payment_gateway.rb +0 -19
- data/lib/braintree/masterpass_card.rb +0 -81
- data/lib/braintree/settlement_batch.rb +0 -0
- data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
- data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
- data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
- data/lib/braintree/transparent_redirect.rb +0 -40
- data/lib/braintree/transparent_redirect_gateway.rb +0 -105
- data/spec/hacks/tcp_socket.rb +0 -18
- data/spec/integration/braintree/coinbase_spec.rb +0 -34
- data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
- data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
- data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -8,7 +8,7 @@ describe Braintree::Subscription do
|
|
8
8
|
:credit_card => {
|
9
9
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
10
10
|
:expiration_date => "05/2010"
|
11
|
-
}
|
11
|
+
},
|
12
12
|
).credit_cards[0]
|
13
13
|
end
|
14
14
|
|
@@ -16,48 +16,46 @@ describe Braintree::Subscription do
|
|
16
16
|
it "is successful with a minimum of params" do
|
17
17
|
result = Braintree::Subscription.create(
|
18
18
|
:payment_method_token => @credit_card.token,
|
19
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
19
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
20
20
|
)
|
21
21
|
|
22
|
-
|
23
|
-
result.
|
24
|
-
result.subscription.
|
25
|
-
result.subscription.
|
26
|
-
|
27
|
-
|
28
|
-
result.subscription.
|
29
|
-
result.subscription.
|
30
|
-
result.subscription.
|
31
|
-
result.subscription.
|
32
|
-
|
33
|
-
|
34
|
-
result.subscription.
|
35
|
-
|
36
|
-
|
37
|
-
result.subscription.
|
38
|
-
result.subscription.
|
39
|
-
|
40
|
-
result.subscription.
|
41
|
-
|
42
|
-
result.subscription.status_history.first.
|
43
|
-
result.subscription.status_history.first.
|
44
|
-
result.subscription.status_history.first.
|
45
|
-
result.subscription.status_history.first.currency_iso_code.should == "USD"
|
46
|
-
result.subscription.status_history.first.plan_id.should == SpecHelper::TriallessPlan[:id]
|
22
|
+
expect(result.success?).to eq(true)
|
23
|
+
expect(result.subscription.id).to match(/^\w{6}$/)
|
24
|
+
expect(result.subscription.status).to eq(Braintree::Subscription::Status::Active)
|
25
|
+
expect(result.subscription.plan_id).to eq("integration_trialless_plan")
|
26
|
+
|
27
|
+
expect(result.subscription.first_billing_date).to be_a Date
|
28
|
+
expect(result.subscription.next_billing_date).to be_a Date
|
29
|
+
expect(result.subscription.billing_period_start_date).to be_a Date
|
30
|
+
expect(result.subscription.billing_period_end_date).to be_a Date
|
31
|
+
expect(result.subscription.paid_through_date).to be_a Date
|
32
|
+
|
33
|
+
expect(result.subscription.created_at.between?(Time.now - 60, Time.now)).to eq(true)
|
34
|
+
expect(result.subscription.updated_at.between?(Time.now - 60, Time.now)).to eq(true)
|
35
|
+
|
36
|
+
expect(result.subscription.failure_count).to eq(0)
|
37
|
+
expect(result.subscription.next_billing_period_amount).to eq("12.34")
|
38
|
+
expect(result.subscription.payment_method_token).to eq(@credit_card.token)
|
39
|
+
|
40
|
+
expect(result.subscription.status_history.first.price).to eq("12.34")
|
41
|
+
expect(result.subscription.status_history.first.status).to eq(Braintree::Subscription::Status::Active)
|
42
|
+
expect(result.subscription.status_history.first.subscription_source).to eq(Braintree::Subscription::Source::Api)
|
43
|
+
expect(result.subscription.status_history.first.currency_iso_code).to eq("USD")
|
44
|
+
expect(result.subscription.status_history.first.plan_id).to eq(SpecHelper::TriallessPlan[:id])
|
47
45
|
end
|
48
46
|
|
49
47
|
it "returns a transaction with billing period populated" do
|
50
48
|
result = Braintree::Subscription.create(
|
51
49
|
:payment_method_token => @credit_card.token,
|
52
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
50
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
53
51
|
)
|
54
52
|
|
55
|
-
result.success
|
53
|
+
expect(result.success?).to eq(true)
|
56
54
|
subscription = result.subscription
|
57
55
|
transaction = subscription.transactions.first
|
58
56
|
|
59
|
-
transaction.subscription_details.billing_period_start_date.
|
60
|
-
transaction.subscription_details.billing_period_end_date.
|
57
|
+
expect(transaction.subscription_details.billing_period_start_date).to eq(subscription.billing_period_start_date)
|
58
|
+
expect(transaction.subscription_details.billing_period_end_date).to eq(subscription.billing_period_end_date)
|
61
59
|
end
|
62
60
|
|
63
61
|
it "can set the id" do
|
@@ -65,12 +63,11 @@ describe Braintree::Subscription do
|
|
65
63
|
result = Braintree::Subscription.create(
|
66
64
|
:payment_method_token => @credit_card.token,
|
67
65
|
:plan_id => SpecHelper::TrialPlan[:id],
|
68
|
-
:id => new_id
|
66
|
+
:id => new_id,
|
69
67
|
)
|
70
68
|
|
71
|
-
|
72
|
-
result.
|
73
|
-
result.subscription.id.should == new_id
|
69
|
+
expect(result.success?).to eq(true)
|
70
|
+
expect(result.subscription.id).to eq(new_id)
|
74
71
|
end
|
75
72
|
|
76
73
|
context "with payment_method_nonces" do
|
@@ -83,41 +80,41 @@ describe Braintree::Subscription do
|
|
83
80
|
},
|
84
81
|
:client_token_options => {
|
85
82
|
:customer_id => @credit_card.customer_id
|
86
|
-
}
|
83
|
+
},
|
87
84
|
)
|
88
85
|
result = Braintree::Subscription.create(
|
89
86
|
:payment_method_nonce => nonce,
|
90
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
87
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
91
88
|
)
|
92
89
|
|
93
|
-
result.success
|
90
|
+
expect(result.success?).to eq(true)
|
94
91
|
transaction = result.subscription.transactions[0]
|
95
|
-
transaction.credit_card_details.bin.
|
96
|
-
transaction.credit_card_details.last_4.
|
92
|
+
expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
93
|
+
expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4, 4])
|
97
94
|
end
|
98
95
|
|
99
96
|
it "creates a subscription when given a paypal account payment_method_nonce" do
|
100
97
|
customer = Braintree::Customer.create!
|
101
98
|
payment_method_result = Braintree::PaymentMethod.create(
|
102
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
103
|
-
:customer_id => customer.id
|
99
|
+
:payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
|
100
|
+
:customer_id => customer.id,
|
104
101
|
)
|
105
102
|
|
106
103
|
result = Braintree::Subscription.create(
|
107
104
|
:payment_method_token => payment_method_result.payment_method.token,
|
108
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
105
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
109
106
|
)
|
110
107
|
|
111
|
-
result.
|
108
|
+
expect(result).to be_success
|
112
109
|
transaction = result.subscription.transactions[0]
|
113
|
-
transaction.paypal_details.payer_email.
|
110
|
+
expect(transaction.paypal_details.payer_email).to eq("payer@example.com")
|
114
111
|
end
|
115
112
|
|
116
113
|
it "creates a subscription when given a paypal description" do
|
117
114
|
customer = Braintree::Customer.create!
|
118
115
|
payment_method_result = Braintree::PaymentMethod.create(
|
119
116
|
:payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
|
120
|
-
:customer_id => customer.id
|
117
|
+
:customer_id => customer.id,
|
121
118
|
)
|
122
119
|
|
123
120
|
result = Braintree::Subscription.create(
|
@@ -130,23 +127,22 @@ describe Braintree::Subscription do
|
|
130
127
|
},
|
131
128
|
)
|
132
129
|
|
133
|
-
result.
|
130
|
+
expect(result).to be_success
|
134
131
|
subscription = result.subscription
|
135
|
-
subscription.description.
|
132
|
+
expect(subscription.description).to eq("A great product")
|
136
133
|
transaction = subscription.transactions[0]
|
137
|
-
transaction.paypal_details.payer_email.
|
138
|
-
transaction.paypal_details.description.
|
134
|
+
expect(transaction.paypal_details.payer_email).to eq("payer@example.com")
|
135
|
+
expect(transaction.paypal_details.description).to eq("A great product")
|
139
136
|
end
|
140
137
|
|
141
138
|
it "returns an error if the payment_method_nonce hasn't been vaulted" do
|
142
|
-
customer = Braintree::Customer.create!
|
143
139
|
result = Braintree::Subscription.create(
|
144
140
|
:payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
|
145
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
141
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
146
142
|
)
|
147
143
|
|
148
|
-
result.
|
149
|
-
result.errors.for(:subscription).on(:payment_method_nonce).first.code.
|
144
|
+
expect(result).not_to be_success
|
145
|
+
expect(result.errors.for(:subscription).on(:payment_method_nonce).first.code).to eq("91925")
|
150
146
|
end
|
151
147
|
end
|
152
148
|
|
@@ -154,22 +150,22 @@ describe Braintree::Subscription do
|
|
154
150
|
it "inherits from the plan if not provided" do
|
155
151
|
result = Braintree::Subscription.create(
|
156
152
|
:payment_method_token => @credit_card.token,
|
157
|
-
:plan_id => SpecHelper::BillingDayOfMonthPlan[:id]
|
153
|
+
:plan_id => SpecHelper::BillingDayOfMonthPlan[:id],
|
158
154
|
)
|
159
155
|
|
160
|
-
result.success
|
161
|
-
result.subscription.billing_day_of_month.
|
156
|
+
expect(result.success?).to eq(true)
|
157
|
+
expect(result.subscription.billing_day_of_month).to eq(5)
|
162
158
|
end
|
163
159
|
|
164
160
|
it "allows overriding" do
|
165
161
|
result = Braintree::Subscription.create(
|
166
162
|
:payment_method_token => @credit_card.token,
|
167
163
|
:plan_id => SpecHelper::BillingDayOfMonthPlan[:id],
|
168
|
-
:billing_day_of_month => 25
|
164
|
+
:billing_day_of_month => 25,
|
169
165
|
)
|
170
166
|
|
171
|
-
result.success
|
172
|
-
result.subscription.billing_day_of_month.
|
167
|
+
expect(result.success?).to eq(true)
|
168
|
+
expect(result.subscription.billing_day_of_month).to eq(25)
|
173
169
|
end
|
174
170
|
|
175
171
|
it "allows overriding with start_immediately" do
|
@@ -178,11 +174,11 @@ describe Braintree::Subscription do
|
|
178
174
|
:plan_id => SpecHelper::BillingDayOfMonthPlan[:id],
|
179
175
|
:options => {
|
180
176
|
:start_immediately => true
|
181
|
-
}
|
177
|
+
},
|
182
178
|
)
|
183
179
|
|
184
|
-
result.success
|
185
|
-
result.subscription.transactions.size.
|
180
|
+
expect(result.success?).to eq(true)
|
181
|
+
expect(result.subscription.transactions.size).to eq(1)
|
186
182
|
end
|
187
183
|
end
|
188
184
|
|
@@ -191,23 +187,23 @@ describe Braintree::Subscription do
|
|
191
187
|
result = Braintree::Subscription.create(
|
192
188
|
:payment_method_token => @credit_card.token,
|
193
189
|
:plan_id => SpecHelper::BillingDayOfMonthPlan[:id],
|
194
|
-
:first_billing_date => Date.today + 3
|
190
|
+
:first_billing_date => Date.today + 3,
|
195
191
|
)
|
196
192
|
|
197
|
-
result.success
|
198
|
-
result.subscription.first_billing_date.
|
199
|
-
result.subscription.status.
|
193
|
+
expect(result.success?).to eq(true)
|
194
|
+
expect(result.subscription.first_billing_date).to eq(Date.today + 3)
|
195
|
+
expect(result.subscription.status).to eq(Braintree::Subscription::Status::Pending)
|
200
196
|
end
|
201
197
|
|
202
198
|
it "returns an error if the date is in the past" do
|
203
199
|
result = Braintree::Subscription.create(
|
204
200
|
:payment_method_token => @credit_card.token,
|
205
201
|
:plan_id => SpecHelper::BillingDayOfMonthPlan[:id],
|
206
|
-
:first_billing_date => Date.today - 3
|
202
|
+
:first_billing_date => Date.today - 3,
|
207
203
|
)
|
208
204
|
|
209
|
-
result.success
|
210
|
-
result.errors.for(:subscription).on(:first_billing_date).first.code.
|
205
|
+
expect(result.success?).to eq(false)
|
206
|
+
expect(result.errors.for(:subscription).on(:first_billing_date).first.code).to eq(Braintree::ErrorCodes::Subscription::FirstBillingDateCannotBeInThePast)
|
211
207
|
end
|
212
208
|
end
|
213
209
|
|
@@ -215,22 +211,22 @@ describe Braintree::Subscription do
|
|
215
211
|
it "defaults to the default merchant account if no merchant_account_id is provided" do
|
216
212
|
result = Braintree::Subscription.create(
|
217
213
|
:payment_method_token => @credit_card.token,
|
218
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
214
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
219
215
|
)
|
220
216
|
|
221
|
-
result.success
|
222
|
-
result.subscription.merchant_account_id.
|
217
|
+
expect(result.success?).to eq(true)
|
218
|
+
expect(result.subscription.merchant_account_id).to eq(SpecHelper::DefaultMerchantAccountId)
|
223
219
|
end
|
224
220
|
|
225
221
|
it "allows setting the merchant_account_id" do
|
226
222
|
result = Braintree::Subscription.create(
|
227
223
|
:payment_method_token => @credit_card.token,
|
228
224
|
:plan_id => SpecHelper::TrialPlan[:id],
|
229
|
-
:merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
|
225
|
+
:merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
230
226
|
)
|
231
227
|
|
232
|
-
result.success
|
233
|
-
result.subscription.merchant_account_id.
|
228
|
+
expect(result.success?).to eq(true)
|
229
|
+
expect(result.subscription.merchant_account_id).to eq(SpecHelper::NonDefaultMerchantAccountId)
|
234
230
|
end
|
235
231
|
end
|
236
232
|
|
@@ -239,22 +235,22 @@ describe Braintree::Subscription do
|
|
239
235
|
result = Braintree::Subscription.create(
|
240
236
|
:payment_method_token => @credit_card.token,
|
241
237
|
:plan_id => SpecHelper::TrialPlan[:id],
|
242
|
-
:number_of_billing_cycles => 10
|
238
|
+
:number_of_billing_cycles => 10,
|
243
239
|
)
|
244
240
|
|
245
|
-
result.success
|
246
|
-
result.subscription.number_of_billing_cycles.
|
241
|
+
expect(result.success?).to eq(true)
|
242
|
+
expect(result.subscription.number_of_billing_cycles).to eq(10)
|
247
243
|
end
|
248
244
|
|
249
245
|
it "sets the number of billing cycles to nil if :never_expires => true" do
|
250
246
|
result = Braintree::Subscription.create(
|
251
247
|
:payment_method_token => @credit_card.token,
|
252
248
|
:plan_id => SpecHelper::TrialPlan[:id],
|
253
|
-
:never_expires => true
|
249
|
+
:never_expires => true,
|
254
250
|
)
|
255
251
|
|
256
|
-
result.success
|
257
|
-
result.subscription.number_of_billing_cycles.
|
252
|
+
expect(result.success?).to eq(true)
|
253
|
+
expect(result.subscription.number_of_billing_cycles).to eq(nil)
|
258
254
|
end
|
259
255
|
end
|
260
256
|
|
@@ -263,23 +259,23 @@ describe Braintree::Subscription do
|
|
263
259
|
it "with no trial" do
|
264
260
|
result = Braintree::Subscription.create(
|
265
261
|
:payment_method_token => @credit_card.token,
|
266
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
262
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
267
263
|
)
|
268
264
|
|
269
|
-
result.subscription.trial_period.
|
270
|
-
result.subscription.trial_duration.
|
271
|
-
result.subscription.trial_duration_unit.
|
265
|
+
expect(result.subscription.trial_period).to eq(false)
|
266
|
+
expect(result.subscription.trial_duration).to eq(nil)
|
267
|
+
expect(result.subscription.trial_duration_unit).to eq(nil)
|
272
268
|
end
|
273
269
|
|
274
270
|
it "with a trial" do
|
275
271
|
result = Braintree::Subscription.create(
|
276
272
|
:payment_method_token => @credit_card.token,
|
277
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
273
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
278
274
|
)
|
279
275
|
|
280
|
-
result.subscription.trial_period.
|
281
|
-
result.subscription.trial_duration.
|
282
|
-
result.subscription.trial_duration_unit.
|
276
|
+
expect(result.subscription.trial_period).to eq(true)
|
277
|
+
expect(result.subscription.trial_duration).to eq(2)
|
278
|
+
expect(result.subscription.trial_duration_unit).to eq(Braintree::Subscription::TrialDurationUnit::Day)
|
283
279
|
end
|
284
280
|
|
285
281
|
it "can alter the trial period params" do
|
@@ -287,31 +283,31 @@ describe Braintree::Subscription do
|
|
287
283
|
:payment_method_token => @credit_card.token,
|
288
284
|
:plan_id => SpecHelper::TrialPlan[:id],
|
289
285
|
:trial_duration => 5,
|
290
|
-
:trial_duration_unit => Braintree::Subscription::TrialDurationUnit::Month
|
286
|
+
:trial_duration_unit => Braintree::Subscription::TrialDurationUnit::Month,
|
291
287
|
)
|
292
288
|
|
293
|
-
result.subscription.trial_period.
|
294
|
-
result.subscription.trial_duration.
|
295
|
-
result.subscription.trial_duration_unit.
|
289
|
+
expect(result.subscription.trial_period).to eq(true)
|
290
|
+
expect(result.subscription.trial_duration).to eq(5)
|
291
|
+
expect(result.subscription.trial_duration_unit).to eq(Braintree::Subscription::TrialDurationUnit::Month)
|
296
292
|
end
|
297
293
|
|
298
294
|
it "can override the trial_period param" do
|
299
295
|
result = Braintree::Subscription.create(
|
300
296
|
:payment_method_token => @credit_card.token,
|
301
297
|
:plan_id => SpecHelper::TrialPlan[:id],
|
302
|
-
:trial_period => false
|
298
|
+
:trial_period => false,
|
303
299
|
)
|
304
300
|
|
305
|
-
result.subscription.trial_period.
|
301
|
+
expect(result.subscription.trial_period).to eq(false)
|
306
302
|
end
|
307
303
|
|
308
304
|
it "doesn't create a transaction if there's a trial period" do
|
309
305
|
result = Braintree::Subscription.create(
|
310
306
|
:payment_method_token => @credit_card.token,
|
311
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
307
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
312
308
|
)
|
313
309
|
|
314
|
-
result.subscription.transactions.size.
|
310
|
+
expect(result.subscription.transactions.size).to eq(0)
|
315
311
|
end
|
316
312
|
end
|
317
313
|
|
@@ -319,26 +315,26 @@ describe Braintree::Subscription do
|
|
319
315
|
it "creates a transaction if no trial period" do
|
320
316
|
result = Braintree::Subscription.create(
|
321
317
|
:payment_method_token => @credit_card.token,
|
322
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
318
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
323
319
|
)
|
324
320
|
|
325
|
-
result.subscription.transactions.size.
|
326
|
-
result.subscription.transactions.first.
|
327
|
-
result.subscription.transactions.first.amount.
|
328
|
-
result.subscription.transactions.first.type.
|
329
|
-
result.subscription.transactions.first.subscription_id.
|
321
|
+
expect(result.subscription.transactions.size).to eq(1)
|
322
|
+
expect(result.subscription.transactions.first).to be_a(Braintree::Transaction)
|
323
|
+
expect(result.subscription.transactions.first.amount).to eq(SpecHelper::TriallessPlan[:price])
|
324
|
+
expect(result.subscription.transactions.first.type).to eq(Braintree::Transaction::Type::Sale)
|
325
|
+
expect(result.subscription.transactions.first.subscription_id).to eq(result.subscription.id)
|
330
326
|
end
|
331
327
|
|
332
328
|
it "does not create the subscription and returns the transaction if the transaction is not successful" do
|
333
329
|
result = Braintree::Subscription.create(
|
334
330
|
:payment_method_token => @credit_card.token,
|
335
331
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
336
|
-
:price => Braintree::Test::TransactionAmounts::Decline
|
332
|
+
:price => Braintree::Test::TransactionAmounts::Decline,
|
337
333
|
)
|
338
334
|
|
339
|
-
result.success
|
340
|
-
result.transaction.status.
|
341
|
-
result.message.
|
335
|
+
expect(result.success?).to be(false)
|
336
|
+
expect(result.transaction.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
337
|
+
expect(result.message).to eq("Do Not Honor")
|
342
338
|
end
|
343
339
|
end
|
344
340
|
|
@@ -346,20 +342,20 @@ describe Braintree::Subscription do
|
|
346
342
|
it "defaults to the plan's price" do
|
347
343
|
result = Braintree::Subscription.create(
|
348
344
|
:payment_method_token => @credit_card.token,
|
349
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
345
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
350
346
|
)
|
351
347
|
|
352
|
-
result.subscription.price.
|
348
|
+
expect(result.subscription.price).to eq(SpecHelper::TrialPlan[:price])
|
353
349
|
end
|
354
350
|
|
355
351
|
it "can be overridden" do
|
356
352
|
result = Braintree::Subscription.create(
|
357
353
|
:payment_method_token => @credit_card.token,
|
358
354
|
:plan_id => SpecHelper::TrialPlan[:id],
|
359
|
-
:price => 98.76
|
355
|
+
:price => 98.76,
|
360
356
|
)
|
361
357
|
|
362
|
-
result.subscription.price.
|
358
|
+
expect(result.subscription.price).to eq(BigDecimal("98.76"))
|
363
359
|
end
|
364
360
|
end
|
365
361
|
end
|
@@ -369,10 +365,10 @@ describe Braintree::Subscription do
|
|
369
365
|
result = Braintree::Subscription.create(
|
370
366
|
:payment_method_token => @credit_card.token,
|
371
367
|
:plan_id => SpecHelper::TrialPlan[:id],
|
372
|
-
:id => "invalid token"
|
368
|
+
:id => "invalid token",
|
373
369
|
)
|
374
|
-
result.success
|
375
|
-
result.errors.for(:subscription).on(:id)[0].message.
|
370
|
+
expect(result.success?).to eq(false)
|
371
|
+
expect(result.errors.for(:subscription).on(:id)[0].message).to eq("ID is invalid (use only letters, numbers, '-', and '_').")
|
376
372
|
end
|
377
373
|
|
378
374
|
it "has validation errors on duplicate id" do
|
@@ -380,17 +376,17 @@ describe Braintree::Subscription do
|
|
380
376
|
result = Braintree::Subscription.create(
|
381
377
|
:payment_method_token => @credit_card.token,
|
382
378
|
:plan_id => SpecHelper::TrialPlan[:id],
|
383
|
-
:id => duplicate_token
|
379
|
+
:id => duplicate_token,
|
384
380
|
)
|
385
|
-
result.success
|
381
|
+
expect(result.success?).to eq(true)
|
386
382
|
|
387
383
|
result = Braintree::Subscription.create(
|
388
384
|
:payment_method_token => @credit_card.token,
|
389
385
|
:plan_id => SpecHelper::TrialPlan[:id],
|
390
|
-
:id => duplicate_token
|
386
|
+
:id => duplicate_token,
|
391
387
|
)
|
392
|
-
result.success
|
393
|
-
result.errors.for(:subscription).on(:id)[0].message.
|
388
|
+
expect(result.success?).to eq(false)
|
389
|
+
expect(result.errors.for(:subscription).on(:id)[0].message).to eq("ID has already been taken.")
|
394
390
|
end
|
395
391
|
|
396
392
|
it "trial duration required" do
|
@@ -398,10 +394,10 @@ describe Braintree::Subscription do
|
|
398
394
|
:payment_method_token => @credit_card.token,
|
399
395
|
:plan_id => SpecHelper::TrialPlan[:id],
|
400
396
|
:trial_period => true,
|
401
|
-
:trial_duration => nil
|
397
|
+
:trial_duration => nil,
|
402
398
|
)
|
403
|
-
result.success
|
404
|
-
result.errors.for(:subscription).on(:trial_duration)[0].message.
|
399
|
+
expect(result.success?).to eq(false)
|
400
|
+
expect(result.errors.for(:subscription).on(:trial_duration)[0].message).to eq("Trial Duration is required.")
|
405
401
|
end
|
406
402
|
|
407
403
|
it "trial duration unit required" do
|
@@ -410,10 +406,10 @@ describe Braintree::Subscription do
|
|
410
406
|
:plan_id => SpecHelper::TrialPlan[:id],
|
411
407
|
:trial_period => true,
|
412
408
|
:trial_duration => 2,
|
413
|
-
:trial_duration_unit => nil
|
409
|
+
:trial_duration_unit => nil,
|
414
410
|
)
|
415
|
-
result.success
|
416
|
-
result.errors.for(:subscription).on(:trial_duration_unit)[0].message.
|
411
|
+
expect(result.success?).to eq(false)
|
412
|
+
expect(result.errors.for(:subscription).on(:trial_duration_unit)[0].message).to eq("Trial Duration Unit is invalid.")
|
417
413
|
end
|
418
414
|
end
|
419
415
|
|
@@ -422,58 +418,58 @@ describe Braintree::Subscription do
|
|
422
418
|
result = Braintree::Subscription.create(
|
423
419
|
:payment_method_token => @credit_card.token,
|
424
420
|
:plan_id => SpecHelper::AddOnDiscountPlan[:id],
|
425
|
-
:options => {:do_not_inherit_add_ons_or_discounts => true}
|
421
|
+
:options => {:do_not_inherit_add_ons_or_discounts => true},
|
426
422
|
)
|
427
|
-
result.success
|
423
|
+
expect(result.success?).to eq(true)
|
428
424
|
|
429
425
|
subscription = result.subscription
|
430
426
|
|
431
|
-
subscription.add_ons.size.
|
432
|
-
subscription.discounts.size.
|
427
|
+
expect(subscription.add_ons.size).to eq(0)
|
428
|
+
expect(subscription.discounts.size).to eq(0)
|
433
429
|
end
|
434
430
|
|
435
431
|
it "inherits the add_ons and discounts from the plan when not specified" do
|
436
432
|
result = Braintree::Subscription.create(
|
437
433
|
:payment_method_token => @credit_card.token,
|
438
|
-
:plan_id => SpecHelper::AddOnDiscountPlan[:id]
|
434
|
+
:plan_id => SpecHelper::AddOnDiscountPlan[:id],
|
439
435
|
)
|
440
|
-
result.success
|
436
|
+
expect(result.success?).to eq(true)
|
441
437
|
|
442
438
|
subscription = result.subscription
|
443
439
|
|
444
|
-
subscription.add_ons.size.
|
440
|
+
expect(subscription.add_ons.size).to eq(2)
|
445
441
|
add_ons = subscription.add_ons.sort_by { |add_on| add_on.id }
|
446
442
|
|
447
|
-
add_ons.first.id.
|
448
|
-
add_ons.first.amount.
|
449
|
-
add_ons.first.quantity.
|
450
|
-
add_ons.first.number_of_billing_cycles.
|
451
|
-
add_ons.first.never_expires
|
452
|
-
add_ons.first.current_billing_cycle.
|
453
|
-
|
454
|
-
add_ons.last.id.
|
455
|
-
add_ons.last.amount.
|
456
|
-
add_ons.last.quantity.
|
457
|
-
add_ons.last.number_of_billing_cycles.
|
458
|
-
add_ons.last.never_expires
|
459
|
-
add_ons.last.current_billing_cycle.
|
460
|
-
|
461
|
-
subscription.discounts.size.
|
443
|
+
expect(add_ons.first.id).to eq("increase_10")
|
444
|
+
expect(add_ons.first.amount).to eq(BigDecimal("10.00"))
|
445
|
+
expect(add_ons.first.quantity).to eq(1)
|
446
|
+
expect(add_ons.first.number_of_billing_cycles).to be_nil
|
447
|
+
expect(add_ons.first.never_expires?).to be(true)
|
448
|
+
expect(add_ons.first.current_billing_cycle).to eq(0)
|
449
|
+
|
450
|
+
expect(add_ons.last.id).to eq("increase_20")
|
451
|
+
expect(add_ons.last.amount).to eq(BigDecimal("20.00"))
|
452
|
+
expect(add_ons.last.quantity).to eq(1)
|
453
|
+
expect(add_ons.last.number_of_billing_cycles).to be_nil
|
454
|
+
expect(add_ons.last.never_expires?).to be(true)
|
455
|
+
expect(add_ons.last.current_billing_cycle).to eq(0)
|
456
|
+
|
457
|
+
expect(subscription.discounts.size).to eq(2)
|
462
458
|
discounts = subscription.discounts.sort_by { |discount| discount.id }
|
463
459
|
|
464
|
-
discounts.first.id.
|
465
|
-
discounts.first.amount.
|
466
|
-
discounts.first.quantity.
|
467
|
-
discounts.first.number_of_billing_cycles.
|
468
|
-
discounts.first.never_expires
|
469
|
-
discounts.first.current_billing_cycle.
|
460
|
+
expect(discounts.first.id).to eq("discount_11")
|
461
|
+
expect(discounts.first.amount).to eq(BigDecimal("11.00"))
|
462
|
+
expect(discounts.first.quantity).to eq(1)
|
463
|
+
expect(discounts.first.number_of_billing_cycles).to be_nil
|
464
|
+
expect(discounts.first.never_expires?).to be(true)
|
465
|
+
expect(discounts.first.current_billing_cycle).to eq(0)
|
470
466
|
|
471
|
-
discounts.last.id.
|
472
|
-
discounts.last.amount.
|
473
|
-
discounts.last.quantity.
|
474
|
-
discounts.last.number_of_billing_cycles.
|
475
|
-
discounts.last.never_expires
|
476
|
-
discounts.last.current_billing_cycle.
|
467
|
+
expect(discounts.last.id).to eq("discount_7")
|
468
|
+
expect(discounts.last.amount).to eq(BigDecimal("7.00"))
|
469
|
+
expect(discounts.last.quantity).to eq(1)
|
470
|
+
expect(discounts.last.number_of_billing_cycles).to be_nil
|
471
|
+
expect(discounts.last.never_expires?).to be(true)
|
472
|
+
expect(discounts.last.current_billing_cycle).to eq(0)
|
477
473
|
end
|
478
474
|
|
479
475
|
it "allows overriding of inherited add_ons and discounts" do
|
@@ -499,41 +495,41 @@ describe Braintree::Subscription do
|
|
499
495
|
:never_expires => true
|
500
496
|
}
|
501
497
|
]
|
502
|
-
}
|
498
|
+
},
|
503
499
|
)
|
504
|
-
result.success
|
500
|
+
expect(result.success?).to eq(true)
|
505
501
|
|
506
502
|
subscription = result.subscription
|
507
503
|
|
508
|
-
subscription.add_ons.size.
|
504
|
+
expect(subscription.add_ons.size).to eq(2)
|
509
505
|
add_ons = subscription.add_ons.sort_by { |add_on| add_on.id }
|
510
506
|
|
511
|
-
add_ons.first.id.
|
512
|
-
add_ons.first.amount.
|
513
|
-
add_ons.first.quantity.
|
514
|
-
add_ons.first.number_of_billing_cycles.
|
515
|
-
add_ons.first.never_expires
|
516
|
-
add_ons.first.current_billing_cycle.
|
507
|
+
expect(add_ons.first.id).to eq("increase_10")
|
508
|
+
expect(add_ons.first.amount).to eq(BigDecimal("50.00"))
|
509
|
+
expect(add_ons.first.quantity).to eq(2)
|
510
|
+
expect(add_ons.first.number_of_billing_cycles).to eq(5)
|
511
|
+
expect(add_ons.first.never_expires?).to be(false)
|
512
|
+
expect(add_ons.first.current_billing_cycle).to eq(0)
|
517
513
|
|
518
|
-
add_ons.last.id.
|
519
|
-
add_ons.last.amount.
|
520
|
-
add_ons.last.quantity.
|
521
|
-
add_ons.last.current_billing_cycle.
|
514
|
+
expect(add_ons.last.id).to eq("increase_20")
|
515
|
+
expect(add_ons.last.amount).to eq(BigDecimal("20.00"))
|
516
|
+
expect(add_ons.last.quantity).to eq(1)
|
517
|
+
expect(add_ons.last.current_billing_cycle).to eq(0)
|
522
518
|
|
523
|
-
subscription.discounts.size.
|
519
|
+
expect(subscription.discounts.size).to eq(2)
|
524
520
|
discounts = subscription.discounts.sort_by { |discount| discount.id }
|
525
521
|
|
526
|
-
discounts.first.id.
|
527
|
-
discounts.first.amount.
|
528
|
-
discounts.first.quantity.
|
529
|
-
discounts.first.current_billing_cycle.
|
522
|
+
expect(discounts.first.id).to eq("discount_11")
|
523
|
+
expect(discounts.first.amount).to eq(BigDecimal("11.00"))
|
524
|
+
expect(discounts.first.quantity).to eq(1)
|
525
|
+
expect(discounts.first.current_billing_cycle).to eq(0)
|
530
526
|
|
531
|
-
discounts.last.id.
|
532
|
-
discounts.last.amount.
|
533
|
-
discounts.last.quantity.
|
534
|
-
discounts.last.number_of_billing_cycles.
|
535
|
-
discounts.last.never_expires
|
536
|
-
discounts.last.current_billing_cycle.
|
527
|
+
expect(discounts.last.id).to eq("discount_7")
|
528
|
+
expect(discounts.last.amount).to eq(BigDecimal("15.00"))
|
529
|
+
expect(discounts.last.quantity).to eq(3)
|
530
|
+
expect(discounts.last.number_of_billing_cycles).to be_nil
|
531
|
+
expect(discounts.last.never_expires?).to be(true)
|
532
|
+
expect(discounts.last.current_billing_cycle).to eq(0)
|
537
533
|
end
|
538
534
|
|
539
535
|
it "allows deleting of inherited add_ons and discounts" do
|
@@ -545,23 +541,23 @@ describe Braintree::Subscription do
|
|
545
541
|
},
|
546
542
|
:discounts => {
|
547
543
|
:remove => [SpecHelper::Discount7]
|
548
|
-
}
|
544
|
+
},
|
549
545
|
)
|
550
|
-
result.success
|
546
|
+
expect(result.success?).to eq(true)
|
551
547
|
|
552
548
|
subscription = result.subscription
|
553
549
|
|
554
|
-
subscription.add_ons.size.
|
555
|
-
subscription.add_ons.first.id.
|
556
|
-
subscription.add_ons.first.amount.
|
557
|
-
subscription.add_ons.first.quantity.
|
558
|
-
subscription.add_ons.first.current_billing_cycle.
|
550
|
+
expect(subscription.add_ons.size).to eq(1)
|
551
|
+
expect(subscription.add_ons.first.id).to eq("increase_20")
|
552
|
+
expect(subscription.add_ons.first.amount).to eq(BigDecimal("20.00"))
|
553
|
+
expect(subscription.add_ons.first.quantity).to eq(1)
|
554
|
+
expect(subscription.add_ons.first.current_billing_cycle).to eq(0)
|
559
555
|
|
560
|
-
subscription.discounts.size.
|
561
|
-
subscription.discounts.last.id.
|
562
|
-
subscription.discounts.last.amount.
|
563
|
-
subscription.discounts.last.quantity.
|
564
|
-
subscription.discounts.last.current_billing_cycle.
|
556
|
+
expect(subscription.discounts.size).to eq(1)
|
557
|
+
expect(subscription.discounts.last.id).to eq("discount_11")
|
558
|
+
expect(subscription.discounts.last.amount).to eq(BigDecimal("11.00"))
|
559
|
+
expect(subscription.discounts.last.quantity).to eq(1)
|
560
|
+
expect(subscription.discounts.last.current_billing_cycle).to eq(0)
|
565
561
|
end
|
566
562
|
|
567
563
|
it "allows adding new add_ons and discounts" do
|
@@ -573,40 +569,40 @@ describe Braintree::Subscription do
|
|
573
569
|
},
|
574
570
|
:discounts => {
|
575
571
|
:add => [{:inherited_from_id => SpecHelper::Discount15}]
|
576
|
-
}
|
572
|
+
},
|
577
573
|
)
|
578
|
-
result.success
|
574
|
+
expect(result.success?).to eq(true)
|
579
575
|
subscription = result.subscription
|
580
576
|
|
581
|
-
subscription.add_ons.size.
|
577
|
+
expect(subscription.add_ons.size).to eq(3)
|
582
578
|
add_ons = subscription.add_ons.sort_by { |add_on| add_on.id }
|
583
579
|
|
584
|
-
add_ons[0].id.
|
585
|
-
add_ons[0].amount.
|
586
|
-
add_ons[0].quantity.
|
580
|
+
expect(add_ons[0].id).to eq("increase_10")
|
581
|
+
expect(add_ons[0].amount).to eq(BigDecimal("10.00"))
|
582
|
+
expect(add_ons[0].quantity).to eq(1)
|
587
583
|
|
588
|
-
add_ons[1].id.
|
589
|
-
add_ons[1].amount.
|
590
|
-
add_ons[1].quantity.
|
584
|
+
expect(add_ons[1].id).to eq("increase_20")
|
585
|
+
expect(add_ons[1].amount).to eq(BigDecimal("20.00"))
|
586
|
+
expect(add_ons[1].quantity).to eq(1)
|
591
587
|
|
592
|
-
add_ons[2].id.
|
593
|
-
add_ons[2].amount.
|
594
|
-
add_ons[2].quantity.
|
588
|
+
expect(add_ons[2].id).to eq("increase_30")
|
589
|
+
expect(add_ons[2].amount).to eq(BigDecimal("30.00"))
|
590
|
+
expect(add_ons[2].quantity).to eq(1)
|
595
591
|
|
596
|
-
subscription.discounts.size.
|
592
|
+
expect(subscription.discounts.size).to eq(3)
|
597
593
|
discounts = subscription.discounts.sort_by { |discount| discount.id }
|
598
594
|
|
599
|
-
discounts[0].id.
|
600
|
-
discounts[0].amount.
|
601
|
-
discounts[0].quantity.
|
595
|
+
expect(discounts[0].id).to eq("discount_11")
|
596
|
+
expect(discounts[0].amount).to eq(BigDecimal("11.00"))
|
597
|
+
expect(discounts[0].quantity).to eq(1)
|
602
598
|
|
603
|
-
discounts[1].id.
|
604
|
-
discounts[1].amount.
|
605
|
-
discounts[1].quantity.
|
599
|
+
expect(discounts[1].id).to eq("discount_15")
|
600
|
+
expect(discounts[1].amount).to eq(BigDecimal("15.00"))
|
601
|
+
expect(discounts[1].quantity).to eq(1)
|
606
602
|
|
607
|
-
discounts[2].id.
|
608
|
-
discounts[2].amount.
|
609
|
-
discounts[2].quantity.
|
603
|
+
expect(discounts[2].id).to eq("discount_7")
|
604
|
+
expect(discounts[2].amount).to eq(BigDecimal("7.00"))
|
605
|
+
expect(discounts[2].quantity).to eq(1)
|
610
606
|
end
|
611
607
|
|
612
608
|
it "properly parses validation errors for arrays" do
|
@@ -624,11 +620,11 @@ describe Braintree::Subscription do
|
|
624
620
|
:quantity => -10,
|
625
621
|
}
|
626
622
|
]
|
627
|
-
}
|
623
|
+
},
|
628
624
|
)
|
629
|
-
result.success
|
630
|
-
result.errors.for(:subscription).for(:add_ons).for(:update).for_index(0).on(:amount)[0].code.
|
631
|
-
result.errors.for(:subscription).for(:add_ons).for(:update).for_index(1).on(:quantity)[0].code.
|
625
|
+
expect(result.success?).to eq(false)
|
626
|
+
expect(result.errors.for(:subscription).for(:add_ons).for(:update).for_index(0).on(:amount)[0].code).to eq(Braintree::ErrorCodes::Subscription::Modification::AmountIsInvalid)
|
627
|
+
expect(result.errors.for(:subscription).for(:add_ons).for(:update).for_index(1).on(:quantity)[0].code).to eq(Braintree::ErrorCodes::Subscription::Modification::QuantityIsInvalid)
|
632
628
|
end
|
633
629
|
end
|
634
630
|
|
@@ -638,19 +634,19 @@ describe Braintree::Subscription do
|
|
638
634
|
:payment_method_token => @credit_card.token,
|
639
635
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
640
636
|
:descriptor => {
|
641
|
-
:name =>
|
642
|
-
:phone =>
|
643
|
-
}
|
637
|
+
:name => "123*123456789012345678",
|
638
|
+
:phone => "3334445555"
|
639
|
+
},
|
644
640
|
)
|
645
641
|
|
646
|
-
result.success
|
647
|
-
result.subscription.descriptor.name.
|
648
|
-
result.subscription.descriptor.phone.
|
642
|
+
expect(result.success?).to eq(true)
|
643
|
+
expect(result.subscription.descriptor.name).to eq("123*123456789012345678")
|
644
|
+
expect(result.subscription.descriptor.phone).to eq("3334445555")
|
649
645
|
|
650
|
-
result.subscription.transactions.size.
|
646
|
+
expect(result.subscription.transactions.size).to eq(1)
|
651
647
|
transaction = result.subscription.transactions.first
|
652
|
-
transaction.descriptor.name.
|
653
|
-
transaction.descriptor.phone.
|
648
|
+
expect(transaction.descriptor.name).to eq("123*123456789012345678")
|
649
|
+
expect(transaction.descriptor.phone).to eq("3334445555")
|
654
650
|
end
|
655
651
|
|
656
652
|
it "has validation errors if format is invalid" do
|
@@ -658,15 +654,15 @@ describe Braintree::Subscription do
|
|
658
654
|
:payment_method_token => @credit_card.token,
|
659
655
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
660
656
|
:descriptor => {
|
661
|
-
:name =>
|
662
|
-
:phone =>
|
657
|
+
:name => "badcompanyname12*badproduct12",
|
658
|
+
:phone => "%bad4445555",
|
663
659
|
:url => "12345678901234"
|
664
|
-
}
|
660
|
+
},
|
665
661
|
)
|
666
|
-
result.success
|
667
|
-
result.errors.for(:subscription).for(:descriptor).on(:name)[0].code.
|
668
|
-
result.errors.for(:subscription).for(:descriptor).on(:phone)[0].code.
|
669
|
-
result.errors.for(:subscription).for(:descriptor).on(:url)[0].code.
|
662
|
+
expect(result.success?).to eq(false)
|
663
|
+
expect(result.errors.for(:subscription).for(:descriptor).on(:name)[0].code).to eq(Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid)
|
664
|
+
expect(result.errors.for(:subscription).for(:descriptor).on(:phone)[0].code).to eq(Braintree::ErrorCodes::Descriptor::PhoneFormatIsInvalid)
|
665
|
+
expect(result.errors.for(:subscription).for(:descriptor).on(:url)[0].code).to eq(Braintree::ErrorCodes::Descriptor::UrlFormatIsInvalid)
|
670
666
|
end
|
671
667
|
end
|
672
668
|
end
|
@@ -675,32 +671,30 @@ describe Braintree::Subscription do
|
|
675
671
|
it "returns the subscription if valid" do
|
676
672
|
subscription = Braintree::Subscription.create!(
|
677
673
|
:payment_method_token => @credit_card.token,
|
678
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
674
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
679
675
|
)
|
680
676
|
|
681
|
-
|
682
|
-
subscription.
|
683
|
-
subscription.
|
684
|
-
|
685
|
-
|
686
|
-
subscription.
|
687
|
-
subscription.
|
688
|
-
subscription.
|
689
|
-
subscription.
|
690
|
-
|
691
|
-
|
692
|
-
subscription.
|
693
|
-
subscription.
|
694
|
-
subscription.
|
695
|
-
subscription.next_billing_period_amount.should == "12.34"
|
696
|
-
subscription.payment_method_token.should == @credit_card.token
|
677
|
+
expect(subscription.id).to match(/^\w{6}$/)
|
678
|
+
expect(subscription.status).to eq(Braintree::Subscription::Status::Active)
|
679
|
+
expect(subscription.plan_id).to eq("integration_trialless_plan")
|
680
|
+
|
681
|
+
expect(subscription.first_billing_date).to be_a Date
|
682
|
+
expect(subscription.next_billing_date).to be_a Date
|
683
|
+
expect(subscription.billing_period_start_date).to be_a Date
|
684
|
+
expect(subscription.billing_period_end_date).to be_a Date
|
685
|
+
expect(subscription.paid_through_date).to be_a Date
|
686
|
+
|
687
|
+
expect(subscription.failure_count).to eq(0)
|
688
|
+
expect(subscription.current_billing_cycle).to eq(1)
|
689
|
+
expect(subscription.next_billing_period_amount).to eq("12.34")
|
690
|
+
expect(subscription.payment_method_token).to eq(@credit_card.token)
|
697
691
|
end
|
698
692
|
|
699
693
|
it "raises a ValidationsFailed if invalid" do
|
700
694
|
expect do
|
701
695
|
Braintree::Subscription.create!(
|
702
696
|
:payment_method_token => @credit_card.token,
|
703
|
-
:plan_id =>
|
697
|
+
:plan_id => "not_a_plan_id",
|
704
698
|
)
|
705
699
|
end.to raise_error(Braintree::ValidationsFailed)
|
706
700
|
end
|
@@ -710,16 +704,16 @@ describe Braintree::Subscription do
|
|
710
704
|
it "finds a subscription" do
|
711
705
|
result = Braintree::Subscription.create(
|
712
706
|
:payment_method_token => @credit_card.token,
|
713
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
707
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
714
708
|
)
|
715
|
-
result.success
|
709
|
+
expect(result.success?).to eq(true)
|
716
710
|
|
717
|
-
Braintree::Subscription.find(result.subscription.id).
|
711
|
+
expect(Braintree::Subscription.find(result.subscription.id)).to eq(result.subscription)
|
718
712
|
end
|
719
713
|
|
720
714
|
it "raises Braintree::NotFoundError if it cannot find" do
|
721
715
|
expect {
|
722
|
-
Braintree::Subscription.find(
|
716
|
+
Braintree::Subscription.find("noSuchSubscription")
|
723
717
|
}.to raise_error(Braintree::NotFoundError, 'subscription with id "noSuchSubscription" not found')
|
724
718
|
end
|
725
719
|
end
|
@@ -729,31 +723,31 @@ describe Braintree::Subscription do
|
|
729
723
|
@subscription = Braintree::Subscription.create(
|
730
724
|
:payment_method_token => @credit_card.token,
|
731
725
|
:price => 54.32,
|
732
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
726
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
733
727
|
).subscription
|
734
728
|
end
|
735
729
|
|
736
730
|
it "allows changing the merchant_account_id" do
|
737
731
|
result = Braintree::Subscription.update(@subscription.id,
|
738
|
-
:merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
|
732
|
+
:merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
739
733
|
)
|
740
734
|
|
741
|
-
result.success
|
742
|
-
result.subscription.merchant_account_id.
|
735
|
+
expect(result.success?).to eq(true)
|
736
|
+
expect(result.subscription.merchant_account_id).to eq(SpecHelper::NonDefaultMerchantAccountId)
|
743
737
|
end
|
744
738
|
|
745
739
|
it "allows changing the payment method by payment_method_token" do
|
746
740
|
new_credit_card = Braintree::CreditCard.create!(
|
747
741
|
:customer_id => @credit_card.customer_id,
|
748
742
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
749
|
-
:expiration_date => "05/2010"
|
743
|
+
:expiration_date => "05/2010",
|
750
744
|
)
|
751
745
|
|
752
746
|
result = Braintree::Subscription.update(@subscription.id,
|
753
|
-
:payment_method_token => new_credit_card.token
|
747
|
+
:payment_method_token => new_credit_card.token,
|
754
748
|
)
|
755
749
|
|
756
|
-
result.subscription.payment_method_token.
|
750
|
+
expect(result.subscription.payment_method_token).to eq(new_credit_card.token)
|
757
751
|
end
|
758
752
|
|
759
753
|
it "allows changing the payment_method by payment_method_nonce" do
|
@@ -764,52 +758,52 @@ describe Braintree::Subscription do
|
|
764
758
|
},
|
765
759
|
:client_token_options => {
|
766
760
|
:customer_id => @credit_card.customer_id,
|
767
|
-
}
|
761
|
+
},
|
768
762
|
)
|
769
763
|
|
770
764
|
result = Braintree::Subscription.update(@subscription.id, :payment_method_nonce => nonce)
|
771
|
-
result.subscription.transactions[0].credit_card_details.token.
|
772
|
-
result.subscription.payment_method_token.
|
765
|
+
expect(result.subscription.transactions[0].credit_card_details.token).to eq(@credit_card.token)
|
766
|
+
expect(result.subscription.payment_method_token).not_to eq(@credit_card.token)
|
773
767
|
end
|
774
768
|
|
775
769
|
it "allows changing the descriptors" do
|
776
770
|
result = Braintree::Subscription.update(@subscription.id,
|
777
771
|
:descriptor => {
|
778
|
-
:name =>
|
779
|
-
:phone =>
|
772
|
+
:name => "aaa*1234",
|
773
|
+
:phone => "3334443333",
|
780
774
|
:url => "ebay.com"
|
781
|
-
}
|
775
|
+
},
|
782
776
|
)
|
783
777
|
|
784
|
-
result.success
|
785
|
-
result.subscription.descriptor.name.
|
786
|
-
result.subscription.descriptor.phone.
|
787
|
-
result.subscription.descriptor.url.
|
778
|
+
expect(result.success?).to eq(true)
|
779
|
+
expect(result.subscription.descriptor.name).to eq("aaa*1234")
|
780
|
+
expect(result.subscription.descriptor.phone).to eq("3334443333")
|
781
|
+
expect(result.subscription.descriptor.url).to eq("ebay.com")
|
788
782
|
end
|
789
783
|
|
790
784
|
it "allows changing the paypal description" do
|
791
785
|
customer = Braintree::Customer.create!
|
792
786
|
payment_method = Braintree::PaymentMethod.create(
|
793
787
|
:payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
|
794
|
-
:customer_id => customer.id
|
788
|
+
:customer_id => customer.id,
|
795
789
|
).payment_method
|
796
790
|
|
797
791
|
subscription = Braintree::Subscription.create(
|
798
792
|
:payment_method_token => payment_method.token,
|
799
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
793
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
800
794
|
).subscription
|
801
795
|
|
802
796
|
result = Braintree::Subscription.update(
|
803
797
|
subscription.id,
|
804
798
|
:options => {
|
805
799
|
:paypal => {
|
806
|
-
:description =>
|
800
|
+
:description => "A great product",
|
807
801
|
},
|
808
802
|
},
|
809
803
|
)
|
810
804
|
|
811
|
-
result.success
|
812
|
-
result.subscription.description.
|
805
|
+
expect(result.success?).to eq(true)
|
806
|
+
expect(result.subscription.description).to eq("A great product")
|
813
807
|
end
|
814
808
|
|
815
809
|
context "when successful" do
|
@@ -818,56 +812,56 @@ describe Braintree::Subscription do
|
|
818
812
|
result = Braintree::Subscription.update(@subscription.id,
|
819
813
|
:id => new_id,
|
820
814
|
:price => 9999.88,
|
821
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
815
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
822
816
|
)
|
823
817
|
|
824
|
-
result.success
|
825
|
-
result.subscription.id.
|
826
|
-
result.subscription.plan_id.
|
827
|
-
result.subscription.price.
|
818
|
+
expect(result.success?).to eq(true)
|
819
|
+
expect(result.subscription.id).to match(/#{new_id}/)
|
820
|
+
expect(result.subscription.plan_id).to eq(SpecHelper::TrialPlan[:id])
|
821
|
+
expect(result.subscription.price).to eq(BigDecimal("9999.88"))
|
828
822
|
end
|
829
823
|
|
830
824
|
context "proration" do
|
831
825
|
it "prorates if there is a charge (because merchant has proration option enabled in control panel)" do
|
832
826
|
result = Braintree::Subscription.update(@subscription.id,
|
833
|
-
:price => @subscription.price.to_f + 1
|
827
|
+
:price => @subscription.price.to_f + 1,
|
834
828
|
)
|
835
829
|
|
836
|
-
result.success
|
837
|
-
result.subscription.price.to_f.
|
838
|
-
result.subscription.transactions.size.
|
830
|
+
expect(result.success?).to eq(true)
|
831
|
+
expect(result.subscription.price.to_f).to eq(@subscription.price.to_f + 1)
|
832
|
+
expect(result.subscription.transactions.size).to eq(@subscription.transactions.size + 1)
|
839
833
|
end
|
840
834
|
|
841
835
|
it "allows the user to force proration if there is a charge" do
|
842
836
|
result = Braintree::Subscription.update(@subscription.id,
|
843
837
|
:price => @subscription.price.to_f + 1,
|
844
|
-
:options => {
|
838
|
+
:options => {:prorate_charges => true},
|
845
839
|
)
|
846
840
|
|
847
|
-
result.success
|
848
|
-
result.subscription.price.to_f.
|
849
|
-
result.subscription.transactions.size.
|
841
|
+
expect(result.success?).to eq(true)
|
842
|
+
expect(result.subscription.price.to_f).to eq(@subscription.price.to_f + 1)
|
843
|
+
expect(result.subscription.transactions.size).to eq(@subscription.transactions.size + 1)
|
850
844
|
end
|
851
845
|
|
852
846
|
it "allows the user to prevent proration if there is a charge" do
|
853
847
|
result = Braintree::Subscription.update(@subscription.id,
|
854
848
|
:price => @subscription.price.to_f + 1,
|
855
|
-
:options => {
|
849
|
+
:options => {:prorate_charges => false},
|
856
850
|
)
|
857
851
|
|
858
|
-
result.success
|
859
|
-
result.subscription.price.to_f.
|
860
|
-
result.subscription.transactions.size.
|
852
|
+
expect(result.success?).to eq(true)
|
853
|
+
expect(result.subscription.price.to_f).to eq(@subscription.price.to_f + 1)
|
854
|
+
expect(result.subscription.transactions.size).to eq(@subscription.transactions.size)
|
861
855
|
end
|
862
856
|
|
863
857
|
it "doesn't prorate if price decreases" do
|
864
858
|
result = Braintree::Subscription.update(@subscription.id,
|
865
|
-
:price => @subscription.price.to_f - 1
|
859
|
+
:price => @subscription.price.to_f - 1,
|
866
860
|
)
|
867
861
|
|
868
|
-
result.success
|
869
|
-
result.subscription.price.to_f.
|
870
|
-
result.subscription.transactions.size.
|
862
|
+
expect(result.success?).to eq(true)
|
863
|
+
expect(result.subscription.price.to_f).to eq(@subscription.price.to_f - 1)
|
864
|
+
expect(result.subscription.transactions.size).to eq(@subscription.transactions.size)
|
871
865
|
end
|
872
866
|
|
873
867
|
it "updates the subscription if the proration fails and revert_subscription_on_proration_failure => false" do
|
@@ -875,16 +869,16 @@ describe Braintree::Subscription do
|
|
875
869
|
:price => @subscription.price.to_f + 2100,
|
876
870
|
:options => {
|
877
871
|
:revert_subscription_on_proration_failure => false
|
878
|
-
}
|
872
|
+
},
|
879
873
|
)
|
880
874
|
|
881
|
-
result.success
|
882
|
-
result.subscription.price.to_f.
|
875
|
+
expect(result.success?).to eq(true)
|
876
|
+
expect(result.subscription.price.to_f).to eq(@subscription.price.to_f + 2100)
|
883
877
|
|
884
|
-
result.subscription.transactions.size.
|
878
|
+
expect(result.subscription.transactions.size).to eq(@subscription.transactions.size + 1)
|
885
879
|
transaction = result.subscription.transactions.first
|
886
|
-
transaction.status.
|
887
|
-
result.subscription.balance.
|
880
|
+
expect(transaction.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
881
|
+
expect(result.subscription.balance).to eq(transaction.amount)
|
888
882
|
end
|
889
883
|
|
890
884
|
it "does not update the subscription if the proration fails and revert_subscription_on_proration_failure => true" do
|
@@ -892,16 +886,16 @@ describe Braintree::Subscription do
|
|
892
886
|
:price => @subscription.price.to_f + 2100,
|
893
887
|
:options => {
|
894
888
|
:revert_subscription_on_proration_failure => true
|
895
|
-
}
|
889
|
+
},
|
896
890
|
)
|
897
891
|
|
898
|
-
result.success
|
899
|
-
result.subscription.price.to_f.
|
892
|
+
expect(result.success?).to eq(false)
|
893
|
+
expect(result.subscription.price.to_f).to eq(@subscription.price.to_f)
|
900
894
|
|
901
|
-
result.subscription.transactions.size.
|
895
|
+
expect(result.subscription.transactions.size).to eq(@subscription.transactions.size + 1)
|
902
896
|
transaction = result.subscription.transactions.first
|
903
|
-
transaction.status.
|
904
|
-
result.subscription.balance.
|
897
|
+
expect(transaction.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
898
|
+
expect(result.subscription.balance).to eq(0)
|
905
899
|
end
|
906
900
|
end
|
907
901
|
end
|
@@ -910,66 +904,66 @@ describe Braintree::Subscription do
|
|
910
904
|
before(:each) do
|
911
905
|
@subscription = Braintree::Subscription.create(
|
912
906
|
:payment_method_token => @credit_card.token,
|
913
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
907
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
914
908
|
).subscription
|
915
909
|
end
|
916
910
|
|
917
911
|
it "raises NotFoundError if the subscription can't be found" do
|
918
912
|
expect {
|
919
913
|
Braintree::Subscription.update(rand(36**9).to_s(36),
|
920
|
-
:price => 58.20
|
914
|
+
:price => 58.20,
|
921
915
|
)
|
922
916
|
}.to raise_error(Braintree::NotFoundError)
|
923
917
|
end
|
924
918
|
|
925
919
|
it "has validation errors on id" do
|
926
920
|
result = Braintree::Subscription.update(@subscription.id, :id => "invalid token")
|
927
|
-
result.success
|
928
|
-
result.errors.for(:subscription).on(:id)[0].code.
|
921
|
+
expect(result.success?).to eq(false)
|
922
|
+
expect(result.errors.for(:subscription).on(:id)[0].code).to eq(Braintree::ErrorCodes::Subscription::TokenFormatIsInvalid)
|
929
923
|
end
|
930
924
|
|
931
925
|
it "has a price" do
|
932
926
|
result = Braintree::Subscription.update(@subscription.id, :price => "")
|
933
|
-
result.success
|
934
|
-
result.errors.for(:subscription).on(:price)[0].code.
|
927
|
+
expect(result.success?).to eq(false)
|
928
|
+
expect(result.errors.for(:subscription).on(:price)[0].code).to eq(Braintree::ErrorCodes::Subscription::PriceCannotBeBlank)
|
935
929
|
end
|
936
930
|
|
937
931
|
it "has a properly formatted price" do
|
938
932
|
result = Braintree::Subscription.update(@subscription.id, :price => "9.2.1 apples")
|
939
|
-
result.success
|
940
|
-
result.errors.for(:subscription).on(:price)[0].code.
|
933
|
+
expect(result.success?).to eq(false)
|
934
|
+
expect(result.errors.for(:subscription).on(:price)[0].code).to eq(Braintree::ErrorCodes::Subscription::PriceFormatIsInvalid)
|
941
935
|
end
|
942
936
|
|
943
937
|
it "has validation errors on duplicate id" do
|
944
938
|
duplicate_id = "new_id_#{rand(36**6).to_s(36)}"
|
945
|
-
|
939
|
+
Braintree::Subscription.create(
|
946
940
|
:payment_method_token => @credit_card.token,
|
947
941
|
:plan_id => SpecHelper::TrialPlan[:id],
|
948
|
-
:id => duplicate_id
|
942
|
+
:id => duplicate_id,
|
949
943
|
)
|
950
|
-
|
944
|
+
duplicate = Braintree::Subscription.update(
|
951
945
|
@subscription.id,
|
952
|
-
:id => duplicate_id
|
946
|
+
:id => duplicate_id,
|
953
947
|
)
|
954
|
-
|
955
|
-
|
948
|
+
expect(duplicate.success?).to eq(false)
|
949
|
+
expect(duplicate.errors.for(:subscription).on(:id)[0].code).to eq(Braintree::ErrorCodes::Subscription::IdIsInUse)
|
956
950
|
end
|
957
951
|
|
958
952
|
it "cannot update a canceled subscription" do
|
959
953
|
subscription = Braintree::Subscription.create(
|
960
954
|
:payment_method_token => @credit_card.token,
|
961
955
|
:price => 54.32,
|
962
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
956
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
963
957
|
).subscription
|
964
958
|
|
965
959
|
result = Braintree::Subscription.cancel(subscription.id)
|
966
|
-
result.success
|
960
|
+
expect(result.success?).to eq(true)
|
967
961
|
|
968
962
|
result = Braintree::Subscription.update(subscription.id,
|
969
|
-
:price => 123.45
|
963
|
+
:price => 123.45,
|
970
964
|
)
|
971
|
-
result.success
|
972
|
-
result.errors.for(:subscription)[0].code.
|
965
|
+
expect(result.success?).to eq(false)
|
966
|
+
expect(result.errors.for(:subscription)[0].code).to eq(Braintree::ErrorCodes::Subscription::CannotEditCanceledSubscription)
|
973
967
|
end
|
974
968
|
end
|
975
969
|
|
@@ -978,32 +972,32 @@ describe Braintree::Subscription do
|
|
978
972
|
subscription = Braintree::Subscription.create(
|
979
973
|
:payment_method_token => @credit_card.token,
|
980
974
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
981
|
-
:number_of_billing_cycles => 10
|
975
|
+
:number_of_billing_cycles => 10,
|
982
976
|
).subscription
|
983
977
|
|
984
978
|
result = Braintree::Subscription.update(
|
985
979
|
subscription.id,
|
986
|
-
:number_of_billing_cycles => 5
|
980
|
+
:number_of_billing_cycles => 5,
|
987
981
|
)
|
988
982
|
|
989
|
-
result.subscription.number_of_billing_cycles.
|
983
|
+
expect(result.subscription.number_of_billing_cycles).to eq(5)
|
990
984
|
end
|
991
985
|
|
992
986
|
it "sets the number of billing cycles to nil if :never_expires => true" do
|
993
987
|
subscription = Braintree::Subscription.create(
|
994
988
|
:payment_method_token => @credit_card.token,
|
995
989
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
996
|
-
:number_of_billing_cycles => 10
|
990
|
+
:number_of_billing_cycles => 10,
|
997
991
|
).subscription
|
998
992
|
|
999
993
|
result = Braintree::Subscription.update(
|
1000
994
|
subscription.id,
|
1001
|
-
:never_expires => true
|
995
|
+
:never_expires => true,
|
1002
996
|
)
|
1003
997
|
|
1004
|
-
result.success
|
1005
|
-
result.subscription.number_of_billing_cycles.
|
1006
|
-
result.subscription.never_expires
|
998
|
+
expect(result.success?).to eq(true)
|
999
|
+
expect(result.subscription.number_of_billing_cycles).to eq(nil)
|
1000
|
+
expect(result.subscription.never_expires?).to be(true)
|
1007
1001
|
end
|
1008
1002
|
end
|
1009
1003
|
|
@@ -1011,9 +1005,9 @@ describe Braintree::Subscription do
|
|
1011
1005
|
it "can update add_ons and discounts" do
|
1012
1006
|
result = Braintree::Subscription.create(
|
1013
1007
|
:payment_method_token => @credit_card.token,
|
1014
|
-
:plan_id => SpecHelper::AddOnDiscountPlan[:id]
|
1008
|
+
:plan_id => SpecHelper::AddOnDiscountPlan[:id],
|
1015
1009
|
)
|
1016
|
-
result.success
|
1010
|
+
expect(result.success?).to eq(true)
|
1017
1011
|
subscription = result.subscription
|
1018
1012
|
|
1019
1013
|
result = Braintree::Subscription.update(
|
@@ -1035,28 +1029,28 @@ describe Braintree::Subscription do
|
|
1035
1029
|
:quantity => 9
|
1036
1030
|
}
|
1037
1031
|
]
|
1038
|
-
}
|
1032
|
+
},
|
1039
1033
|
)
|
1040
1034
|
|
1041
1035
|
subscription = result.subscription
|
1042
1036
|
|
1043
|
-
subscription.add_ons.size.
|
1037
|
+
expect(subscription.add_ons.size).to eq(2)
|
1044
1038
|
add_ons = subscription.add_ons.sort_by { |add_on| add_on.id }
|
1045
1039
|
|
1046
|
-
add_ons.first.amount.
|
1047
|
-
add_ons.first.quantity.
|
1040
|
+
expect(add_ons.first.amount).to eq(BigDecimal("99.99"))
|
1041
|
+
expect(add_ons.first.quantity).to eq(12)
|
1048
1042
|
|
1049
|
-
subscription.discounts.size.
|
1043
|
+
expect(subscription.discounts.size).to eq(2)
|
1050
1044
|
discounts = subscription.discounts.sort_by { |discount| discount.id }
|
1051
1045
|
|
1052
|
-
discounts.last.amount.
|
1053
|
-
discounts.last.quantity.
|
1046
|
+
expect(discounts.last.amount).to eq(BigDecimal("88.88"))
|
1047
|
+
expect(discounts.last.quantity).to eq(9)
|
1054
1048
|
end
|
1055
1049
|
|
1056
1050
|
it "allows adding new add_ons and discounts" do
|
1057
1051
|
subscription = Braintree::Subscription.create(
|
1058
1052
|
:payment_method_token => @credit_card.token,
|
1059
|
-
:plan_id => SpecHelper::AddOnDiscountPlan[:id]
|
1053
|
+
:plan_id => SpecHelper::AddOnDiscountPlan[:id],
|
1060
1054
|
).subscription
|
1061
1055
|
|
1062
1056
|
result = Braintree::Subscription.update(subscription.id,
|
@@ -1065,47 +1059,47 @@ describe Braintree::Subscription do
|
|
1065
1059
|
},
|
1066
1060
|
:discounts => {
|
1067
1061
|
:add => [{:inherited_from_id => SpecHelper::Discount15}]
|
1068
|
-
}
|
1062
|
+
},
|
1069
1063
|
)
|
1070
1064
|
|
1071
|
-
result.success
|
1065
|
+
expect(result.success?).to eq(true)
|
1072
1066
|
subscription = result.subscription
|
1073
1067
|
|
1074
|
-
subscription.add_ons.size.
|
1068
|
+
expect(subscription.add_ons.size).to eq(3)
|
1075
1069
|
add_ons = subscription.add_ons.sort_by { |add_on| add_on.id }
|
1076
1070
|
|
1077
|
-
add_ons[0].id.
|
1078
|
-
add_ons[0].amount.
|
1079
|
-
add_ons[0].quantity.
|
1071
|
+
expect(add_ons[0].id).to eq("increase_10")
|
1072
|
+
expect(add_ons[0].amount).to eq(BigDecimal("10.00"))
|
1073
|
+
expect(add_ons[0].quantity).to eq(1)
|
1080
1074
|
|
1081
|
-
add_ons[1].id.
|
1082
|
-
add_ons[1].amount.
|
1083
|
-
add_ons[1].quantity.
|
1075
|
+
expect(add_ons[1].id).to eq("increase_20")
|
1076
|
+
expect(add_ons[1].amount).to eq(BigDecimal("20.00"))
|
1077
|
+
expect(add_ons[1].quantity).to eq(1)
|
1084
1078
|
|
1085
|
-
add_ons[2].id.
|
1086
|
-
add_ons[2].amount.
|
1087
|
-
add_ons[2].quantity.
|
1079
|
+
expect(add_ons[2].id).to eq("increase_30")
|
1080
|
+
expect(add_ons[2].amount).to eq(BigDecimal("30.00"))
|
1081
|
+
expect(add_ons[2].quantity).to eq(1)
|
1088
1082
|
|
1089
|
-
subscription.discounts.size.
|
1083
|
+
expect(subscription.discounts.size).to eq(3)
|
1090
1084
|
discounts = subscription.discounts.sort_by { |discount| discount.id }
|
1091
1085
|
|
1092
|
-
discounts[0].id.
|
1093
|
-
discounts[0].amount.
|
1094
|
-
discounts[0].quantity.
|
1086
|
+
expect(discounts[0].id).to eq("discount_11")
|
1087
|
+
expect(discounts[0].amount).to eq(BigDecimal("11.00"))
|
1088
|
+
expect(discounts[0].quantity).to eq(1)
|
1095
1089
|
|
1096
|
-
discounts[1].id.
|
1097
|
-
discounts[1].amount.
|
1098
|
-
discounts[1].quantity.
|
1090
|
+
expect(discounts[1].id).to eq("discount_15")
|
1091
|
+
expect(discounts[1].amount).to eq(BigDecimal("15.00"))
|
1092
|
+
expect(discounts[1].quantity).to eq(1)
|
1099
1093
|
|
1100
|
-
discounts[2].id.
|
1101
|
-
discounts[2].amount.
|
1102
|
-
discounts[2].quantity.
|
1094
|
+
expect(discounts[2].id).to eq("discount_7")
|
1095
|
+
expect(discounts[2].amount).to eq(BigDecimal("7.00"))
|
1096
|
+
expect(discounts[2].quantity).to eq(1)
|
1103
1097
|
end
|
1104
1098
|
|
1105
1099
|
it "allows replacing entire set of add_ons and discounts" do
|
1106
1100
|
subscription = Braintree::Subscription.create(
|
1107
1101
|
:payment_method_token => @credit_card.token,
|
1108
|
-
:plan_id => SpecHelper::AddOnDiscountPlan[:id]
|
1102
|
+
:plan_id => SpecHelper::AddOnDiscountPlan[:id],
|
1109
1103
|
).subscription
|
1110
1104
|
|
1111
1105
|
result = Braintree::Subscription.update(subscription.id,
|
@@ -1115,27 +1109,27 @@ describe Braintree::Subscription do
|
|
1115
1109
|
:discounts => {
|
1116
1110
|
:add => [{:inherited_from_id => SpecHelper::Discount15}]
|
1117
1111
|
},
|
1118
|
-
:options => {:replace_all_add_ons_and_discounts => true}
|
1112
|
+
:options => {:replace_all_add_ons_and_discounts => true},
|
1119
1113
|
)
|
1120
1114
|
|
1121
|
-
result.success
|
1115
|
+
expect(result.success?).to eq(true)
|
1122
1116
|
subscription = result.subscription
|
1123
1117
|
|
1124
|
-
subscription.add_ons.size.
|
1118
|
+
expect(subscription.add_ons.size).to eq(1)
|
1125
1119
|
|
1126
|
-
subscription.add_ons[0].amount.
|
1127
|
-
subscription.add_ons[0].quantity.
|
1120
|
+
expect(subscription.add_ons[0].amount).to eq(BigDecimal("30.00"))
|
1121
|
+
expect(subscription.add_ons[0].quantity).to eq(1)
|
1128
1122
|
|
1129
|
-
subscription.discounts.size.
|
1123
|
+
expect(subscription.discounts.size).to eq(1)
|
1130
1124
|
|
1131
|
-
subscription.discounts[0].amount.
|
1132
|
-
subscription.discounts[0].quantity.
|
1125
|
+
expect(subscription.discounts[0].amount).to eq(BigDecimal("15.00"))
|
1126
|
+
expect(subscription.discounts[0].quantity).to eq(1)
|
1133
1127
|
end
|
1134
1128
|
|
1135
1129
|
it "allows deleting of add_ons and discounts" do
|
1136
1130
|
subscription = Braintree::Subscription.create(
|
1137
1131
|
:payment_method_token => @credit_card.token,
|
1138
|
-
:plan_id => SpecHelper::AddOnDiscountPlan[:id]
|
1132
|
+
:plan_id => SpecHelper::AddOnDiscountPlan[:id],
|
1139
1133
|
).subscription
|
1140
1134
|
|
1141
1135
|
result = Braintree::Subscription.update(subscription.id,
|
@@ -1144,19 +1138,19 @@ describe Braintree::Subscription do
|
|
1144
1138
|
},
|
1145
1139
|
:discounts => {
|
1146
1140
|
:remove => [SpecHelper::Discount7]
|
1147
|
-
}
|
1141
|
+
},
|
1148
1142
|
)
|
1149
|
-
result.success
|
1143
|
+
expect(result.success?).to eq(true)
|
1150
1144
|
|
1151
1145
|
subscription = result.subscription
|
1152
1146
|
|
1153
|
-
subscription.add_ons.size.
|
1154
|
-
subscription.add_ons.first.amount.
|
1155
|
-
subscription.add_ons.first.quantity.
|
1147
|
+
expect(subscription.add_ons.size).to eq(1)
|
1148
|
+
expect(subscription.add_ons.first.amount).to eq(BigDecimal("20.00"))
|
1149
|
+
expect(subscription.add_ons.first.quantity).to eq(1)
|
1156
1150
|
|
1157
|
-
subscription.discounts.size.
|
1158
|
-
subscription.discounts.last.amount.
|
1159
|
-
subscription.discounts.last.quantity.
|
1151
|
+
expect(subscription.discounts.size).to eq(1)
|
1152
|
+
expect(subscription.discounts.last.amount).to eq(BigDecimal("11.00"))
|
1153
|
+
expect(subscription.discounts.last.quantity).to eq(1)
|
1160
1154
|
end
|
1161
1155
|
end
|
1162
1156
|
end
|
@@ -1166,7 +1160,7 @@ describe Braintree::Subscription do
|
|
1166
1160
|
@subscription = Braintree::Subscription.create(
|
1167
1161
|
:payment_method_token => @credit_card.token,
|
1168
1162
|
:price => 54.32,
|
1169
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1163
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1170
1164
|
).subscription
|
1171
1165
|
end
|
1172
1166
|
|
@@ -1175,18 +1169,18 @@ describe Braintree::Subscription do
|
|
1175
1169
|
subscription = Braintree::Subscription.update!(@subscription.id,
|
1176
1170
|
:id => new_id,
|
1177
1171
|
:price => 9999.88,
|
1178
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
1172
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
1179
1173
|
)
|
1180
1174
|
|
1181
|
-
subscription.id.
|
1182
|
-
subscription.plan_id.
|
1183
|
-
subscription.price.
|
1175
|
+
expect(subscription.id).to match(/#{new_id}/)
|
1176
|
+
expect(subscription.plan_id).to eq(SpecHelper::TrialPlan[:id])
|
1177
|
+
expect(subscription.price).to eq(BigDecimal("9999.88"))
|
1184
1178
|
end
|
1185
1179
|
|
1186
1180
|
it "raises a ValidationsFailed if invalid" do
|
1187
1181
|
expect do
|
1188
1182
|
Braintree::Subscription.update!(@subscription.id,
|
1189
|
-
:plan_id =>
|
1183
|
+
:plan_id => "not_a_plan_id",
|
1190
1184
|
)
|
1191
1185
|
end.to raise_error(Braintree::ValidationsFailed)
|
1192
1186
|
end
|
@@ -1198,17 +1192,17 @@ describe Braintree::Subscription do
|
|
1198
1192
|
subscription = Braintree::Subscription.create(
|
1199
1193
|
:payment_method_token => @credit_card.token,
|
1200
1194
|
:price => 54.32,
|
1201
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1195
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1202
1196
|
).subscription
|
1203
1197
|
|
1204
1198
|
result = Braintree::Subscription.cancel(subscription.id)
|
1205
|
-
result.success
|
1206
|
-
result.subscription.status.
|
1199
|
+
expect(result.success?).to eq(true)
|
1200
|
+
expect(result.subscription.status).to eq(Braintree::Subscription::Status::Canceled)
|
1207
1201
|
end
|
1208
1202
|
|
1209
1203
|
it "returns a validation error if record not found" do
|
1210
1204
|
expect {
|
1211
|
-
|
1205
|
+
Braintree::Subscription.cancel("noSuchSubscription")
|
1212
1206
|
}.to raise_error(Braintree::NotFoundError, 'subscription with id "noSuchSubscription" not found')
|
1213
1207
|
end
|
1214
1208
|
|
@@ -1216,16 +1210,16 @@ describe Braintree::Subscription do
|
|
1216
1210
|
subscription = Braintree::Subscription.create(
|
1217
1211
|
:payment_method_token => @credit_card.token,
|
1218
1212
|
:price => 54.32,
|
1219
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1213
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1220
1214
|
).subscription
|
1221
1215
|
|
1222
1216
|
result = Braintree::Subscription.cancel(subscription.id)
|
1223
|
-
result.success
|
1224
|
-
result.subscription.status.
|
1217
|
+
expect(result.success?).to eq(true)
|
1218
|
+
expect(result.subscription.status).to eq(Braintree::Subscription::Status::Canceled)
|
1225
1219
|
|
1226
1220
|
result = Braintree::Subscription.cancel(subscription.id)
|
1227
|
-
result.success
|
1228
|
-
result.errors.for(:subscription)[0].code.
|
1221
|
+
expect(result.success?).to eq(false)
|
1222
|
+
expect(result.errors.for(:subscription)[0].code).to eq("81905")
|
1229
1223
|
end
|
1230
1224
|
end
|
1231
1225
|
|
@@ -1234,11 +1228,11 @@ describe Braintree::Subscription do
|
|
1234
1228
|
subscription = Braintree::Subscription.create!(
|
1235
1229
|
:payment_method_token => @credit_card.token,
|
1236
1230
|
:price => 54.32,
|
1237
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1231
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1238
1232
|
)
|
1239
1233
|
|
1240
1234
|
updated_subscription = Braintree::Subscription.cancel!(subscription.id)
|
1241
|
-
updated_subscription.status.
|
1235
|
+
expect(updated_subscription.status).to eq(Braintree::Subscription::Status::Canceled)
|
1242
1236
|
end
|
1243
1237
|
end
|
1244
1238
|
|
@@ -1249,28 +1243,28 @@ describe Braintree::Subscription do
|
|
1249
1243
|
subscription_with_trial = Braintree::Subscription.create(
|
1250
1244
|
:payment_method_token => @credit_card.token,
|
1251
1245
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1252
|
-
:id => "subscription1_#{id}"
|
1246
|
+
:id => "subscription1_#{id}",
|
1253
1247
|
).subscription
|
1254
1248
|
|
1255
1249
|
subscription_without_trial = Braintree::Subscription.create(
|
1256
1250
|
:payment_method_token => @credit_card.token,
|
1257
1251
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
1258
|
-
:id => "subscription2_#{id}"
|
1252
|
+
:id => "subscription2_#{id}",
|
1259
1253
|
).subscription
|
1260
1254
|
|
1261
1255
|
subscriptions_in_trial_period = Braintree::Subscription.search do |search|
|
1262
1256
|
search.in_trial_period.is true
|
1263
1257
|
end
|
1264
1258
|
|
1265
|
-
subscriptions_in_trial_period.
|
1266
|
-
subscriptions_in_trial_period.
|
1259
|
+
expect(subscriptions_in_trial_period).to include(subscription_with_trial)
|
1260
|
+
expect(subscriptions_in_trial_period).not_to include(subscription_without_trial)
|
1267
1261
|
|
1268
1262
|
subscriptions_not_in_trial_period = Braintree::Subscription.search do |search|
|
1269
1263
|
search.in_trial_period.is false
|
1270
1264
|
end
|
1271
1265
|
|
1272
|
-
subscriptions_not_in_trial_period.
|
1273
|
-
subscriptions_not_in_trial_period.
|
1266
|
+
expect(subscriptions_not_in_trial_period).not_to include(subscription_with_trial)
|
1267
|
+
expect(subscriptions_not_in_trial_period).to include(subscription_without_trial)
|
1274
1268
|
end
|
1275
1269
|
end
|
1276
1270
|
|
@@ -1281,7 +1275,7 @@ describe Braintree::Subscription do
|
|
1281
1275
|
:payment_method_token => @credit_card.token,
|
1282
1276
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1283
1277
|
:id => "subscription1_#{id}",
|
1284
|
-
:price => "11.38"
|
1278
|
+
:price => "11.38",
|
1285
1279
|
).subscription
|
1286
1280
|
|
1287
1281
|
collection = Braintree::Subscription.search do |search|
|
@@ -1291,21 +1285,21 @@ describe Braintree::Subscription do
|
|
1291
1285
|
|
1292
1286
|
# not testing for specific number since the
|
1293
1287
|
# create subscriptions accumulate over time
|
1294
|
-
collection.maximum_size.
|
1288
|
+
expect(collection.maximum_size).to be >= 1
|
1295
1289
|
|
1296
1290
|
collection = Braintree::Subscription.search do |search|
|
1297
1291
|
search.merchant_account_id.in subscription.merchant_account_id, "bogus_merchant_account_id"
|
1298
1292
|
search.price.is "11.38"
|
1299
1293
|
end
|
1300
1294
|
|
1301
|
-
collection.maximum_size.
|
1295
|
+
expect(collection.maximum_size).to be >= 1
|
1302
1296
|
|
1303
1297
|
collection = Braintree::Subscription.search do |search|
|
1304
1298
|
search.merchant_account_id.is "bogus_merchant_account_id"
|
1305
1299
|
search.price.is "11.38"
|
1306
1300
|
end
|
1307
1301
|
|
1308
|
-
collection.maximum_size.
|
1302
|
+
expect(collection.maximum_size).to eq(0)
|
1309
1303
|
end
|
1310
1304
|
end
|
1311
1305
|
|
@@ -1315,21 +1309,21 @@ describe Braintree::Subscription do
|
|
1315
1309
|
subscription1 = Braintree::Subscription.create(
|
1316
1310
|
:payment_method_token => @credit_card.token,
|
1317
1311
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1318
|
-
:id => "subscription1_#{id}"
|
1312
|
+
:id => "subscription1_#{id}",
|
1319
1313
|
).subscription
|
1320
1314
|
|
1321
1315
|
subscription2 = Braintree::Subscription.create(
|
1322
1316
|
:payment_method_token => @credit_card.token,
|
1323
1317
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1324
|
-
:id => "subscription2_#{id}"
|
1318
|
+
:id => "subscription2_#{id}",
|
1325
1319
|
).subscription
|
1326
1320
|
|
1327
1321
|
collection = Braintree::Subscription.search do |search|
|
1328
1322
|
search.id.is "subscription1_#{id}"
|
1329
1323
|
end
|
1330
1324
|
|
1331
|
-
collection.
|
1332
|
-
collection.
|
1325
|
+
expect(collection).to include(subscription1)
|
1326
|
+
expect(collection).not_to include(subscription2)
|
1333
1327
|
end
|
1334
1328
|
end
|
1335
1329
|
|
@@ -1339,14 +1333,14 @@ describe Braintree::Subscription do
|
|
1339
1333
|
:payment_method_token => @credit_card.token,
|
1340
1334
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1341
1335
|
:merchant_account_id => SpecHelper::DefaultMerchantAccountId,
|
1342
|
-
:price => "1"
|
1336
|
+
:price => "1",
|
1343
1337
|
).subscription
|
1344
1338
|
|
1345
1339
|
subscription2 = Braintree::Subscription.create(
|
1346
1340
|
:payment_method_token => @credit_card.token,
|
1347
1341
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1348
1342
|
:merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
1349
|
-
:price => "1"
|
1343
|
+
:price => "1",
|
1350
1344
|
).subscription
|
1351
1345
|
|
1352
1346
|
collection = Braintree::Subscription.search do |search|
|
@@ -1354,16 +1348,16 @@ describe Braintree::Subscription do
|
|
1354
1348
|
search.price.is "1"
|
1355
1349
|
end
|
1356
1350
|
|
1357
|
-
collection.
|
1358
|
-
collection.
|
1351
|
+
expect(collection).to include(subscription1)
|
1352
|
+
expect(collection).not_to include(subscription2)
|
1359
1353
|
|
1360
1354
|
collection = Braintree::Subscription.search do |search|
|
1361
1355
|
search.merchant_account_id.in [SpecHelper::DefaultMerchantAccountId, SpecHelper::NonDefaultMerchantAccountId]
|
1362
1356
|
search.price.is "1"
|
1363
1357
|
end
|
1364
1358
|
|
1365
|
-
collection.
|
1366
|
-
collection.
|
1359
|
+
expect(collection).to include(subscription1)
|
1360
|
+
expect(collection).to include(subscription2)
|
1367
1361
|
end
|
1368
1362
|
end
|
1369
1363
|
|
@@ -1372,13 +1366,13 @@ describe Braintree::Subscription do
|
|
1372
1366
|
trialless_subscription = Braintree::Subscription.create(
|
1373
1367
|
:payment_method_token => @credit_card.token,
|
1374
1368
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
1375
|
-
:price => "2"
|
1369
|
+
:price => "2",
|
1376
1370
|
).subscription
|
1377
1371
|
|
1378
1372
|
trial_subscription = Braintree::Subscription.create(
|
1379
1373
|
:payment_method_token => @credit_card.token,
|
1380
1374
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1381
|
-
:price => "2"
|
1375
|
+
:price => "2",
|
1382
1376
|
).subscription
|
1383
1377
|
|
1384
1378
|
collection = Braintree::Subscription.search do |search|
|
@@ -1386,8 +1380,8 @@ describe Braintree::Subscription do
|
|
1386
1380
|
search.price.is "2"
|
1387
1381
|
end
|
1388
1382
|
|
1389
|
-
collection.
|
1390
|
-
collection.
|
1383
|
+
expect(collection).to include(trialless_subscription)
|
1384
|
+
expect(collection).not_to include(trial_subscription)
|
1391
1385
|
end
|
1392
1386
|
end
|
1393
1387
|
|
@@ -1396,21 +1390,21 @@ describe Braintree::Subscription do
|
|
1396
1390
|
subscription_500 = Braintree::Subscription.create(
|
1397
1391
|
:payment_method_token => @credit_card.token,
|
1398
1392
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1399
|
-
:price => "5.00"
|
1393
|
+
:price => "5.00",
|
1400
1394
|
).subscription
|
1401
1395
|
|
1402
1396
|
subscription_501 = Braintree::Subscription.create(
|
1403
1397
|
:payment_method_token => @credit_card.token,
|
1404
1398
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1405
|
-
:price => "5.01"
|
1399
|
+
:price => "5.01",
|
1406
1400
|
).subscription
|
1407
1401
|
|
1408
1402
|
collection = Braintree::Subscription.search do |search|
|
1409
1403
|
search.price.is "5.00"
|
1410
1404
|
end
|
1411
1405
|
|
1412
|
-
collection.
|
1413
|
-
collection.
|
1406
|
+
expect(collection).to include(subscription_500)
|
1407
|
+
expect(collection).not_to include(subscription_501)
|
1414
1408
|
end
|
1415
1409
|
end
|
1416
1410
|
|
@@ -1419,13 +1413,13 @@ describe Braintree::Subscription do
|
|
1419
1413
|
active_subscription = Braintree::Subscription.create(
|
1420
1414
|
:payment_method_token => @credit_card.token,
|
1421
1415
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1422
|
-
:price => "6"
|
1416
|
+
:price => "6",
|
1423
1417
|
).subscription
|
1424
1418
|
|
1425
1419
|
past_due_subscription = Braintree::Subscription.create(
|
1426
1420
|
:payment_method_token => @credit_card.token,
|
1427
1421
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1428
|
-
:price => "6"
|
1422
|
+
:price => "6",
|
1429
1423
|
).subscription
|
1430
1424
|
|
1431
1425
|
SpecHelper.make_past_due(past_due_subscription, 5)
|
@@ -1435,28 +1429,28 @@ describe Braintree::Subscription do
|
|
1435
1429
|
search.days_past_due.is 5
|
1436
1430
|
end
|
1437
1431
|
|
1438
|
-
collection.
|
1439
|
-
collection.
|
1432
|
+
expect(collection).to include(past_due_subscription)
|
1433
|
+
expect(collection).not_to include(active_subscription)
|
1440
1434
|
collection.each do |s|
|
1441
|
-
s.status.
|
1442
|
-
s.balance.
|
1435
|
+
expect(s.status).to eq(Braintree::Subscription::Status::PastDue)
|
1436
|
+
expect(s.balance).to eq(BigDecimal("6.00"))
|
1443
1437
|
end
|
1444
1438
|
end
|
1445
1439
|
|
1446
1440
|
it "passes a smoke test" do
|
1447
1441
|
subscription = Braintree::Subscription.create(
|
1448
1442
|
:payment_method_token => @credit_card.token,
|
1449
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
1443
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
1450
1444
|
).subscription
|
1451
1445
|
|
1452
1446
|
collection = Braintree::Subscription.search do |search|
|
1453
1447
|
search.days_past_due.between 1, 20
|
1454
1448
|
end
|
1455
1449
|
|
1456
|
-
collection.
|
1450
|
+
expect(collection).not_to include(subscription)
|
1457
1451
|
collection.each do |s|
|
1458
|
-
s.days_past_due.
|
1459
|
-
s.days_past_due.
|
1452
|
+
expect(s.days_past_due).to be >= 1
|
1453
|
+
expect(s.days_past_due).to be <= 20
|
1460
1454
|
end
|
1461
1455
|
end
|
1462
1456
|
end
|
@@ -1466,28 +1460,28 @@ describe Braintree::Subscription do
|
|
1466
1460
|
subscription_5 = Braintree::Subscription.create(
|
1467
1461
|
:payment_method_token => @credit_card.token,
|
1468
1462
|
:plan_id => SpecHelper::TrialPlan[:id],
|
1469
|
-
:number_of_billing_cycles => 5
|
1463
|
+
:number_of_billing_cycles => 5,
|
1470
1464
|
).subscription
|
1471
1465
|
|
1472
1466
|
subscription_9 = Braintree::Subscription.create(
|
1473
1467
|
:payment_method_token => @credit_card.token,
|
1474
1468
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
1475
|
-
:number_of_billing_cycles => 10
|
1469
|
+
:number_of_billing_cycles => 10,
|
1476
1470
|
).subscription
|
1477
1471
|
|
1478
1472
|
subscription_15 = Braintree::Subscription.create(
|
1479
1473
|
:payment_method_token => @credit_card.token,
|
1480
1474
|
:plan_id => SpecHelper::TriallessPlan[:id],
|
1481
|
-
:number_of_billing_cycles => 15
|
1475
|
+
:number_of_billing_cycles => 15,
|
1482
1476
|
).subscription
|
1483
1477
|
|
1484
1478
|
collection = Braintree::Subscription.search do |search|
|
1485
1479
|
search.billing_cycles_remaining.between 5, 10
|
1486
1480
|
end
|
1487
1481
|
|
1488
|
-
collection.
|
1489
|
-
collection.
|
1490
|
-
collection.
|
1482
|
+
expect(collection).to include(subscription_5)
|
1483
|
+
expect(collection).to include(subscription_9)
|
1484
|
+
expect(collection).not_to include(subscription_15)
|
1491
1485
|
end
|
1492
1486
|
end
|
1493
1487
|
|
@@ -1495,20 +1489,20 @@ describe Braintree::Subscription do
|
|
1495
1489
|
it "returns matching results" do
|
1496
1490
|
matching_subscription = Braintree::Subscription.create(
|
1497
1491
|
:payment_method_token => @credit_card.token,
|
1498
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1492
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1499
1493
|
).subscription
|
1500
1494
|
|
1501
1495
|
non_matching_subscription = Braintree::Subscription.create(
|
1502
1496
|
:payment_method_token => @credit_card.token,
|
1503
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1497
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1504
1498
|
).subscription
|
1505
1499
|
|
1506
1500
|
collection = Braintree::Subscription.search do |search|
|
1507
1501
|
search.transaction_id.is matching_subscription.transactions.first.id
|
1508
1502
|
end
|
1509
1503
|
|
1510
|
-
collection.
|
1511
|
-
collection.
|
1504
|
+
expect(collection).to include(matching_subscription)
|
1505
|
+
expect(collection).not_to include(non_matching_subscription)
|
1512
1506
|
end
|
1513
1507
|
end
|
1514
1508
|
|
@@ -1516,12 +1510,12 @@ describe Braintree::Subscription do
|
|
1516
1510
|
it "returns matching results" do
|
1517
1511
|
matching_subscription = Braintree::Subscription.create(
|
1518
1512
|
:payment_method_token => @credit_card.token,
|
1519
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1513
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1520
1514
|
).subscription
|
1521
1515
|
|
1522
1516
|
non_matching_subscription = Braintree::Subscription.create(
|
1523
1517
|
:payment_method_token => @credit_card.token,
|
1524
|
-
:plan_id => SpecHelper::TrialPlan[:id]
|
1518
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
1525
1519
|
).subscription
|
1526
1520
|
|
1527
1521
|
five_days_from_now = Time.now + (5 * 24 * 60 * 60)
|
@@ -1529,8 +1523,8 @@ describe Braintree::Subscription do
|
|
1529
1523
|
search.next_billing_date >= five_days_from_now
|
1530
1524
|
end
|
1531
1525
|
|
1532
|
-
collection.
|
1533
|
-
collection.
|
1526
|
+
expect(collection).to include(matching_subscription)
|
1527
|
+
expect(collection).not_to include(non_matching_subscription)
|
1534
1528
|
end
|
1535
1529
|
end
|
1536
1530
|
|
@@ -1538,24 +1532,24 @@ describe Braintree::Subscription do
|
|
1538
1532
|
before(:each) do
|
1539
1533
|
@subscription = Braintree::Subscription.create(
|
1540
1534
|
:payment_method_token => @credit_card.token,
|
1541
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1535
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1542
1536
|
).subscription
|
1543
1537
|
@created_at = @subscription.created_at
|
1544
1538
|
end
|
1545
1539
|
|
1546
1540
|
it "searches on created_at in UTC using between" do
|
1547
|
-
@created_at.
|
1541
|
+
expect(@created_at).to be_utc
|
1548
1542
|
|
1549
1543
|
collection = Braintree::Subscription.search do |search|
|
1550
1544
|
search.id.is @subscription.id
|
1551
1545
|
search.created_at.between(
|
1552
1546
|
@created_at - 60,
|
1553
|
-
@created_at + 60
|
1547
|
+
@created_at + 60,
|
1554
1548
|
)
|
1555
1549
|
end
|
1556
1550
|
|
1557
|
-
collection.maximum_size.
|
1558
|
-
collection.first.id.
|
1551
|
+
expect(collection.maximum_size).to eq(1)
|
1552
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1559
1553
|
end
|
1560
1554
|
|
1561
1555
|
it "searches on created_at in UTC using geq" do
|
@@ -1564,8 +1558,8 @@ describe Braintree::Subscription do
|
|
1564
1558
|
search.created_at >= @created_at - 1
|
1565
1559
|
end
|
1566
1560
|
|
1567
|
-
collection.maximum_size.
|
1568
|
-
collection.first.id.
|
1561
|
+
expect(collection.maximum_size).to eq(1)
|
1562
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1569
1563
|
end
|
1570
1564
|
|
1571
1565
|
it "searches on created_at in UTC using leq" do
|
@@ -1574,8 +1568,8 @@ describe Braintree::Subscription do
|
|
1574
1568
|
search.created_at <= @created_at + 1
|
1575
1569
|
end
|
1576
1570
|
|
1577
|
-
collection.maximum_size.
|
1578
|
-
collection.first.id.
|
1571
|
+
expect(collection.maximum_size).to eq(1)
|
1572
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1579
1573
|
end
|
1580
1574
|
|
1581
1575
|
it "searches on created_at in UTC and finds nothing" do
|
@@ -1583,11 +1577,11 @@ describe Braintree::Subscription do
|
|
1583
1577
|
search.id.is @subscription.id
|
1584
1578
|
search.created_at.between(
|
1585
1579
|
@created_at + 300,
|
1586
|
-
@created_at + 400
|
1580
|
+
@created_at + 400,
|
1587
1581
|
)
|
1588
1582
|
end
|
1589
1583
|
|
1590
|
-
collection.maximum_size.
|
1584
|
+
expect(collection.maximum_size).to eq(0)
|
1591
1585
|
end
|
1592
1586
|
|
1593
1587
|
it "searches on created_at in UTC using exact time" do
|
@@ -1596,8 +1590,8 @@ describe Braintree::Subscription do
|
|
1596
1590
|
search.created_at.is @created_at
|
1597
1591
|
end
|
1598
1592
|
|
1599
|
-
collection.maximum_size.
|
1600
|
-
collection.first.id.
|
1593
|
+
expect(collection.maximum_size).to eq(1)
|
1594
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1601
1595
|
end
|
1602
1596
|
|
1603
1597
|
it "searches on created_at in local time using between" do
|
@@ -1607,12 +1601,12 @@ describe Braintree::Subscription do
|
|
1607
1601
|
search.id.is @subscription.id
|
1608
1602
|
search.created_at.between(
|
1609
1603
|
now - 60,
|
1610
|
-
now + 60
|
1604
|
+
now + 60,
|
1611
1605
|
)
|
1612
1606
|
end
|
1613
1607
|
|
1614
|
-
collection.maximum_size.
|
1615
|
-
collection.first.id.
|
1608
|
+
expect(collection.maximum_size).to eq(1)
|
1609
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1616
1610
|
end
|
1617
1611
|
|
1618
1612
|
it "searches on created_at in local time using geq" do
|
@@ -1623,8 +1617,8 @@ describe Braintree::Subscription do
|
|
1623
1617
|
search.created_at >= now - 60
|
1624
1618
|
end
|
1625
1619
|
|
1626
|
-
collection.maximum_size.
|
1627
|
-
collection.first.id.
|
1620
|
+
expect(collection.maximum_size).to eq(1)
|
1621
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1628
1622
|
end
|
1629
1623
|
|
1630
1624
|
it "searches on created_at in local time using leq" do
|
@@ -1635,8 +1629,8 @@ describe Braintree::Subscription do
|
|
1635
1629
|
search.created_at <= now + 60
|
1636
1630
|
end
|
1637
1631
|
|
1638
|
-
collection.maximum_size.
|
1639
|
-
collection.first.id.
|
1632
|
+
expect(collection.maximum_size).to eq(1)
|
1633
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1640
1634
|
end
|
1641
1635
|
|
1642
1636
|
it "searches on created_at in local time and finds nothing" do
|
@@ -1646,11 +1640,11 @@ describe Braintree::Subscription do
|
|
1646
1640
|
search.id.is @subscription.id
|
1647
1641
|
search.created_at.between(
|
1648
1642
|
now + 300,
|
1649
|
-
now + 400
|
1643
|
+
now + 400,
|
1650
1644
|
)
|
1651
1645
|
end
|
1652
1646
|
|
1653
|
-
collection.maximum_size.
|
1647
|
+
expect(collection.maximum_size).to eq(0)
|
1654
1648
|
end
|
1655
1649
|
|
1656
1650
|
it "searches on created_at with dates" do
|
@@ -1658,12 +1652,12 @@ describe Braintree::Subscription do
|
|
1658
1652
|
search.id.is @subscription.id
|
1659
1653
|
search.created_at.between(
|
1660
1654
|
Date.today - 1,
|
1661
|
-
Date.today + 1
|
1655
|
+
Date.today + 1,
|
1662
1656
|
)
|
1663
1657
|
end
|
1664
1658
|
|
1665
|
-
collection.maximum_size.
|
1666
|
-
collection.first.id.
|
1659
|
+
expect(collection.maximum_size).to eq(1)
|
1660
|
+
expect(collection.first.id).to eq(@subscription.id)
|
1667
1661
|
end
|
1668
1662
|
end
|
1669
1663
|
|
@@ -1673,10 +1667,10 @@ describe Braintree::Subscription do
|
|
1673
1667
|
end
|
1674
1668
|
|
1675
1669
|
collection = Braintree::Subscription.search
|
1676
|
-
collection.maximum_size.
|
1670
|
+
expect(collection.maximum_size).to be > 100
|
1677
1671
|
|
1678
|
-
subscriptions_ids = collection.map {|t| t.id }.uniq.compact
|
1679
|
-
subscriptions_ids.size.
|
1672
|
+
subscriptions_ids = collection.map { |t| t.id }.uniq.compact
|
1673
|
+
expect(subscriptions_ids.size).to eq(collection.maximum_size)
|
1680
1674
|
end
|
1681
1675
|
end
|
1682
1676
|
|
@@ -1684,73 +1678,73 @@ describe Braintree::Subscription do
|
|
1684
1678
|
it "is successful with only subscription id" do
|
1685
1679
|
subscription = Braintree::Subscription.create(
|
1686
1680
|
:payment_method_token => @credit_card.token,
|
1687
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1681
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1688
1682
|
).subscription
|
1689
1683
|
SpecHelper.make_past_due(subscription)
|
1690
1684
|
|
1691
1685
|
result = Braintree::Subscription.retry_charge(subscription.id)
|
1692
1686
|
|
1693
|
-
result.success
|
1687
|
+
expect(result.success?).to eq(true)
|
1694
1688
|
transaction = result.transaction
|
1695
1689
|
|
1696
|
-
transaction.amount.
|
1697
|
-
transaction.processor_authorization_code.
|
1698
|
-
transaction.type.
|
1699
|
-
transaction.status.
|
1690
|
+
expect(transaction.amount).to eq(subscription.price)
|
1691
|
+
expect(transaction.processor_authorization_code).not_to be_nil
|
1692
|
+
expect(transaction.type).to eq(Braintree::Transaction::Type::Sale)
|
1693
|
+
expect(transaction.status).to eq(Braintree::Transaction::Status::Authorized)
|
1700
1694
|
end
|
1701
1695
|
|
1702
1696
|
it "is successful with subscription id and amount" do
|
1703
1697
|
subscription = Braintree::Subscription.create(
|
1704
1698
|
:payment_method_token => @credit_card.token,
|
1705
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1699
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1706
1700
|
).subscription
|
1707
1701
|
SpecHelper.make_past_due(subscription)
|
1708
1702
|
|
1709
1703
|
result = Braintree::Subscription.retry_charge(subscription.id, Braintree::Test::TransactionAmounts::Authorize)
|
1710
1704
|
|
1711
|
-
result.success
|
1705
|
+
expect(result.success?).to eq(true)
|
1712
1706
|
transaction = result.transaction
|
1713
1707
|
|
1714
|
-
transaction.amount.
|
1715
|
-
transaction.processor_authorization_code.
|
1716
|
-
transaction.type.
|
1717
|
-
transaction.status.
|
1708
|
+
expect(transaction.amount).to eq(BigDecimal(Braintree::Test::TransactionAmounts::Authorize))
|
1709
|
+
expect(transaction.processor_authorization_code).not_to be_nil
|
1710
|
+
expect(transaction.type).to eq(Braintree::Transaction::Type::Sale)
|
1711
|
+
expect(transaction.status).to eq(Braintree::Transaction::Status::Authorized)
|
1718
1712
|
end
|
1719
1713
|
|
1720
1714
|
it "is successful with subscription id and submit_for_settlement" do
|
1721
1715
|
subscription = Braintree::Subscription.create(
|
1722
1716
|
:payment_method_token => @credit_card.token,
|
1723
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1717
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1724
1718
|
).subscription
|
1725
1719
|
SpecHelper.make_past_due(subscription)
|
1726
1720
|
|
1727
1721
|
result = Braintree::Subscription.retry_charge(subscription.id, Braintree::Test::TransactionAmounts::Authorize, true)
|
1728
1722
|
|
1729
|
-
result.success
|
1723
|
+
expect(result.success?).to eq(true)
|
1730
1724
|
transaction = result.transaction
|
1731
1725
|
|
1732
|
-
transaction.amount.
|
1733
|
-
transaction.processor_authorization_code.
|
1734
|
-
transaction.type.
|
1735
|
-
transaction.status.
|
1726
|
+
expect(transaction.amount).to eq(BigDecimal(Braintree::Test::TransactionAmounts::Authorize))
|
1727
|
+
expect(transaction.processor_authorization_code).not_to be_nil
|
1728
|
+
expect(transaction.type).to eq(Braintree::Transaction::Type::Sale)
|
1729
|
+
expect(transaction.status).to eq(Braintree::Transaction::Status::SubmittedForSettlement)
|
1736
1730
|
end
|
1737
1731
|
|
1738
1732
|
it "is successful with subscription id, amount and submit_for_settlement" do
|
1739
1733
|
subscription = Braintree::Subscription.create(
|
1740
1734
|
:payment_method_token => @credit_card.token,
|
1741
|
-
:plan_id => SpecHelper::TriallessPlan[:id]
|
1735
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1742
1736
|
).subscription
|
1743
1737
|
SpecHelper.make_past_due(subscription)
|
1744
1738
|
|
1745
1739
|
result = Braintree::Subscription.retry_charge(subscription.id, Braintree::Test::TransactionAmounts::Authorize, true)
|
1746
1740
|
|
1747
|
-
result.success
|
1741
|
+
expect(result.success?).to eq(true)
|
1748
1742
|
transaction = result.transaction
|
1749
1743
|
|
1750
|
-
transaction.amount.
|
1751
|
-
transaction.processor_authorization_code.
|
1752
|
-
transaction.type.
|
1753
|
-
transaction.status.
|
1744
|
+
expect(transaction.amount).to eq(BigDecimal(Braintree::Test::TransactionAmounts::Authorize))
|
1745
|
+
expect(transaction.processor_authorization_code).not_to be_nil
|
1746
|
+
expect(transaction.type).to eq(Braintree::Transaction::Type::Sale)
|
1747
|
+
expect(transaction.status).to eq(Braintree::Transaction::Status::SubmittedForSettlement)
|
1754
1748
|
end
|
1755
1749
|
end
|
1756
1750
|
end
|