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