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,14 +1,16 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
|
|
3
4
|
|
|
4
5
|
describe Braintree::Customer do
|
|
5
6
|
describe "self.all" do
|
|
6
|
-
|
|
7
|
+
#Disabling test until we have a more stable CI
|
|
8
|
+
xit "gets more than a page of customers" do
|
|
7
9
|
customers = Braintree::Customer.all
|
|
8
|
-
customers.maximum_size.
|
|
10
|
+
expect(customers.maximum_size).to be > 100
|
|
9
11
|
|
|
10
|
-
customer_ids = customers.map {|c| c.id }.uniq.compact
|
|
11
|
-
customer_ids.size.
|
|
12
|
+
customer_ids = customers.map { |c| c.id }.uniq.compact
|
|
13
|
+
expect(customer_ids.size).to eq(customers.maximum_size)
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
|
|
@@ -16,13 +18,13 @@ describe Braintree::Customer do
|
|
|
16
18
|
it "deletes the customer with the given id" do
|
|
17
19
|
create_result = Braintree::Customer.create(
|
|
18
20
|
:first_name => "Joe",
|
|
19
|
-
:last_name => "Cool"
|
|
21
|
+
:last_name => "Cool",
|
|
20
22
|
)
|
|
21
|
-
create_result.success
|
|
23
|
+
expect(create_result.success?).to eq(true)
|
|
22
24
|
customer = create_result.customer
|
|
23
25
|
|
|
24
26
|
delete_result = Braintree::Customer.delete(customer.id)
|
|
25
|
-
delete_result.success
|
|
27
|
+
expect(delete_result.success?).to eq(true)
|
|
26
28
|
expect do
|
|
27
29
|
Braintree::Customer.find(customer.id)
|
|
28
30
|
end.to raise_error(Braintree::NotFoundError)
|
|
@@ -37,62 +39,175 @@ describe Braintree::Customer do
|
|
|
37
39
|
:company => "Microsoft",
|
|
38
40
|
:email => "bill@microsoft.com",
|
|
39
41
|
:phone => "312.555.1234",
|
|
42
|
+
:international_phone => {:country_code => "1", :national_number => "3121234567"},
|
|
40
43
|
:fax => "614.555.5678",
|
|
41
|
-
:website => "www.microsoft.com"
|
|
44
|
+
:website => "www.microsoft.com",
|
|
45
|
+
:tax_identifiers => [{:country_code => "US", :identifier => "987654321"}],
|
|
42
46
|
)
|
|
43
|
-
result.success
|
|
44
|
-
result.customer.id.
|
|
45
|
-
result.customer.first_name.
|
|
46
|
-
result.customer.last_name.
|
|
47
|
-
result.customer.company.
|
|
48
|
-
result.customer.email.
|
|
49
|
-
result.customer.phone.
|
|
50
|
-
result.customer.
|
|
51
|
-
result.customer.
|
|
52
|
-
result.customer.
|
|
53
|
-
result.customer.
|
|
47
|
+
expect(result.success?).to eq(true)
|
|
48
|
+
expect(result.customer.id).to match(/^\d{6,}$/)
|
|
49
|
+
expect(result.customer.first_name).to eq("Bill")
|
|
50
|
+
expect(result.customer.last_name).to eq("Gates")
|
|
51
|
+
expect(result.customer.company).to eq("Microsoft")
|
|
52
|
+
expect(result.customer.email).to eq("bill@microsoft.com")
|
|
53
|
+
expect(result.customer.phone).to eq("312.555.1234")
|
|
54
|
+
expect(result.customer.international_phone[:country_code]).to eq("1")
|
|
55
|
+
expect(result.customer.international_phone[:national_number]).to eq("3121234567")
|
|
56
|
+
expect(result.customer.fax).to eq("614.555.5678")
|
|
57
|
+
expect(result.customer.website).to eq("www.microsoft.com")
|
|
58
|
+
expect(result.customer.created_at.between?(Time.now - 10, Time.now)).to eq(true)
|
|
59
|
+
expect(result.customer.updated_at.between?(Time.now - 10, Time.now)).to eq(true)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "returns a successful result if successful using an access token" do
|
|
63
|
+
oauth_gateway = Braintree::Gateway.new(
|
|
64
|
+
:client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
|
|
65
|
+
:client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
|
|
66
|
+
:logger => Logger.new("/dev/null"),
|
|
67
|
+
)
|
|
68
|
+
access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
|
|
69
|
+
:merchant_public_id => "integration_merchant_id",
|
|
70
|
+
:scope => "read_write"
|
|
71
|
+
}).credentials.access_token
|
|
72
|
+
|
|
73
|
+
gateway = Braintree::Gateway.new(
|
|
74
|
+
:access_token => access_token,
|
|
75
|
+
:logger => Logger.new("/dev/null"),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
result = gateway.customer.create(
|
|
79
|
+
:first_name => "Joe",
|
|
80
|
+
:last_name => "Brown",
|
|
81
|
+
:company => "ExampleCo",
|
|
82
|
+
:email => "joe@example.com",
|
|
83
|
+
:phone => "312.555.1234",
|
|
84
|
+
:fax => "614.555.5678",
|
|
85
|
+
:website => "www.example.com",
|
|
86
|
+
)
|
|
87
|
+
expect(result.success?).to eq(true)
|
|
88
|
+
expect(result.customer.id).to match(/^\d{6,}$/)
|
|
89
|
+
expect(result.customer.first_name).to eq("Joe")
|
|
90
|
+
expect(result.customer.last_name).to eq("Brown")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "supports creation with device_data" do
|
|
94
|
+
result = Braintree::Customer.create(
|
|
95
|
+
:credit_card => {
|
|
96
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
97
|
+
:expiration_date => "05/2010",
|
|
98
|
+
:cvv => "100",
|
|
99
|
+
:device_data => "device_data",
|
|
100
|
+
},
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
expect(result).to be_success
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "supports creation including risk data with customer_browser and customer_ip" do
|
|
107
|
+
result = Braintree::Customer.create(
|
|
108
|
+
:credit_card => {
|
|
109
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
110
|
+
:expiration_date => "05/2010",
|
|
111
|
+
:cvv => "100"
|
|
112
|
+
},
|
|
113
|
+
:risk_data => {
|
|
114
|
+
:customer_browser => "IE5",
|
|
115
|
+
:customer_ip => "192.168.0.1"
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
expect(result).to be_success
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "includes risk data when skip_advanced_fraud_checking is false" do
|
|
123
|
+
with_fraud_protection_enterprise_merchant do
|
|
124
|
+
result = Braintree::Customer.create(
|
|
125
|
+
:credit_card => {
|
|
126
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
127
|
+
:expiration_date => "05/2010",
|
|
128
|
+
:cvv => "100",
|
|
129
|
+
:options => {
|
|
130
|
+
:skip_advanced_fraud_checking => false,
|
|
131
|
+
:verify_card => true,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
expect(result).to be_success
|
|
137
|
+
verification = result.customer.credit_cards.first.verification
|
|
138
|
+
expect(verification.risk_data).not_to be_nil
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "does not include risk data when skip_advanced_fraud_checking is true" do
|
|
143
|
+
with_fraud_protection_enterprise_merchant do
|
|
144
|
+
result = Braintree::Customer.create(
|
|
145
|
+
:credit_card => {
|
|
146
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
147
|
+
:expiration_date => "05/2010",
|
|
148
|
+
:cvv => "100",
|
|
149
|
+
:options => {
|
|
150
|
+
:skip_advanced_fraud_checking => true,
|
|
151
|
+
:verify_card => true,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
expect(result).to be_success
|
|
157
|
+
verification = result.customer.credit_cards.first.verification
|
|
158
|
+
expect(verification.risk_data).to be_nil
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "supports creation with tax_identifiers" do
|
|
163
|
+
result = Braintree::Customer.create(
|
|
164
|
+
:tax_identifiers => [
|
|
165
|
+
{:country_code => "US", :identifier => "987654321"},
|
|
166
|
+
{:country_code => "CL", :identifier => "123456789"}
|
|
167
|
+
],
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
expect(result).to be_success
|
|
54
171
|
end
|
|
55
172
|
|
|
56
173
|
it "can create without any attributes" do
|
|
57
174
|
result = Braintree::Customer.create
|
|
58
|
-
result.success
|
|
175
|
+
expect(result.success?).to eq(true)
|
|
59
176
|
end
|
|
60
177
|
|
|
61
178
|
it "supports utf-8" do
|
|
62
179
|
first_name = "Jos\303\251"
|
|
63
180
|
last_name = "Mu\303\261oz"
|
|
64
181
|
result = Braintree::Customer.create(:first_name => first_name, :last_name => last_name)
|
|
65
|
-
result.success
|
|
182
|
+
expect(result.success?).to eq(true)
|
|
66
183
|
|
|
67
184
|
if RUBY_VERSION =~ /^1.8/
|
|
68
|
-
result.customer.first_name.
|
|
69
|
-
result.customer.last_name.
|
|
185
|
+
expect(result.customer.first_name).to eq(first_name)
|
|
186
|
+
expect(result.customer.last_name).to eq(last_name)
|
|
70
187
|
|
|
71
188
|
found_customer = Braintree::Customer.find(result.customer.id)
|
|
72
|
-
found_customer.first_name.
|
|
73
|
-
found_customer.last_name.
|
|
74
|
-
|
|
75
|
-
result.customer.first_name.
|
|
76
|
-
result.customer.first_name.bytes.map {|b| b.to_s(8)}.
|
|
77
|
-
result.customer.last_name.
|
|
78
|
-
result.customer.last_name.bytes.map {|b| b.to_s(8)}.
|
|
189
|
+
expect(found_customer.first_name).to eq(first_name)
|
|
190
|
+
expect(found_customer.last_name).to eq(last_name)
|
|
191
|
+
else
|
|
192
|
+
expect(result.customer.first_name).to eq("José")
|
|
193
|
+
expect(result.customer.first_name.bytes.map { |b| b.to_s(8) }).to eq(["112", "157", "163", "303", "251"])
|
|
194
|
+
expect(result.customer.last_name).to eq("Muñoz")
|
|
195
|
+
expect(result.customer.last_name.bytes.map { |b| b.to_s(8) }).to eq(["115", "165", "303", "261", "157", "172"])
|
|
79
196
|
|
|
80
197
|
found_customer = Braintree::Customer.find(result.customer.id)
|
|
81
|
-
found_customer.first_name.
|
|
82
|
-
found_customer.first_name.bytes.map {|b| b.to_s(8)}.
|
|
83
|
-
found_customer.last_name.
|
|
84
|
-
found_customer.last_name.bytes.map {|b| b.to_s(8)}.
|
|
85
|
-
else
|
|
86
|
-
raise "unknown ruby version: #{RUBY_VERSION.inspect}"
|
|
198
|
+
expect(found_customer.first_name).to eq("José")
|
|
199
|
+
expect(found_customer.first_name.bytes.map { |b| b.to_s(8) }).to eq(["112", "157", "163", "303", "251"])
|
|
200
|
+
expect(found_customer.last_name).to eq("Muñoz")
|
|
201
|
+
expect(found_customer.last_name.bytes.map { |b| b.to_s(8) }).to eq(["115", "165", "303", "261", "157", "172"])
|
|
87
202
|
end
|
|
88
203
|
end
|
|
89
204
|
|
|
90
205
|
it "returns an error response if invalid" do
|
|
91
206
|
result = Braintree::Customer.create(
|
|
92
|
-
:email => "@invalid.com"
|
|
207
|
+
:email => "@invalid.com",
|
|
93
208
|
)
|
|
94
|
-
result.success
|
|
95
|
-
result.errors.for(:customer).on(:email)[0].message.
|
|
209
|
+
expect(result.success?).to eq(false)
|
|
210
|
+
expect(result.errors.for(:customer).on(:email)[0].message).to eq("Email is an invalid format.")
|
|
96
211
|
end
|
|
97
212
|
|
|
98
213
|
it "can create a customer and a payment method at the same time" do
|
|
@@ -103,14 +218,34 @@ describe Braintree::Customer do
|
|
|
103
218
|
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
104
219
|
:expiration_date => "05/2010",
|
|
105
220
|
:cvv => "100"
|
|
106
|
-
}
|
|
221
|
+
},
|
|
107
222
|
)
|
|
108
|
-
|
|
109
|
-
result.
|
|
110
|
-
result.customer.
|
|
111
|
-
result.customer.
|
|
112
|
-
result.customer.credit_cards[0].
|
|
113
|
-
result.customer.credit_cards[0].
|
|
223
|
+
|
|
224
|
+
expect(result.success?).to eq(true)
|
|
225
|
+
expect(result.customer.first_name).to eq("Mike")
|
|
226
|
+
expect(result.customer.last_name).to eq("Jones")
|
|
227
|
+
expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
|
|
228
|
+
expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
|
|
229
|
+
expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
|
|
230
|
+
expect(result.customer.credit_cards[0].unique_number_identifier).to match(/\A\w{32}\z/)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it "can create a customer and a paypal account at the same time" do
|
|
234
|
+
result = Braintree::Customer.create(
|
|
235
|
+
:first_name => "Mike",
|
|
236
|
+
:last_name => "Jones",
|
|
237
|
+
:paypal_account => {
|
|
238
|
+
:email => "other@example.com",
|
|
239
|
+
:billing_agreement_id => "B-123456",
|
|
240
|
+
:options => {:make_default => true}
|
|
241
|
+
},
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
expect(result.success?).to eq(true)
|
|
245
|
+
expect(result.customer.first_name).to eq("Mike")
|
|
246
|
+
expect(result.customer.last_name).to eq("Jones")
|
|
247
|
+
expect(result.customer.paypal_accounts[0].billing_agreement_id).to eq("B-123456")
|
|
248
|
+
expect(result.customer.paypal_accounts[0].email).to eq("other@example.com")
|
|
114
249
|
end
|
|
115
250
|
|
|
116
251
|
it "verifies the card if credit_card[options][verify_card]=true" do
|
|
@@ -121,10 +256,44 @@ describe Braintree::Customer do
|
|
|
121
256
|
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
|
|
122
257
|
:expiration_date => "05/2010",
|
|
123
258
|
:options => {:verify_card => true}
|
|
124
|
-
}
|
|
259
|
+
},
|
|
260
|
+
)
|
|
261
|
+
expect(result.success?).to eq(false)
|
|
262
|
+
expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it "allows a verification_amount" do
|
|
266
|
+
result = Braintree::Customer.create(
|
|
267
|
+
:first_name => "Mike",
|
|
268
|
+
:last_name => "Jones",
|
|
269
|
+
:credit_card => {
|
|
270
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
271
|
+
:expiration_date => "05/2019",
|
|
272
|
+
:options => {:verify_card => true, :verification_amount => "2.00"}
|
|
273
|
+
},
|
|
125
274
|
)
|
|
126
|
-
result.success
|
|
127
|
-
|
|
275
|
+
expect(result.success?).to eq(true)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
it "fails on create if credit_card[options][fail_on_duplicate_payment_method]=true and there is a duplicated payment method" do
|
|
279
|
+
customer = Braintree::Customer.create!
|
|
280
|
+
Braintree::CreditCard.create(
|
|
281
|
+
:customer_id => customer.id,
|
|
282
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
283
|
+
:expiration_date => "05/2015",
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
result = Braintree::Customer.create(
|
|
287
|
+
:first_name => "Mike",
|
|
288
|
+
:last_name => "Jones",
|
|
289
|
+
:credit_card => {
|
|
290
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
291
|
+
:expiration_date => "05/2015",
|
|
292
|
+
:options => {:fail_on_duplicate_payment_method => true}
|
|
293
|
+
},
|
|
294
|
+
)
|
|
295
|
+
expect(result.success?).to eq(false)
|
|
296
|
+
expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Duplicate card exists in the vault.")
|
|
128
297
|
end
|
|
129
298
|
|
|
130
299
|
it "allows the user to specify the merchant account for verification" do
|
|
@@ -138,12 +307,98 @@ describe Braintree::Customer do
|
|
|
138
307
|
:verify_card => true,
|
|
139
308
|
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
|
|
140
309
|
}
|
|
141
|
-
}
|
|
310
|
+
},
|
|
311
|
+
)
|
|
312
|
+
expect(result.success?).to eq(false)
|
|
313
|
+
expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
it "can create a customer and a payment method at the same time after validating verification_currency_iso_code" do
|
|
317
|
+
result = Braintree::Customer.create(
|
|
318
|
+
:first_name => "Mike",
|
|
319
|
+
:last_name => "Jones",
|
|
320
|
+
:credit_card => {
|
|
321
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
322
|
+
:expiration_date => "05/2010",
|
|
323
|
+
:cvv => "100",
|
|
324
|
+
:options => {
|
|
325
|
+
:verify_card => true,
|
|
326
|
+
:verification_currency_iso_code => "USD"
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
expect(result.success?).to eq(true)
|
|
332
|
+
expect(result.customer.first_name).to eq("Mike")
|
|
333
|
+
expect(result.customer.last_name).to eq("Jones")
|
|
334
|
+
expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
|
|
335
|
+
expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
|
|
336
|
+
expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
|
|
337
|
+
expect(result.customer.credit_cards[0].unique_number_identifier).to match(/\A\w{32}\z/)
|
|
338
|
+
result.customer.credit_cards[0].verification.currency_iso_code == "USD"
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
it "errors when verification_currency_iso_code is not supported by merchant account" do
|
|
342
|
+
result = Braintree::Customer.create(
|
|
343
|
+
:first_name => "Mike",
|
|
344
|
+
:last_name => "Jones",
|
|
345
|
+
:credit_card => {
|
|
346
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
347
|
+
:expiration_date => "05/2010",
|
|
348
|
+
:cvv => "100",
|
|
349
|
+
:options => {
|
|
350
|
+
:verify_card => true,
|
|
351
|
+
:verification_currency_iso_code => "GBP"
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
)
|
|
355
|
+
expect(result).to_not be_success
|
|
356
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
it "validates verification_currency_iso_code of the given verification_merchant_account_id and creates customer" do
|
|
360
|
+
result = Braintree::Customer.create(
|
|
361
|
+
:first_name => "Mike",
|
|
362
|
+
:last_name => "Jones",
|
|
363
|
+
:credit_card => {
|
|
364
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
365
|
+
:expiration_date => "05/2010",
|
|
366
|
+
:options => {
|
|
367
|
+
:verify_card => true,
|
|
368
|
+
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
|
369
|
+
:verification_currency_iso_code => "USD"
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
)
|
|
373
|
+
expect(result.success?).to eq(true)
|
|
374
|
+
result.customer.credit_cards[0].verification.currency_iso_code == "USD"
|
|
375
|
+
expect(result.customer.first_name).to eq("Mike")
|
|
376
|
+
expect(result.customer.last_name).to eq("Jones")
|
|
377
|
+
expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
|
|
378
|
+
expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
|
|
379
|
+
expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
|
|
380
|
+
expect(result.customer.credit_cards[0].unique_number_identifier).to match(/\A\w{32}\z/)
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
it "validates verification_currency_iso_code of the given verification_merchant_account_id and returns error" do
|
|
384
|
+
result = Braintree::Customer.create(
|
|
385
|
+
:first_name => "Mike",
|
|
386
|
+
:last_name => "Jones",
|
|
387
|
+
:credit_card => {
|
|
388
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
389
|
+
:expiration_date => "05/2010",
|
|
390
|
+
:options => {
|
|
391
|
+
:verify_card => true,
|
|
392
|
+
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
|
393
|
+
:verification_currency_iso_code => "GBP"
|
|
394
|
+
}
|
|
395
|
+
},
|
|
142
396
|
)
|
|
143
|
-
result.
|
|
144
|
-
result.
|
|
397
|
+
expect(result).to_not be_success
|
|
398
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
|
145
399
|
end
|
|
146
400
|
|
|
401
|
+
|
|
147
402
|
it "can create a customer, payment method, and billing address at the same time" do
|
|
148
403
|
result = Braintree::Customer.create(
|
|
149
404
|
:first_name => "Mike",
|
|
@@ -159,22 +414,22 @@ describe Braintree::Customer do
|
|
|
159
414
|
:postal_code => "60622",
|
|
160
415
|
:country_name => "United States of America"
|
|
161
416
|
}
|
|
162
|
-
}
|
|
163
|
-
)
|
|
164
|
-
result.success
|
|
165
|
-
result.customer.first_name.
|
|
166
|
-
result.customer.last_name.
|
|
167
|
-
result.customer.credit_cards[0].bin.
|
|
168
|
-
result.customer.credit_cards[0].last_4.
|
|
169
|
-
result.customer.credit_cards[0].expiration_date.
|
|
170
|
-
result.customer.credit_cards[0].billing_address.id.
|
|
171
|
-
result.customer.addresses[0].id.
|
|
172
|
-
result.customer.addresses[0].street_address.
|
|
173
|
-
result.customer.addresses[0].extended_address.
|
|
174
|
-
result.customer.addresses[0].locality.
|
|
175
|
-
result.customer.addresses[0].region.
|
|
176
|
-
result.customer.addresses[0].postal_code.
|
|
177
|
-
result.customer.addresses[0].country_name.
|
|
417
|
+
},
|
|
418
|
+
)
|
|
419
|
+
expect(result.success?).to eq(true)
|
|
420
|
+
expect(result.customer.first_name).to eq("Mike")
|
|
421
|
+
expect(result.customer.last_name).to eq("Jones")
|
|
422
|
+
expect(result.customer.credit_cards[0].bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
|
|
423
|
+
expect(result.customer.credit_cards[0].last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
|
|
424
|
+
expect(result.customer.credit_cards[0].expiration_date).to eq("05/2010")
|
|
425
|
+
expect(result.customer.credit_cards[0].billing_address.id).to eq(result.customer.addresses[0].id)
|
|
426
|
+
expect(result.customer.addresses[0].id).to match(/\w+/)
|
|
427
|
+
expect(result.customer.addresses[0].street_address).to eq("1 E Main St")
|
|
428
|
+
expect(result.customer.addresses[0].extended_address).to eq("Suite 3")
|
|
429
|
+
expect(result.customer.addresses[0].locality).to eq("Chicago")
|
|
430
|
+
expect(result.customer.addresses[0].region).to eq("Illinois")
|
|
431
|
+
expect(result.customer.addresses[0].postal_code).to eq("60622")
|
|
432
|
+
expect(result.customer.addresses[0].country_name).to eq("United States of America")
|
|
178
433
|
end
|
|
179
434
|
|
|
180
435
|
it "can use any country code" do
|
|
@@ -190,13 +445,13 @@ describe Braintree::Customer do
|
|
|
190
445
|
:country_code_alpha3 => "COM",
|
|
191
446
|
:country_code_numeric => "174"
|
|
192
447
|
}
|
|
193
|
-
}
|
|
448
|
+
},
|
|
194
449
|
)
|
|
195
|
-
result.success
|
|
196
|
-
result.customer.addresses[0].country_name.
|
|
197
|
-
result.customer.addresses[0].country_code_alpha2.
|
|
198
|
-
result.customer.addresses[0].country_code_alpha3.
|
|
199
|
-
result.customer.addresses[0].country_code_numeric.
|
|
450
|
+
expect(result.success?).to eq(true)
|
|
451
|
+
expect(result.customer.addresses[0].country_name).to eq("Comoros")
|
|
452
|
+
expect(result.customer.addresses[0].country_code_alpha2).to eq("KM")
|
|
453
|
+
expect(result.customer.addresses[0].country_code_alpha3).to eq("COM")
|
|
454
|
+
expect(result.customer.addresses[0].country_code_numeric).to eq("174")
|
|
200
455
|
end
|
|
201
456
|
|
|
202
457
|
it "stores custom fields when valid" do
|
|
@@ -205,10 +460,20 @@ describe Braintree::Customer do
|
|
|
205
460
|
:last_name => "Gates",
|
|
206
461
|
:custom_fields => {
|
|
207
462
|
:store_me => "custom value"
|
|
208
|
-
}
|
|
463
|
+
},
|
|
209
464
|
)
|
|
210
|
-
result.success
|
|
211
|
-
result.customer.custom_fields[:store_me].
|
|
465
|
+
expect(result.success?).to eq(true)
|
|
466
|
+
expect(result.customer.custom_fields[:store_me]).to eq("custom value")
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
it "returns empty hash for custom fields when blank" do
|
|
470
|
+
result = Braintree::Customer.create(
|
|
471
|
+
:first_name => "Bill",
|
|
472
|
+
:last_name => "Gates",
|
|
473
|
+
:custom_fields => {:store_me => ""},
|
|
474
|
+
)
|
|
475
|
+
expect(result.success?).to eq(true)
|
|
476
|
+
expect(result.customer.custom_fields).to eq({})
|
|
212
477
|
end
|
|
213
478
|
|
|
214
479
|
it "returns nested errors if credit card and/or billing address are invalid" do
|
|
@@ -219,12 +484,12 @@ describe Braintree::Customer do
|
|
|
219
484
|
:billing_address => {
|
|
220
485
|
:country_name => "invalid"
|
|
221
486
|
}
|
|
222
|
-
}
|
|
487
|
+
},
|
|
223
488
|
)
|
|
224
|
-
result.success
|
|
225
|
-
result.errors.for(:customer).on(:email)[0].message.
|
|
226
|
-
result.errors.for(:customer).for(:credit_card).on(:number)[0].message.
|
|
227
|
-
result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_name)[0].message.
|
|
489
|
+
expect(result.success?).to eq(false)
|
|
490
|
+
expect(result.errors.for(:customer).on(:email)[0].message).to eq("Email is an invalid format.")
|
|
491
|
+
expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Credit card number is invalid.")
|
|
492
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_name)[0].message).to eq("Country name is not an accepted country.")
|
|
228
493
|
end
|
|
229
494
|
|
|
230
495
|
it "returns errors if country codes are inconsistent" do
|
|
@@ -239,10 +504,10 @@ describe Braintree::Customer do
|
|
|
239
504
|
:country_code_alpha2 => "US",
|
|
240
505
|
:country_code_alpha3 => "COM",
|
|
241
506
|
}
|
|
242
|
-
}
|
|
507
|
+
},
|
|
243
508
|
)
|
|
244
|
-
result.success
|
|
245
|
-
result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map {|e| e.code}.
|
|
509
|
+
expect(result.success?).to eq(false)
|
|
510
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:base).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::InconsistentCountry)
|
|
246
511
|
end
|
|
247
512
|
|
|
248
513
|
it "returns an error if country code alpha2 is invalid" do
|
|
@@ -255,10 +520,10 @@ describe Braintree::Customer do
|
|
|
255
520
|
:billing_address => {
|
|
256
521
|
:country_code_alpha2 => "zz",
|
|
257
522
|
}
|
|
258
|
-
}
|
|
523
|
+
},
|
|
259
524
|
)
|
|
260
|
-
result.success
|
|
261
|
-
result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha2).map {|e| e.code}.
|
|
525
|
+
expect(result.success?).to eq(false)
|
|
526
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha2).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
|
|
262
527
|
end
|
|
263
528
|
|
|
264
529
|
it "returns an error if country code alpha3 is invalid" do
|
|
@@ -271,10 +536,10 @@ describe Braintree::Customer do
|
|
|
271
536
|
:billing_address => {
|
|
272
537
|
:country_code_alpha3 => "zzz",
|
|
273
538
|
}
|
|
274
|
-
}
|
|
539
|
+
},
|
|
275
540
|
)
|
|
276
|
-
result.success
|
|
277
|
-
result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha3).map {|e| e.code}.
|
|
541
|
+
expect(result.success?).to eq(false)
|
|
542
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_alpha3).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
|
|
278
543
|
end
|
|
279
544
|
|
|
280
545
|
it "returns an error if country code numeric is invalid" do
|
|
@@ -287,10 +552,10 @@ describe Braintree::Customer do
|
|
|
287
552
|
:billing_address => {
|
|
288
553
|
:country_code_numeric => "zzz",
|
|
289
554
|
}
|
|
290
|
-
}
|
|
555
|
+
},
|
|
291
556
|
)
|
|
292
|
-
result.success
|
|
293
|
-
result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_numeric).map {|e| e.code}.
|
|
557
|
+
expect(result.success?).to eq(false)
|
|
558
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_code_numeric).map { |e| e.code }).to include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
|
|
294
559
|
end
|
|
295
560
|
|
|
296
561
|
it "returns errors if custom_fields are not registered" do
|
|
@@ -299,10 +564,138 @@ describe Braintree::Customer do
|
|
|
299
564
|
:last_name => "Kennedy",
|
|
300
565
|
:custom_fields => {
|
|
301
566
|
:spouse_name => "Jacqueline"
|
|
302
|
-
}
|
|
567
|
+
},
|
|
303
568
|
)
|
|
304
|
-
result.success
|
|
305
|
-
result.errors.for(:customer).on(:custom_fields)[0].message.
|
|
569
|
+
expect(result.success?).to eq(false)
|
|
570
|
+
expect(result.errors.for(:customer).on(:custom_fields)[0].message).to eq("Custom field is invalid: spouse_name.")
|
|
571
|
+
end
|
|
572
|
+
|
|
573
|
+
context "client API" do
|
|
574
|
+
it "can create a customer with a payment method nonce" do
|
|
575
|
+
nonce = nonce_for_new_payment_method(
|
|
576
|
+
:credit_card => {
|
|
577
|
+
:number => "4111111111111111",
|
|
578
|
+
:expiration_month => "11",
|
|
579
|
+
:expiration_year => "2099",
|
|
580
|
+
},
|
|
581
|
+
:share => true,
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
result = Braintree::Customer.create(
|
|
585
|
+
:credit_card => {
|
|
586
|
+
:payment_method_nonce => nonce
|
|
587
|
+
},
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
expect(result.success?).to eq(true)
|
|
591
|
+
expect(result.customer.credit_cards.first.bin).to eq("411111")
|
|
592
|
+
expect(result.customer.credit_cards.first.last_4).to eq("1111")
|
|
593
|
+
end
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
it "can create a customer with an apple pay payment method" do
|
|
597
|
+
result = Braintree::Customer.create(:payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa)
|
|
598
|
+
|
|
599
|
+
expect(result.success?).to eq(true)
|
|
600
|
+
expect(result.customer.payment_methods).not_to be_empty
|
|
601
|
+
expect(result.customer.payment_methods.first.token).not_to be_nil
|
|
602
|
+
end
|
|
603
|
+
|
|
604
|
+
it "can create a customer with an unknown payment method" do
|
|
605
|
+
result = Braintree::Customer.create(:payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable)
|
|
606
|
+
|
|
607
|
+
expect(result.success?).to eq(true)
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
context "verification_account_type" do
|
|
611
|
+
it "verifies card with account_type debit" do
|
|
612
|
+
nonce = nonce_for_new_payment_method(
|
|
613
|
+
:credit_card => {
|
|
614
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
615
|
+
:expiration_month => "11",
|
|
616
|
+
:expiration_year => "2099",
|
|
617
|
+
},
|
|
618
|
+
)
|
|
619
|
+
result = Braintree::Customer.create(
|
|
620
|
+
:payment_method_nonce => nonce,
|
|
621
|
+
:credit_card => {
|
|
622
|
+
:options => {
|
|
623
|
+
:verify_card => true,
|
|
624
|
+
:verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
|
|
625
|
+
:verification_account_type => "debit",
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
expect(result).to be_success
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
it "verifies card with account_type credit" do
|
|
634
|
+
nonce = nonce_for_new_payment_method(
|
|
635
|
+
:credit_card => {
|
|
636
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
637
|
+
:expiration_month => "11",
|
|
638
|
+
:expiration_year => "2099",
|
|
639
|
+
},
|
|
640
|
+
)
|
|
641
|
+
result = Braintree::Customer.create(
|
|
642
|
+
:payment_method_nonce => nonce,
|
|
643
|
+
:credit_card => {
|
|
644
|
+
:options => {
|
|
645
|
+
:verify_card => true,
|
|
646
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
|
647
|
+
:verification_account_type => "credit",
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
expect(result).to be_success
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
it "errors with invalid account_type" do
|
|
656
|
+
nonce = nonce_for_new_payment_method(
|
|
657
|
+
:credit_card => {
|
|
658
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
659
|
+
:expiration_month => "11",
|
|
660
|
+
:expiration_year => "2099",
|
|
661
|
+
},
|
|
662
|
+
)
|
|
663
|
+
result = Braintree::Customer.create(
|
|
664
|
+
:payment_method_nonce => nonce,
|
|
665
|
+
:credit_card => {
|
|
666
|
+
:options => {
|
|
667
|
+
:verify_card => true,
|
|
668
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
|
669
|
+
:verification_account_type => "ach",
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
)
|
|
673
|
+
|
|
674
|
+
expect(result).to_not be_success
|
|
675
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq Braintree::ErrorCodes::CreditCard::VerificationAccountTypeIsInvalid
|
|
676
|
+
end
|
|
677
|
+
|
|
678
|
+
it "errors when account_type not supported by merchant" do
|
|
679
|
+
nonce = nonce_for_new_payment_method(
|
|
680
|
+
:credit_card => {
|
|
681
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
682
|
+
:expiration_month => "11",
|
|
683
|
+
:expiration_year => "2099",
|
|
684
|
+
},
|
|
685
|
+
)
|
|
686
|
+
result = Braintree::Customer.create(
|
|
687
|
+
:payment_method_nonce => nonce,
|
|
688
|
+
:credit_card => {
|
|
689
|
+
:options => {
|
|
690
|
+
:verify_card => true,
|
|
691
|
+
:verification_account_type => "credit",
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
)
|
|
695
|
+
|
|
696
|
+
expect(result).to_not be_success
|
|
697
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq Braintree::ErrorCodes::CreditCard::VerificationAccountTypeNotSupported
|
|
698
|
+
end
|
|
306
699
|
end
|
|
307
700
|
end
|
|
308
701
|
|
|
@@ -310,16 +703,16 @@ describe Braintree::Customer do
|
|
|
310
703
|
it "returns the customer if successful" do
|
|
311
704
|
customer = Braintree::Customer.create!(
|
|
312
705
|
:first_name => "Jim",
|
|
313
|
-
:last_name => "Smith"
|
|
706
|
+
:last_name => "Smith",
|
|
314
707
|
)
|
|
315
|
-
customer.id.
|
|
316
|
-
customer.first_name.
|
|
317
|
-
customer.last_name.
|
|
708
|
+
expect(customer.id).to match(/\d+/)
|
|
709
|
+
expect(customer.first_name).to eq("Jim")
|
|
710
|
+
expect(customer.last_name).to eq("Smith")
|
|
318
711
|
end
|
|
319
712
|
|
|
320
713
|
it "can create without any attributes" do
|
|
321
714
|
customer = Braintree::Customer.create!
|
|
322
|
-
customer.id.
|
|
715
|
+
expect(customer.id).to match(/\d+/)
|
|
323
716
|
end
|
|
324
717
|
|
|
325
718
|
it "raises an exception if not successful" do
|
|
@@ -335,17 +728,17 @@ describe Braintree::Customer do
|
|
|
335
728
|
:credit_card => {
|
|
336
729
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
337
730
|
:expiration_date => "05/2010"
|
|
338
|
-
}
|
|
731
|
+
},
|
|
339
732
|
)
|
|
340
733
|
result = Braintree::Customer.credit(customer.id, :amount => "100.00")
|
|
341
|
-
result.success
|
|
342
|
-
result.transaction.amount.
|
|
343
|
-
result.transaction.type.
|
|
344
|
-
result.transaction.customer_details.id.
|
|
345
|
-
result.transaction.credit_card_details.token.
|
|
346
|
-
result.transaction.credit_card_details.bin.
|
|
347
|
-
result.transaction.credit_card_details.last_4.
|
|
348
|
-
result.transaction.credit_card_details.expiration_date.
|
|
734
|
+
expect(result.success?).to eq(true)
|
|
735
|
+
expect(result.transaction.amount).to eq(BigDecimal("100.00"))
|
|
736
|
+
expect(result.transaction.type).to eq("credit")
|
|
737
|
+
expect(result.transaction.customer_details.id).to eq(customer.id)
|
|
738
|
+
expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
|
|
739
|
+
expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
|
740
|
+
expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
|
|
741
|
+
expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
|
|
349
742
|
end
|
|
350
743
|
end
|
|
351
744
|
|
|
@@ -355,16 +748,16 @@ describe Braintree::Customer do
|
|
|
355
748
|
:credit_card => {
|
|
356
749
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
357
750
|
:expiration_date => "05/2010"
|
|
358
|
-
}
|
|
751
|
+
},
|
|
359
752
|
)
|
|
360
753
|
transaction = Braintree::Customer.credit!(customer.id, :amount => "100.00")
|
|
361
|
-
transaction.amount.
|
|
362
|
-
transaction.type.
|
|
363
|
-
transaction.customer_details.id.
|
|
364
|
-
transaction.credit_card_details.token.
|
|
365
|
-
transaction.credit_card_details.bin.
|
|
366
|
-
transaction.credit_card_details.last_4.
|
|
367
|
-
transaction.credit_card_details.expiration_date.
|
|
754
|
+
expect(transaction.amount).to eq(BigDecimal("100.00"))
|
|
755
|
+
expect(transaction.type).to eq("credit")
|
|
756
|
+
expect(transaction.customer_details.id).to eq(customer.id)
|
|
757
|
+
expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
|
|
758
|
+
expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
|
759
|
+
expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
|
|
760
|
+
expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
|
|
368
761
|
end
|
|
369
762
|
end
|
|
370
763
|
|
|
@@ -374,17 +767,17 @@ describe Braintree::Customer do
|
|
|
374
767
|
:credit_card => {
|
|
375
768
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
376
769
|
:expiration_date => "05/2010"
|
|
377
|
-
}
|
|
770
|
+
},
|
|
378
771
|
)
|
|
379
772
|
result = Braintree::Customer.sale(customer.id, :amount => "100.00")
|
|
380
|
-
result.success
|
|
381
|
-
result.transaction.amount.
|
|
382
|
-
result.transaction.type.
|
|
383
|
-
result.transaction.customer_details.id.
|
|
384
|
-
result.transaction.credit_card_details.token.
|
|
385
|
-
result.transaction.credit_card_details.bin.
|
|
386
|
-
result.transaction.credit_card_details.last_4.
|
|
387
|
-
result.transaction.credit_card_details.expiration_date.
|
|
773
|
+
expect(result.success?).to eq(true)
|
|
774
|
+
expect(result.transaction.amount).to eq(BigDecimal("100.00"))
|
|
775
|
+
expect(result.transaction.type).to eq("sale")
|
|
776
|
+
expect(result.transaction.customer_details.id).to eq(customer.id)
|
|
777
|
+
expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
|
|
778
|
+
expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
|
779
|
+
expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
|
|
780
|
+
expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
|
|
388
781
|
end
|
|
389
782
|
end
|
|
390
783
|
|
|
@@ -394,16 +787,16 @@ describe Braintree::Customer do
|
|
|
394
787
|
:credit_card => {
|
|
395
788
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
396
789
|
:expiration_date => "05/2010"
|
|
397
|
-
}
|
|
790
|
+
},
|
|
398
791
|
)
|
|
399
792
|
transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
|
|
400
|
-
transaction.amount.
|
|
401
|
-
transaction.type.
|
|
402
|
-
transaction.customer_details.id.
|
|
403
|
-
transaction.credit_card_details.token.
|
|
404
|
-
transaction.credit_card_details.bin.
|
|
405
|
-
transaction.credit_card_details.last_4.
|
|
406
|
-
transaction.credit_card_details.expiration_date.
|
|
793
|
+
expect(transaction.amount).to eq(BigDecimal("100.00"))
|
|
794
|
+
expect(transaction.type).to eq("sale")
|
|
795
|
+
expect(transaction.customer_details.id).to eq(customer.id)
|
|
796
|
+
expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
|
|
797
|
+
expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
|
798
|
+
expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
|
|
799
|
+
expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
|
|
407
800
|
end
|
|
408
801
|
end
|
|
409
802
|
|
|
@@ -413,67 +806,11 @@ describe Braintree::Customer do
|
|
|
413
806
|
:credit_card => {
|
|
414
807
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
415
808
|
:expiration_date => "05/2010"
|
|
416
|
-
}
|
|
809
|
+
},
|
|
417
810
|
)
|
|
418
|
-
transaction =
|
|
811
|
+
transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
|
|
419
812
|
collection = Braintree::Customer.transactions(customer.id)
|
|
420
|
-
collection.first.
|
|
421
|
-
end
|
|
422
|
-
end
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
describe "sale" do
|
|
426
|
-
it "creates a sale transaction using the customer, returning a result object" do
|
|
427
|
-
customer = Braintree::Customer.create!(
|
|
428
|
-
:credit_card => {
|
|
429
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
430
|
-
:expiration_date => "05/2010"
|
|
431
|
-
}
|
|
432
|
-
)
|
|
433
|
-
result = customer.sale(
|
|
434
|
-
:amount => "100.00"
|
|
435
|
-
)
|
|
436
|
-
result.success?.should == true
|
|
437
|
-
result.transaction.amount.should == BigDecimal.new("100.00")
|
|
438
|
-
result.transaction.type.should == "sale"
|
|
439
|
-
result.transaction.customer_details.id.should == customer.id
|
|
440
|
-
result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
|
441
|
-
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
|
442
|
-
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
|
443
|
-
result.transaction.credit_card_details.expiration_date.should == "05/2010"
|
|
444
|
-
end
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
describe "sale!" do
|
|
448
|
-
it "returns the created sale tranaction if valid" do
|
|
449
|
-
customer = Braintree::Customer.create!(
|
|
450
|
-
:credit_card => {
|
|
451
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
452
|
-
:expiration_date => "05/2010"
|
|
453
|
-
}
|
|
454
|
-
)
|
|
455
|
-
transaction = customer.sale!(:amount => "100.00")
|
|
456
|
-
transaction.amount.should == BigDecimal.new("100.00")
|
|
457
|
-
transaction.type.should == "sale"
|
|
458
|
-
transaction.customer_details.id.should == customer.id
|
|
459
|
-
transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
|
460
|
-
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
|
461
|
-
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
|
462
|
-
transaction.credit_card_details.expiration_date.should == "05/2010"
|
|
463
|
-
end
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
describe "transactions" do
|
|
467
|
-
it "finds transactions for the customer" do
|
|
468
|
-
customer = Braintree::Customer.create!(
|
|
469
|
-
:credit_card => {
|
|
470
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
471
|
-
:expiration_date => "05/2010"
|
|
472
|
-
}
|
|
473
|
-
)
|
|
474
|
-
transaction = customer.sale!(:amount => "100.00")
|
|
475
|
-
collection = customer.transactions
|
|
476
|
-
collection.first.should == transaction
|
|
813
|
+
expect(collection.first).to eq(transaction)
|
|
477
814
|
end
|
|
478
815
|
end
|
|
479
816
|
|
|
@@ -483,19 +820,19 @@ describe Braintree::Customer do
|
|
|
483
820
|
:credit_card => {
|
|
484
821
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
485
822
|
:expiration_date => "05/2010"
|
|
486
|
-
}
|
|
823
|
+
},
|
|
487
824
|
)
|
|
488
825
|
result = customer.credit(
|
|
489
|
-
:amount => "100.00"
|
|
826
|
+
:amount => "100.00",
|
|
490
827
|
)
|
|
491
|
-
result.success
|
|
492
|
-
result.transaction.amount.
|
|
493
|
-
result.transaction.type.
|
|
494
|
-
result.transaction.customer_details.id.
|
|
495
|
-
result.transaction.credit_card_details.token.
|
|
496
|
-
result.transaction.credit_card_details.bin.
|
|
497
|
-
result.transaction.credit_card_details.last_4.
|
|
498
|
-
result.transaction.credit_card_details.expiration_date.
|
|
828
|
+
expect(result.success?).to eq(true)
|
|
829
|
+
expect(result.transaction.amount).to eq(BigDecimal("100.00"))
|
|
830
|
+
expect(result.transaction.type).to eq("credit")
|
|
831
|
+
expect(result.transaction.customer_details.id).to eq(customer.id)
|
|
832
|
+
expect(result.transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
|
|
833
|
+
expect(result.transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
|
834
|
+
expect(result.transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
|
|
835
|
+
expect(result.transaction.credit_card_details.expiration_date).to eq("05/2010")
|
|
499
836
|
end
|
|
500
837
|
end
|
|
501
838
|
|
|
@@ -505,77 +842,16 @@ describe Braintree::Customer do
|
|
|
505
842
|
:credit_card => {
|
|
506
843
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
507
844
|
:expiration_date => "05/2010"
|
|
508
|
-
}
|
|
845
|
+
},
|
|
509
846
|
)
|
|
510
847
|
transaction = customer.credit!(:amount => "100.00")
|
|
511
|
-
transaction.amount.
|
|
512
|
-
transaction.type.
|
|
513
|
-
transaction.customer_details.id.
|
|
514
|
-
transaction.credit_card_details.token.
|
|
515
|
-
transaction.credit_card_details.bin.
|
|
516
|
-
transaction.credit_card_details.last_4.
|
|
517
|
-
transaction.credit_card_details.expiration_date.
|
|
518
|
-
end
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
describe "create_from_transparent_redirect" do
|
|
522
|
-
it "returns a successful result if successful" do
|
|
523
|
-
params = {
|
|
524
|
-
:customer => {
|
|
525
|
-
:first_name => "John",
|
|
526
|
-
:last_name => "Doe",
|
|
527
|
-
:company => "Doe Co",
|
|
528
|
-
:email => "john@doe.com",
|
|
529
|
-
:phone => "312.555.2323",
|
|
530
|
-
:fax => "614.555.5656",
|
|
531
|
-
:website => "www.johndoe.com"
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
|
|
536
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.create_customer_url)
|
|
537
|
-
result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
|
|
538
|
-
|
|
539
|
-
result.success?.should == true
|
|
540
|
-
customer = result.customer
|
|
541
|
-
customer.first_name.should == "John"
|
|
542
|
-
customer.last_name.should == "Doe"
|
|
543
|
-
customer.company.should == "Doe Co"
|
|
544
|
-
customer.email.should == "john@doe.com"
|
|
545
|
-
customer.phone.should == "312.555.2323"
|
|
546
|
-
customer.fax.should == "614.555.5656"
|
|
547
|
-
customer.website.should == "www.johndoe.com"
|
|
548
|
-
end
|
|
549
|
-
|
|
550
|
-
it "can pass any attribute through tr_data" do
|
|
551
|
-
customer_id = "customer_#{rand(1_000_000)}"
|
|
552
|
-
tr_data_params = {
|
|
553
|
-
:customer => {
|
|
554
|
-
:id => customer_id,
|
|
555
|
-
:first_name => "John",
|
|
556
|
-
:last_name => "Doe",
|
|
557
|
-
:company => "Doe Co",
|
|
558
|
-
:email => "john@doe.com",
|
|
559
|
-
:phone => "312.555.2323",
|
|
560
|
-
:fax => "614.555.5656",
|
|
561
|
-
:website => "www.johndoe.com"
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
|
566
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.create_customer_url)
|
|
567
|
-
result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
|
|
568
|
-
|
|
569
|
-
result.success?.should == true
|
|
570
|
-
customer = result.customer
|
|
571
|
-
customer.id.should == customer_id
|
|
572
|
-
customer.first_name.should == "John"
|
|
573
|
-
customer.last_name.should == "Doe"
|
|
574
|
-
customer.company.should == "Doe Co"
|
|
575
|
-
customer.email.should == "john@doe.com"
|
|
576
|
-
customer.phone.should == "312.555.2323"
|
|
577
|
-
customer.fax.should == "614.555.5656"
|
|
578
|
-
customer.website.should == "www.johndoe.com"
|
|
848
|
+
expect(transaction.amount).to eq(BigDecimal("100.00"))
|
|
849
|
+
expect(transaction.type).to eq("credit")
|
|
850
|
+
expect(transaction.customer_details.id).to eq(customer.id)
|
|
851
|
+
expect(transaction.credit_card_details.token).to eq(customer.credit_cards[0].token)
|
|
852
|
+
expect(transaction.credit_card_details.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
|
853
|
+
expect(transaction.credit_card_details.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
|
|
854
|
+
expect(transaction.credit_card_details.expiration_date).to eq("05/2010")
|
|
579
855
|
end
|
|
580
856
|
end
|
|
581
857
|
|
|
@@ -583,12 +859,12 @@ describe Braintree::Customer do
|
|
|
583
859
|
it "deletes the customer" do
|
|
584
860
|
result = Braintree::Customer.create(
|
|
585
861
|
:first_name => "Joe",
|
|
586
|
-
:last_name => "Cool"
|
|
862
|
+
:last_name => "Cool",
|
|
587
863
|
)
|
|
588
|
-
result.success
|
|
864
|
+
expect(result.success?).to eq(true)
|
|
589
865
|
|
|
590
866
|
customer = result.customer
|
|
591
|
-
customer.delete.success
|
|
867
|
+
expect(customer.delete.success?).to eq(true)
|
|
592
868
|
expect do
|
|
593
869
|
Braintree::Customer.find(customer.id)
|
|
594
870
|
end.to raise_error(Braintree::NotFoundError)
|
|
@@ -600,14 +876,15 @@ describe Braintree::Customer do
|
|
|
600
876
|
it "finds the customer with the given id" do
|
|
601
877
|
result = Braintree::Customer.create(
|
|
602
878
|
:first_name => "Joe",
|
|
603
|
-
:last_name => "Cool"
|
|
879
|
+
:last_name => "Cool",
|
|
604
880
|
)
|
|
605
|
-
result.success
|
|
881
|
+
expect(result.success?).to eq(true)
|
|
606
882
|
|
|
607
883
|
customer = Braintree::Customer.find(result.customer.id)
|
|
608
|
-
customer.id.
|
|
609
|
-
customer.
|
|
610
|
-
customer.
|
|
884
|
+
expect(customer.id).to eq(result.customer.id)
|
|
885
|
+
expect(customer.graphql_id).not_to be_nil
|
|
886
|
+
expect(customer.first_name).to eq("Joe")
|
|
887
|
+
expect(customer.last_name).to eq("Cool")
|
|
611
888
|
end
|
|
612
889
|
|
|
613
890
|
it "returns associated subscriptions" do
|
|
@@ -615,26 +892,215 @@ describe Braintree::Customer do
|
|
|
615
892
|
credit_card = Braintree::CreditCard.create(
|
|
616
893
|
:customer_id => customer.id,
|
|
617
894
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
618
|
-
:expiration_date => "05/2012"
|
|
895
|
+
:expiration_date => "05/2012",
|
|
619
896
|
).credit_card
|
|
620
897
|
|
|
621
898
|
subscription = Braintree::Subscription.create(
|
|
622
899
|
:payment_method_token => credit_card.token,
|
|
623
900
|
:plan_id => "integration_trialless_plan",
|
|
624
|
-
:price => "1.00"
|
|
901
|
+
:price => "1.00",
|
|
625
902
|
).subscription
|
|
626
903
|
|
|
627
904
|
found_customer = Braintree::Customer.find(customer.id)
|
|
628
|
-
found_customer.credit_cards.first.subscriptions.first.id.
|
|
629
|
-
found_customer.credit_cards.first.subscriptions.first.plan_id.
|
|
630
|
-
found_customer.credit_cards.first.subscriptions.first.payment_method_token.
|
|
631
|
-
found_customer.credit_cards.first.subscriptions.first.price.
|
|
905
|
+
expect(found_customer.credit_cards.first.subscriptions.first.id).to eq(subscription.id)
|
|
906
|
+
expect(found_customer.credit_cards.first.subscriptions.first.plan_id).to eq("integration_trialless_plan")
|
|
907
|
+
expect(found_customer.credit_cards.first.subscriptions.first.payment_method_token).to eq(credit_card.token)
|
|
908
|
+
expect(found_customer.credit_cards.first.subscriptions.first.price).to eq(BigDecimal("1.00"))
|
|
909
|
+
end
|
|
910
|
+
|
|
911
|
+
context "when given an association filter id" do
|
|
912
|
+
it "filters out all filterable associations" do
|
|
913
|
+
customer = Braintree::Customer.create(
|
|
914
|
+
:custom_fields => {
|
|
915
|
+
:store_me => "custom value"
|
|
916
|
+
},
|
|
917
|
+
).customer
|
|
918
|
+
credit_card = Braintree::CreditCard.create(
|
|
919
|
+
:customer_id => customer.id,
|
|
920
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
921
|
+
:expiration_date => "05/2012",
|
|
922
|
+
:billing_address => {
|
|
923
|
+
:street_address => "1 E Main St",
|
|
924
|
+
:locality => "Chicago",
|
|
925
|
+
:region => "Illinois",
|
|
926
|
+
:postal_code => "60622",
|
|
927
|
+
:country_name => "United States of America"
|
|
928
|
+
},
|
|
929
|
+
).credit_card
|
|
930
|
+
|
|
931
|
+
Braintree::Subscription.create(
|
|
932
|
+
:payment_method_token => credit_card.token,
|
|
933
|
+
:plan_id => "integration_trialless_plan",
|
|
934
|
+
:price => "1.00",
|
|
935
|
+
)
|
|
936
|
+
|
|
937
|
+
found_customer = Braintree::Customer.find(customer.id, {
|
|
938
|
+
:association_filter_id => "customernoassociations"
|
|
939
|
+
})
|
|
940
|
+
expect(found_customer.credit_cards.length).to eq(0)
|
|
941
|
+
expect(found_customer.payment_methods.length).to eq(0)
|
|
942
|
+
expect(found_customer.addresses.length).to eq(0)
|
|
943
|
+
expect(found_customer.custom_fields).to eq({})
|
|
944
|
+
end
|
|
945
|
+
|
|
946
|
+
it "filters out nested filterable associations" do
|
|
947
|
+
customer = Braintree::Customer.create(
|
|
948
|
+
:custom_fields => {
|
|
949
|
+
:store_me => "custom value"
|
|
950
|
+
},
|
|
951
|
+
).customer
|
|
952
|
+
credit_card = Braintree::CreditCard.create(
|
|
953
|
+
:customer_id => customer.id,
|
|
954
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
955
|
+
:expiration_date => "05/2012",
|
|
956
|
+
:billing_address => {
|
|
957
|
+
:street_address => "1 E Main St",
|
|
958
|
+
:locality => "Chicago",
|
|
959
|
+
:region => "Illinois",
|
|
960
|
+
:postal_code => "60622",
|
|
961
|
+
:country_name => "United States of America"
|
|
962
|
+
},
|
|
963
|
+
).credit_card
|
|
964
|
+
|
|
965
|
+
Braintree::Subscription.create(
|
|
966
|
+
:payment_method_token => credit_card.token,
|
|
967
|
+
:plan_id => "integration_trialless_plan",
|
|
968
|
+
:price => "1.00",
|
|
969
|
+
)
|
|
970
|
+
|
|
971
|
+
found_customer = Braintree::Customer.find(customer.id, {
|
|
972
|
+
:association_filter_id => "customertoplevelassociations"
|
|
973
|
+
})
|
|
974
|
+
|
|
975
|
+
expect(found_customer.credit_cards.length).to eq(1)
|
|
976
|
+
expect(found_customer.credit_cards.first.subscriptions.length).to eq(0)
|
|
977
|
+
expect(found_customer.payment_methods.length).to eq(1)
|
|
978
|
+
expect(found_customer.payment_methods.first.subscriptions.length).to eq(0)
|
|
979
|
+
expect(found_customer.addresses.length).to eq(1)
|
|
980
|
+
expect(found_customer.custom_fields.length).to eq(1)
|
|
981
|
+
end
|
|
982
|
+
end
|
|
983
|
+
|
|
984
|
+
it "returns associated ApplePayCards" do
|
|
985
|
+
result = Braintree::Customer.create(
|
|
986
|
+
:payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
|
|
987
|
+
)
|
|
988
|
+
expect(result.success?).to eq(true)
|
|
989
|
+
|
|
990
|
+
found_customer = Braintree::Customer.find(result.customer.id)
|
|
991
|
+
expect(found_customer.apple_pay_cards).not_to be_nil
|
|
992
|
+
apple_pay_card = found_customer.apple_pay_cards.first
|
|
993
|
+
expect(apple_pay_card).to be_a Braintree::ApplePayCard
|
|
994
|
+
expect(apple_pay_card.commercial).not_to be_nil
|
|
995
|
+
expect(apple_pay_card.country_of_issuance).not_to be_nil
|
|
996
|
+
expect(apple_pay_card.debit).not_to be_nil
|
|
997
|
+
expect(apple_pay_card.durbin_regulated).not_to be_nil
|
|
998
|
+
expect(apple_pay_card.expiration_year).not_to be_nil
|
|
999
|
+
expect(apple_pay_card.healthcare).not_to be_nil
|
|
1000
|
+
expect(apple_pay_card.issuing_bank).not_to be_nil
|
|
1001
|
+
expect(apple_pay_card.payment_instrument_name).to eq("AmEx 41002")
|
|
1002
|
+
expect(apple_pay_card.payroll).not_to be_nil
|
|
1003
|
+
expect(apple_pay_card.prepaid).not_to be_nil
|
|
1004
|
+
expect(apple_pay_card.prepaid_reloadable).not_to be_nil
|
|
1005
|
+
expect(apple_pay_card.product_id).not_to be_nil
|
|
1006
|
+
expect(apple_pay_card.token).not_to be_nil
|
|
1007
|
+
end
|
|
1008
|
+
|
|
1009
|
+
it "returns associated google pay proxy cards" do
|
|
1010
|
+
result = Braintree::Customer.create(
|
|
1011
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
|
1012
|
+
)
|
|
1013
|
+
expect(result.success?).to eq(true)
|
|
1014
|
+
|
|
1015
|
+
found_customer = Braintree::Customer.find(result.customer.id)
|
|
1016
|
+
expect(found_customer.google_pay_cards.size).to eq(1)
|
|
1017
|
+
expect(found_customer.payment_methods.size).to eq(1)
|
|
1018
|
+
google_pay_card = found_customer.google_pay_cards.first
|
|
1019
|
+
expect(google_pay_card).to be_a Braintree::GooglePayCard
|
|
1020
|
+
expect(google_pay_card.commercial).not_to be_nil
|
|
1021
|
+
expect(google_pay_card.country_of_issuance).not_to be_nil
|
|
1022
|
+
expect(google_pay_card.debit).not_to be_nil
|
|
1023
|
+
expect(google_pay_card.durbin_regulated).not_to be_nil
|
|
1024
|
+
expect(google_pay_card.expiration_year).not_to be_nil
|
|
1025
|
+
expect(google_pay_card.healthcare).not_to be_nil
|
|
1026
|
+
expect(google_pay_card.is_network_tokenized?).to eq(false)
|
|
1027
|
+
expect(google_pay_card.issuing_bank).not_to be_nil
|
|
1028
|
+
expect(google_pay_card.payroll).not_to be_nil
|
|
1029
|
+
expect(google_pay_card.prepaid).not_to be_nil
|
|
1030
|
+
expect(google_pay_card.prepaid_reloadable).not_to be_nil
|
|
1031
|
+
expect(google_pay_card.product_id).not_to be_nil
|
|
1032
|
+
expect(google_pay_card.token).not_to be_nil
|
|
1033
|
+
end
|
|
1034
|
+
|
|
1035
|
+
it "returns associated google pay network tokens" do
|
|
1036
|
+
result = Braintree::Customer.create(
|
|
1037
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
|
|
1038
|
+
)
|
|
1039
|
+
expect(result.success?).to eq(true)
|
|
1040
|
+
|
|
1041
|
+
found_customer = Braintree::Customer.find(result.customer.id)
|
|
1042
|
+
expect(found_customer.google_pay_cards.size).to eq(1)
|
|
1043
|
+
expect(found_customer.payment_methods.size).to eq(1)
|
|
1044
|
+
google_pay_card = found_customer.google_pay_cards.first
|
|
1045
|
+
expect(google_pay_card).to be_a Braintree::GooglePayCard
|
|
1046
|
+
expect(google_pay_card.token).not_to be_nil
|
|
1047
|
+
expect(google_pay_card.expiration_year).not_to be_nil
|
|
1048
|
+
expect(google_pay_card.is_network_tokenized?).to eq(true)
|
|
1049
|
+
expect(google_pay_card.commercial).not_to be_nil
|
|
1050
|
+
expect(google_pay_card.country_of_issuance).not_to be_nil
|
|
1051
|
+
expect(google_pay_card.debit).not_to be_nil
|
|
1052
|
+
expect(google_pay_card.durbin_regulated).not_to be_nil
|
|
1053
|
+
expect(google_pay_card.healthcare).not_to be_nil
|
|
1054
|
+
expect(google_pay_card.issuing_bank).not_to be_nil
|
|
1055
|
+
expect(google_pay_card.payroll).not_to be_nil
|
|
1056
|
+
expect(google_pay_card.prepaid).not_to be_nil
|
|
1057
|
+
expect(google_pay_card.prepaid_reloadable).not_to be_nil
|
|
1058
|
+
expect(google_pay_card.product_id).not_to be_nil
|
|
1059
|
+
end
|
|
1060
|
+
|
|
1061
|
+
it "returns associated venmo accounts" do
|
|
1062
|
+
result = Braintree::Customer.create(
|
|
1063
|
+
:payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
|
|
1064
|
+
)
|
|
1065
|
+
expect(result.success?).to eq(true)
|
|
1066
|
+
|
|
1067
|
+
found_customer = Braintree::Customer.find(result.customer.id)
|
|
1068
|
+
expect(found_customer.venmo_accounts.size).to eq(1)
|
|
1069
|
+
expect(found_customer.payment_methods.size).to eq(1)
|
|
1070
|
+
venmo_account = found_customer.venmo_accounts.first
|
|
1071
|
+
expect(venmo_account).to be_a Braintree::VenmoAccount
|
|
1072
|
+
expect(venmo_account.token).not_to be_nil
|
|
1073
|
+
expect(venmo_account.username).not_to be_nil
|
|
1074
|
+
end
|
|
1075
|
+
|
|
1076
|
+
xit "returns associated us bank accounts" do
|
|
1077
|
+
result = Braintree::Customer.create(
|
|
1078
|
+
:payment_method_nonce => generate_non_plaid_us_bank_account_nonce,
|
|
1079
|
+
:credit_card => {
|
|
1080
|
+
:options => {
|
|
1081
|
+
:verification_merchant_account_id => SpecHelper::UsBankMerchantAccountId,
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1084
|
+
)
|
|
1085
|
+
expect(result).to be_success
|
|
1086
|
+
|
|
1087
|
+
found_customer = Braintree::Customer.find(result.customer.id)
|
|
1088
|
+
expect(found_customer.us_bank_accounts.size).to eq(1)
|
|
1089
|
+
expect(found_customer.payment_methods.size).to eq(1)
|
|
1090
|
+
|
|
1091
|
+
us_bank_account = found_customer.us_bank_accounts.first
|
|
1092
|
+
expect(us_bank_account).to be_a(Braintree::UsBankAccount)
|
|
1093
|
+
expect(us_bank_account.routing_number).to eq("021000021")
|
|
1094
|
+
expect(us_bank_account.last_4).to eq("0000")
|
|
1095
|
+
expect(us_bank_account.account_type).to eq("checking")
|
|
1096
|
+
expect(us_bank_account.account_holder_name).to eq("John Doe")
|
|
1097
|
+
expect(us_bank_account.bank_name).to match(/CHASE/)
|
|
632
1098
|
end
|
|
633
1099
|
|
|
634
1100
|
it "works for a blank customer" do
|
|
635
1101
|
created_customer = Braintree::Customer.create!
|
|
636
1102
|
found_customer = Braintree::Customer.find(created_customer.id)
|
|
637
|
-
found_customer.id.
|
|
1103
|
+
expect(found_customer.id).to eq(created_customer.id)
|
|
638
1104
|
end
|
|
639
1105
|
|
|
640
1106
|
it "raises an ArgumentError if customer_id is not a string" do
|
|
@@ -657,30 +1123,214 @@ describe Braintree::Customer do
|
|
|
657
1123
|
end
|
|
658
1124
|
|
|
659
1125
|
describe "self.update" do
|
|
1126
|
+
it "updates the credit card with three_d_secure pass thru params" do
|
|
1127
|
+
customer = Braintree::Customer.create!(
|
|
1128
|
+
:first_name => "Joe",
|
|
1129
|
+
:last_name => "Cool",
|
|
1130
|
+
)
|
|
1131
|
+
result = Braintree::Customer.update(
|
|
1132
|
+
customer.id,
|
|
1133
|
+
:first_name => "Mr. Joe",
|
|
1134
|
+
:last_name => "Super Cool",
|
|
1135
|
+
:custom_fields => {
|
|
1136
|
+
:store_me => "a value"
|
|
1137
|
+
},
|
|
1138
|
+
:credit_card => {
|
|
1139
|
+
:number => 4111111111111111,
|
|
1140
|
+
:expiration_date => "05/2060",
|
|
1141
|
+
:three_d_secure_pass_thru => {
|
|
1142
|
+
:eci_flag => "05",
|
|
1143
|
+
:cavv => "some_cavv",
|
|
1144
|
+
:xid => "some_xid",
|
|
1145
|
+
:three_d_secure_version => "1.0.2",
|
|
1146
|
+
:authentication_response => "Y",
|
|
1147
|
+
:directory_response => "Y",
|
|
1148
|
+
:cavv_algorithm => "2",
|
|
1149
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
1150
|
+
},
|
|
1151
|
+
:options => {:verify_card => true},
|
|
1152
|
+
},
|
|
1153
|
+
)
|
|
1154
|
+
expect(result.success?).to eq(true)
|
|
1155
|
+
expect(result.customer.id).to eq(customer.id)
|
|
1156
|
+
expect(result.customer.first_name).to eq("Mr. Joe")
|
|
1157
|
+
expect(result.customer.last_name).to eq("Super Cool")
|
|
1158
|
+
expect(result.customer.custom_fields[:store_me]).to eq("a value")
|
|
1159
|
+
end
|
|
1160
|
+
|
|
1161
|
+
it "validates the presence of three_d_secure_version while passing three_d_secure_pass_thru in update" do
|
|
1162
|
+
customer = Braintree::Customer.create!(
|
|
1163
|
+
:first_name => "Joe",
|
|
1164
|
+
:last_name => "Cool",
|
|
1165
|
+
)
|
|
1166
|
+
result = Braintree::Customer.update(
|
|
1167
|
+
customer.id,
|
|
1168
|
+
:first_name => "Mr. Joe",
|
|
1169
|
+
:last_name => "Super Cool",
|
|
1170
|
+
:custom_fields => {
|
|
1171
|
+
:store_me => "a value"
|
|
1172
|
+
},
|
|
1173
|
+
:credit_card => {
|
|
1174
|
+
:number => 4111111111111111,
|
|
1175
|
+
:expiration_date => "05/2060",
|
|
1176
|
+
:three_d_secure_pass_thru => {
|
|
1177
|
+
:eci_flag => "05",
|
|
1178
|
+
:cavv => "some_cavv",
|
|
1179
|
+
:xid => "some_xid",
|
|
1180
|
+
:authentication_response => "Y",
|
|
1181
|
+
:directory_response => "Y",
|
|
1182
|
+
:cavv_algorithm => "2",
|
|
1183
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
1184
|
+
},
|
|
1185
|
+
options: {:verify_card => true}
|
|
1186
|
+
},
|
|
1187
|
+
)
|
|
1188
|
+
expect(result).to_not be_success
|
|
1189
|
+
error = result.errors.for(:verification).first
|
|
1190
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
|
|
1191
|
+
expect(error.message).to eq("ThreeDSecureVersion is required.")
|
|
1192
|
+
end
|
|
1193
|
+
|
|
660
1194
|
it "updates the customer with the given id if successful" do
|
|
661
1195
|
customer = Braintree::Customer.create!(
|
|
662
1196
|
:first_name => "Joe",
|
|
663
|
-
:last_name => "Cool"
|
|
1197
|
+
:last_name => "Cool",
|
|
664
1198
|
)
|
|
665
1199
|
result = Braintree::Customer.update(
|
|
666
1200
|
customer.id,
|
|
667
1201
|
:first_name => "Mr. Joe",
|
|
668
1202
|
:last_name => "Super Cool",
|
|
1203
|
+
:international_phone => {:country_code => "1", :national_number => "3121234567"},
|
|
669
1204
|
:custom_fields => {
|
|
670
1205
|
:store_me => "a value"
|
|
671
|
-
}
|
|
1206
|
+
},
|
|
1207
|
+
)
|
|
1208
|
+
expect(result.success?).to eq(true)
|
|
1209
|
+
expect(result.customer.id).to eq(customer.id)
|
|
1210
|
+
expect(result.customer.first_name).to eq("Mr. Joe")
|
|
1211
|
+
expect(result.customer.last_name).to eq("Super Cool")
|
|
1212
|
+
expect(result.customer.international_phone[:country_code]).to eq("1")
|
|
1213
|
+
expect(result.customer.international_phone[:national_number]).to eq("3121234567")
|
|
1214
|
+
expect(result.customer.custom_fields[:store_me]).to eq("a value")
|
|
1215
|
+
end
|
|
1216
|
+
|
|
1217
|
+
it "does not update customer with duplicate payment method if fail_on_payment_method option set" do
|
|
1218
|
+
customer = Braintree::Customer.create!(
|
|
1219
|
+
:credit_card => {
|
|
1220
|
+
:number => 4111111111111111,
|
|
1221
|
+
:expiration_date => "05/2010",
|
|
1222
|
+
},
|
|
1223
|
+
)
|
|
1224
|
+
result = Braintree::Customer.update(
|
|
1225
|
+
customer.id,
|
|
1226
|
+
:credit_card => {
|
|
1227
|
+
:number => 4111111111111111,
|
|
1228
|
+
:expiration_date => "05/2010",
|
|
1229
|
+
:options=> {
|
|
1230
|
+
:fail_on_duplicate_payment_method => true
|
|
1231
|
+
}
|
|
1232
|
+
},
|
|
1233
|
+
)
|
|
1234
|
+
expect(result.success?).to eq(false)
|
|
1235
|
+
expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Duplicate card exists in the vault.")
|
|
1236
|
+
end
|
|
1237
|
+
|
|
1238
|
+
it "does not update customer with duplicate payment method if fail_on_payment_method_for_customer option set" do
|
|
1239
|
+
customer = Braintree::Customer.create!(
|
|
1240
|
+
:credit_card => {
|
|
1241
|
+
:number => 4111111111111111,
|
|
1242
|
+
:expiration_date => "05/2010",
|
|
1243
|
+
},
|
|
672
1244
|
)
|
|
673
|
-
result
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
1245
|
+
result = Braintree::Customer.update(
|
|
1246
|
+
customer.id,
|
|
1247
|
+
:credit_card => {
|
|
1248
|
+
:number => 4111111111111111,
|
|
1249
|
+
:expiration_date => "05/2010",
|
|
1250
|
+
:options=> {
|
|
1251
|
+
:fail_on_duplicate_payment_method_for_customer => true
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
)
|
|
1255
|
+
expect(result.success?).to eq(false)
|
|
1256
|
+
expect(result.errors.for(:customer).for(:credit_card).on(:number)[0].message).to eq("Duplicate card exists in the vault for the customer.")
|
|
1257
|
+
end
|
|
1258
|
+
|
|
1259
|
+
it "updates the default payment method" do
|
|
1260
|
+
customer = Braintree::Customer.create!(
|
|
1261
|
+
:first_name => "Joe",
|
|
1262
|
+
:last_name => "Brown",
|
|
1263
|
+
)
|
|
1264
|
+
|
|
1265
|
+
token1 = random_payment_method_token
|
|
1266
|
+
|
|
1267
|
+
Braintree::PaymentMethod.create(
|
|
1268
|
+
:customer_id => customer.id,
|
|
1269
|
+
:payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
|
|
1270
|
+
:token => token1,
|
|
1271
|
+
)
|
|
1272
|
+
|
|
1273
|
+
payment_method1 = Braintree::PaymentMethod.find(token1)
|
|
1274
|
+
expect(payment_method1).to be_default
|
|
1275
|
+
|
|
1276
|
+
token2 = random_payment_method_token
|
|
1277
|
+
|
|
1278
|
+
Braintree::PaymentMethod.create(
|
|
1279
|
+
:customer_id => customer.id,
|
|
1280
|
+
:payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
|
|
1281
|
+
:token => token2,
|
|
1282
|
+
)
|
|
1283
|
+
|
|
1284
|
+
Braintree::Customer.update(customer.id,
|
|
1285
|
+
:default_payment_method_token => token2,
|
|
1286
|
+
)
|
|
1287
|
+
|
|
1288
|
+
payment_method2 = Braintree::PaymentMethod.find(token2)
|
|
1289
|
+
expect(payment_method2).to be_default
|
|
1290
|
+
end
|
|
1291
|
+
|
|
1292
|
+
it "updates the default payment method in the options" do
|
|
1293
|
+
customer = Braintree::Customer.create!(
|
|
1294
|
+
:first_name => "Joe",
|
|
1295
|
+
:last_name => "Brown",
|
|
1296
|
+
)
|
|
1297
|
+
|
|
1298
|
+
token1 = random_payment_method_token
|
|
1299
|
+
|
|
1300
|
+
Braintree::PaymentMethod.create(
|
|
1301
|
+
:customer_id => customer.id,
|
|
1302
|
+
:payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
|
|
1303
|
+
:token => token1,
|
|
1304
|
+
)
|
|
1305
|
+
|
|
1306
|
+
payment_method1 = Braintree::PaymentMethod.find(token1)
|
|
1307
|
+
expect(payment_method1).to be_default
|
|
1308
|
+
|
|
1309
|
+
token2 = random_payment_method_token
|
|
1310
|
+
|
|
1311
|
+
Braintree::PaymentMethod.create(
|
|
1312
|
+
:customer_id => customer.id,
|
|
1313
|
+
:payment_method_nonce => Braintree::Test::Nonce::TransactableMasterCard,
|
|
1314
|
+
:token => token2,
|
|
1315
|
+
)
|
|
1316
|
+
|
|
1317
|
+
Braintree::Customer.update(customer.id,
|
|
1318
|
+
:credit_card => {
|
|
1319
|
+
:options => {
|
|
1320
|
+
:update_existing_token => token2,
|
|
1321
|
+
:make_default => true
|
|
1322
|
+
}
|
|
1323
|
+
},
|
|
1324
|
+
)
|
|
1325
|
+
|
|
1326
|
+
payment_method2 = Braintree::PaymentMethod.find(token2)
|
|
1327
|
+
expect(payment_method2).to be_default
|
|
678
1328
|
end
|
|
679
1329
|
|
|
680
1330
|
it "can use any country code" do
|
|
681
1331
|
customer = Braintree::Customer.create!(
|
|
682
1332
|
:first_name => "Alex",
|
|
683
|
-
:last_name => "Matterson"
|
|
1333
|
+
:last_name => "Matterson",
|
|
684
1334
|
)
|
|
685
1335
|
result = Braintree::Customer.update(
|
|
686
1336
|
customer.id,
|
|
@@ -695,13 +1345,13 @@ describe Braintree::Customer do
|
|
|
695
1345
|
:country_code_alpha3 => "FJI",
|
|
696
1346
|
:country_code_numeric => "242"
|
|
697
1347
|
}
|
|
698
|
-
}
|
|
1348
|
+
},
|
|
699
1349
|
)
|
|
700
|
-
result.success
|
|
701
|
-
result.customer.addresses[0].country_name.
|
|
702
|
-
result.customer.addresses[0].country_code_alpha2.
|
|
703
|
-
result.customer.addresses[0].country_code_alpha3.
|
|
704
|
-
result.customer.addresses[0].country_code_numeric.
|
|
1350
|
+
expect(result.success?).to eq(true)
|
|
1351
|
+
expect(result.customer.addresses[0].country_name).to eq("Fiji")
|
|
1352
|
+
expect(result.customer.addresses[0].country_code_alpha2).to eq("FJ")
|
|
1353
|
+
expect(result.customer.addresses[0].country_code_alpha3).to eq("FJI")
|
|
1354
|
+
expect(result.customer.addresses[0].country_code_numeric).to eq("242")
|
|
705
1355
|
end
|
|
706
1356
|
|
|
707
1357
|
it "can update the customer, credit card, and billing address in one request" do
|
|
@@ -714,7 +1364,7 @@ describe Braintree::Customer do
|
|
|
714
1364
|
:first_name => "Joe",
|
|
715
1365
|
:postal_code => "60622"
|
|
716
1366
|
}
|
|
717
|
-
}
|
|
1367
|
+
},
|
|
718
1368
|
)
|
|
719
1369
|
|
|
720
1370
|
result = Braintree::Customer.update(
|
|
@@ -722,26 +1372,175 @@ describe Braintree::Customer do
|
|
|
722
1372
|
:first_name => "New Joe",
|
|
723
1373
|
:credit_card => {
|
|
724
1374
|
:cardholder_name => "New Joe Cardholder",
|
|
725
|
-
:options => {
|
|
1375
|
+
:options => {:update_existing_token => customer.credit_cards.first.token},
|
|
726
1376
|
:billing_address => {
|
|
727
1377
|
:last_name => "Cool",
|
|
728
1378
|
:postal_code => "60666",
|
|
729
|
-
:options => {
|
|
1379
|
+
:options => {:update_existing => true}
|
|
730
1380
|
}
|
|
731
|
-
}
|
|
1381
|
+
},
|
|
732
1382
|
)
|
|
733
|
-
result.success
|
|
734
|
-
result.customer.id.
|
|
735
|
-
result.customer.first_name.
|
|
1383
|
+
expect(result.success?).to eq(true)
|
|
1384
|
+
expect(result.customer.id).to eq(customer.id)
|
|
1385
|
+
expect(result.customer.first_name).to eq("New Joe")
|
|
736
1386
|
|
|
737
|
-
result.customer.credit_cards.size.
|
|
1387
|
+
expect(result.customer.credit_cards.size).to eq(1)
|
|
738
1388
|
credit_card = result.customer.credit_cards.first
|
|
739
|
-
credit_card.bin.
|
|
740
|
-
credit_card.cardholder_name.
|
|
1389
|
+
expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa.slice(0, 6))
|
|
1390
|
+
expect(credit_card.cardholder_name).to eq("New Joe Cardholder")
|
|
741
1391
|
|
|
742
|
-
credit_card.billing_address.first_name.
|
|
743
|
-
credit_card.billing_address.last_name.
|
|
744
|
-
credit_card.billing_address.postal_code.
|
|
1392
|
+
expect(credit_card.billing_address.first_name).to eq("Joe")
|
|
1393
|
+
expect(credit_card.billing_address.last_name).to eq("Cool")
|
|
1394
|
+
expect(credit_card.billing_address.postal_code).to eq("60666")
|
|
1395
|
+
end
|
|
1396
|
+
|
|
1397
|
+
it "can update the customer and verify_card with a specific verification_amount" do
|
|
1398
|
+
customer = Braintree::Customer.create!(
|
|
1399
|
+
:first_name => "Joe",
|
|
1400
|
+
)
|
|
1401
|
+
|
|
1402
|
+
result = Braintree::Customer.update(
|
|
1403
|
+
customer.id,
|
|
1404
|
+
:first_name => "New Joe",
|
|
1405
|
+
:credit_card => {
|
|
1406
|
+
:cardholder_name => "New Joe Cardholder",
|
|
1407
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1408
|
+
:expiration_date => "12/2009",
|
|
1409
|
+
:options => {:verify_card => true, :verification_amount => "2.00"}
|
|
1410
|
+
},
|
|
1411
|
+
)
|
|
1412
|
+
expect(result.success?).to eq(true)
|
|
1413
|
+
end
|
|
1414
|
+
|
|
1415
|
+
it "includes risk data when skip_advanced_fraud_checking is false" do
|
|
1416
|
+
with_fraud_protection_enterprise_merchant do
|
|
1417
|
+
customer = Braintree::Customer.create!(
|
|
1418
|
+
:first_name => "Joe",
|
|
1419
|
+
)
|
|
1420
|
+
|
|
1421
|
+
updated_result = Braintree::Customer.update(
|
|
1422
|
+
customer.id,
|
|
1423
|
+
:credit_card => {
|
|
1424
|
+
:cardholder_name => "New Joe Cardholder",
|
|
1425
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1426
|
+
:expiration_date => "12/2009",
|
|
1427
|
+
:options => {
|
|
1428
|
+
:skip_advanced_fraud_checking => false,
|
|
1429
|
+
:verify_card => true,
|
|
1430
|
+
},
|
|
1431
|
+
},
|
|
1432
|
+
)
|
|
1433
|
+
|
|
1434
|
+
expect(updated_result).to be_success
|
|
1435
|
+
verification = updated_result.customer.credit_cards.first.verification
|
|
1436
|
+
expect(verification.risk_data).not_to be_nil
|
|
1437
|
+
end
|
|
1438
|
+
end
|
|
1439
|
+
|
|
1440
|
+
it "does not include risk data when skip_advanced_fraud_checking is true" do
|
|
1441
|
+
with_fraud_protection_enterprise_merchant do
|
|
1442
|
+
customer = Braintree::Customer.create!(
|
|
1443
|
+
:first_name => "Joe",
|
|
1444
|
+
)
|
|
1445
|
+
|
|
1446
|
+
updated_result = Braintree::Customer.update(
|
|
1447
|
+
customer.id,
|
|
1448
|
+
:credit_card => {
|
|
1449
|
+
:cardholder_name => "New Joe Cardholder",
|
|
1450
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1451
|
+
:expiration_date => "12/2009",
|
|
1452
|
+
:options => {
|
|
1453
|
+
:skip_advanced_fraud_checking => true,
|
|
1454
|
+
:verify_card => true,
|
|
1455
|
+
},
|
|
1456
|
+
},
|
|
1457
|
+
)
|
|
1458
|
+
|
|
1459
|
+
expect(updated_result).to be_success
|
|
1460
|
+
verification = updated_result.customer.credit_cards.first.verification
|
|
1461
|
+
expect(verification.risk_data).to be_nil
|
|
1462
|
+
end
|
|
1463
|
+
end
|
|
1464
|
+
|
|
1465
|
+
it "can update a tax_identifier" do
|
|
1466
|
+
customer = Braintree::Customer.create!(
|
|
1467
|
+
:tax_identifiers => [
|
|
1468
|
+
{:country_code => "US", :identifier => "987654321"},
|
|
1469
|
+
{:country_code => "CL", :identifier => "123456789"}
|
|
1470
|
+
],
|
|
1471
|
+
)
|
|
1472
|
+
|
|
1473
|
+
result = Braintree::Customer.update(
|
|
1474
|
+
customer.id,
|
|
1475
|
+
:tax_identifiers => [{:country_code => "US", :identifier => "567891234"}],
|
|
1476
|
+
)
|
|
1477
|
+
expect(result.success?).to eq(true)
|
|
1478
|
+
end
|
|
1479
|
+
|
|
1480
|
+
it "validates presence of three_d_secure_version in 3ds pass thru params" do
|
|
1481
|
+
result = Braintree::Customer.create(
|
|
1482
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
|
1483
|
+
:credit_card => {
|
|
1484
|
+
:three_d_secure_pass_thru => {
|
|
1485
|
+
:eci_flag => "05",
|
|
1486
|
+
:cavv => "some_cavv",
|
|
1487
|
+
:xid => "some_xid",
|
|
1488
|
+
:three_d_secure_version => "xx",
|
|
1489
|
+
:authentication_response => "Y",
|
|
1490
|
+
:directory_response => "Y",
|
|
1491
|
+
:cavv_algorithm => "2",
|
|
1492
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
1493
|
+
},
|
|
1494
|
+
:options => {:verify_card => true}
|
|
1495
|
+
},
|
|
1496
|
+
)
|
|
1497
|
+
|
|
1498
|
+
expect(result).not_to be_success
|
|
1499
|
+
error = result.errors.for(:verification).first
|
|
1500
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
|
|
1501
|
+
expect(error.message).to eq("The version of 3D Secure authentication must be composed only of digits and separated by periods (e.g. `1.0.2`).")
|
|
1502
|
+
end
|
|
1503
|
+
|
|
1504
|
+
it "accepts three_d_secure pass thru params in the request" do
|
|
1505
|
+
result = Braintree::Customer.create(
|
|
1506
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
|
1507
|
+
:credit_card => {
|
|
1508
|
+
:three_d_secure_pass_thru => {
|
|
1509
|
+
:eci_flag => "05",
|
|
1510
|
+
:cavv => "some_cavv",
|
|
1511
|
+
:xid => "some_xid",
|
|
1512
|
+
:three_d_secure_version => "2.2.1",
|
|
1513
|
+
:authentication_response => "Y",
|
|
1514
|
+
:directory_response => "Y",
|
|
1515
|
+
:cavv_algorithm => "2",
|
|
1516
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
1517
|
+
},
|
|
1518
|
+
:options => {:verify_card => true}
|
|
1519
|
+
},
|
|
1520
|
+
)
|
|
1521
|
+
|
|
1522
|
+
expect(result).to be_success
|
|
1523
|
+
end
|
|
1524
|
+
|
|
1525
|
+
it "returns 3DS info on cc verification" do
|
|
1526
|
+
result = Braintree::Customer.create(
|
|
1527
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
|
1528
|
+
:credit_card => {
|
|
1529
|
+
:options => {:verify_card => true}
|
|
1530
|
+
},
|
|
1531
|
+
)
|
|
1532
|
+
expect(result.success?).to eq(true)
|
|
1533
|
+
|
|
1534
|
+
three_d_secure_info = result.customer.payment_methods.first.verification.three_d_secure_info
|
|
1535
|
+
expect(three_d_secure_info.enrolled).to eq("Y")
|
|
1536
|
+
expect(three_d_secure_info).to be_liability_shifted
|
|
1537
|
+
expect(three_d_secure_info).to be_liability_shift_possible
|
|
1538
|
+
expect(three_d_secure_info.status).to eq("authenticate_successful")
|
|
1539
|
+
expect(three_d_secure_info.cavv).to eq("cavv_value")
|
|
1540
|
+
expect(three_d_secure_info.xid).to eq("xid_value")
|
|
1541
|
+
expect(three_d_secure_info.eci_flag).to eq("05")
|
|
1542
|
+
expect(three_d_secure_info.three_d_secure_version).to eq("1.0.2")
|
|
1543
|
+
expect(three_d_secure_info.ds_transaction_id).to eq(nil)
|
|
745
1544
|
end
|
|
746
1545
|
|
|
747
1546
|
it "can update the nested billing address with billing_address_id" do
|
|
@@ -750,7 +1549,7 @@ describe Braintree::Customer do
|
|
|
750
1549
|
address = Braintree::Address.create!(
|
|
751
1550
|
:customer_id => customer.id,
|
|
752
1551
|
:first_name => "John",
|
|
753
|
-
:last_name => "Doe"
|
|
1552
|
+
:last_name => "Doe",
|
|
754
1553
|
)
|
|
755
1554
|
|
|
756
1555
|
customer = Braintree::Customer.update(
|
|
@@ -759,23 +1558,144 @@ describe Braintree::Customer do
|
|
|
759
1558
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
760
1559
|
:expiration_date => "12/2009",
|
|
761
1560
|
:billing_address_id => address.id
|
|
762
|
-
}
|
|
1561
|
+
},
|
|
763
1562
|
).customer
|
|
764
1563
|
|
|
765
1564
|
billing_address = customer.credit_cards.first.billing_address
|
|
766
|
-
billing_address.id.
|
|
767
|
-
billing_address.first_name.
|
|
768
|
-
billing_address.last_name.
|
|
1565
|
+
expect(billing_address.id).to eq(address.id)
|
|
1566
|
+
expect(billing_address.first_name).to eq("John")
|
|
1567
|
+
expect(billing_address.last_name).to eq("Doe")
|
|
769
1568
|
end
|
|
770
1569
|
|
|
771
1570
|
it "returns an error response if invalid" do
|
|
772
1571
|
customer = Braintree::Customer.create!(:email => "valid@email.com")
|
|
773
1572
|
result = Braintree::Customer.update(
|
|
774
1573
|
customer.id,
|
|
775
|
-
:email => "@invalid.com"
|
|
1574
|
+
:email => "@invalid.com",
|
|
776
1575
|
)
|
|
777
|
-
result.success
|
|
778
|
-
result.errors.for(:customer).on(:email)[0].message.
|
|
1576
|
+
expect(result.success?).to eq(false)
|
|
1577
|
+
expect(result.errors.for(:customer).on(:email)[0].message).to eq("Email is an invalid format.")
|
|
1578
|
+
end
|
|
1579
|
+
|
|
1580
|
+
context "verification_currency_iso_code" do
|
|
1581
|
+
it "can update the customer after validating verification_currency_iso_code" do
|
|
1582
|
+
customer = Braintree::Customer.create!(
|
|
1583
|
+
:first_name => "Joe",
|
|
1584
|
+
)
|
|
1585
|
+
|
|
1586
|
+
result = Braintree::Customer.update(
|
|
1587
|
+
customer.id,
|
|
1588
|
+
:first_name => "New Joe",
|
|
1589
|
+
:credit_card => {
|
|
1590
|
+
:cardholder_name => "New Joe Cardholder",
|
|
1591
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1592
|
+
:expiration_date => "12/2009",
|
|
1593
|
+
:options => {:verify_card => true, :verification_currency_iso_code => "USD"}
|
|
1594
|
+
},
|
|
1595
|
+
)
|
|
1596
|
+
expect(result.success?).to eq(true)
|
|
1597
|
+
result.customer.credit_cards[0].verification.currency_iso_code == "USD"
|
|
1598
|
+
end
|
|
1599
|
+
|
|
1600
|
+
it "can update the customer after validating verification_currency_iso_code against the given verification_merchant_account_id" do
|
|
1601
|
+
customer = Braintree::Customer.create!(
|
|
1602
|
+
:first_name => "Joe",
|
|
1603
|
+
)
|
|
1604
|
+
|
|
1605
|
+
result = Braintree::Customer.update(
|
|
1606
|
+
customer.id,
|
|
1607
|
+
:first_name => "New Joe",
|
|
1608
|
+
:credit_card => {
|
|
1609
|
+
:cardholder_name => "New Joe Cardholder",
|
|
1610
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1611
|
+
:expiration_date => "12/2009",
|
|
1612
|
+
:options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"}
|
|
1613
|
+
},
|
|
1614
|
+
)
|
|
1615
|
+
expect(result.success?).to eq(true)
|
|
1616
|
+
result.customer.credit_cards[0].verification.currency_iso_code == "USD"
|
|
1617
|
+
result.customer.credit_cards[0].verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
|
|
1618
|
+
end
|
|
1619
|
+
|
|
1620
|
+
it "throws error due to verification_currency_iso_code not matching against the currency configured in default merchant account" do
|
|
1621
|
+
customer = Braintree::Customer.create!(
|
|
1622
|
+
:first_name => "Joe",
|
|
1623
|
+
)
|
|
1624
|
+
|
|
1625
|
+
result = Braintree::Customer.update(
|
|
1626
|
+
customer.id,
|
|
1627
|
+
:first_name => "New Joe",
|
|
1628
|
+
:credit_card => {
|
|
1629
|
+
:cardholder_name => "New Joe Cardholder",
|
|
1630
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1631
|
+
:expiration_date => "12/2009",
|
|
1632
|
+
:options => {:verify_card => true, :verification_currency_iso_code => "GBP"}
|
|
1633
|
+
},
|
|
1634
|
+
)
|
|
1635
|
+
expect(result.success?).to eq(false)
|
|
1636
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
|
1637
|
+
|
|
1638
|
+
end
|
|
1639
|
+
|
|
1640
|
+
it "throws error due to verification_currency_iso_code not matching against the currency configured in the given verification merchant account" do
|
|
1641
|
+
customer = Braintree::Customer.create!(
|
|
1642
|
+
:first_name => "Joe",
|
|
1643
|
+
)
|
|
1644
|
+
|
|
1645
|
+
result = Braintree::Customer.update(
|
|
1646
|
+
customer.id,
|
|
1647
|
+
:first_name => "New Joe",
|
|
1648
|
+
:credit_card => {
|
|
1649
|
+
:cardholder_name => "New Joe Cardholder",
|
|
1650
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1651
|
+
:expiration_date => "12/2009",
|
|
1652
|
+
:options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"}
|
|
1653
|
+
},
|
|
1654
|
+
)
|
|
1655
|
+
expect(result.success?).to eq(false)
|
|
1656
|
+
expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
|
1657
|
+
|
|
1658
|
+
end
|
|
1659
|
+
end
|
|
1660
|
+
|
|
1661
|
+
context "verification_account_type" do
|
|
1662
|
+
it "updates the credit card with account_type credit" do
|
|
1663
|
+
customer = Braintree::Customer.create!
|
|
1664
|
+
update_result = Braintree::Customer.update(
|
|
1665
|
+
customer.id,
|
|
1666
|
+
:credit_card => {
|
|
1667
|
+
:cardholder_name => "New Holder",
|
|
1668
|
+
:cvv => "456",
|
|
1669
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
1670
|
+
:expiration_date => "06/2013",
|
|
1671
|
+
:options => {
|
|
1672
|
+
:verify_card => true,
|
|
1673
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
|
1674
|
+
:verification_account_type => "credit",
|
|
1675
|
+
},
|
|
1676
|
+
},
|
|
1677
|
+
)
|
|
1678
|
+
expect(update_result).to be_success
|
|
1679
|
+
end
|
|
1680
|
+
|
|
1681
|
+
it "updates the credit card with account_type debit" do
|
|
1682
|
+
customer = Braintree::Customer.create!
|
|
1683
|
+
update_result = Braintree::Customer.update(
|
|
1684
|
+
customer.id,
|
|
1685
|
+
:credit_card => {
|
|
1686
|
+
:cardholder_name => "New Holder",
|
|
1687
|
+
:cvv => "456",
|
|
1688
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
1689
|
+
:expiration_date => "06/2013",
|
|
1690
|
+
:options => {
|
|
1691
|
+
:verify_card => true,
|
|
1692
|
+
:verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
|
|
1693
|
+
:verification_account_type => "debit",
|
|
1694
|
+
},
|
|
1695
|
+
},
|
|
1696
|
+
)
|
|
1697
|
+
expect(update_result).to be_success
|
|
1698
|
+
end
|
|
779
1699
|
end
|
|
780
1700
|
end
|
|
781
1701
|
|
|
@@ -783,16 +1703,16 @@ describe Braintree::Customer do
|
|
|
783
1703
|
it "returns the updated customer if successful" do
|
|
784
1704
|
customer = Braintree::Customer.create!(
|
|
785
1705
|
:first_name => "Joe",
|
|
786
|
-
:last_name => "Cool"
|
|
1706
|
+
:last_name => "Cool",
|
|
787
1707
|
)
|
|
788
1708
|
updated_customer = Braintree::Customer.update!(
|
|
789
1709
|
customer.id,
|
|
790
1710
|
:first_name => "Mr. Joe",
|
|
791
|
-
:last_name => "Super Cool"
|
|
1711
|
+
:last_name => "Super Cool",
|
|
792
1712
|
)
|
|
793
|
-
updated_customer.first_name.
|
|
794
|
-
updated_customer.last_name.
|
|
795
|
-
updated_customer.updated_at.between?(Time.now - 60, Time.now).
|
|
1713
|
+
expect(updated_customer.first_name).to eq("Mr. Joe")
|
|
1714
|
+
expect(updated_customer.last_name).to eq("Super Cool")
|
|
1715
|
+
expect(updated_customer.updated_at.between?(Time.now - 60, Time.now)).to eq(true)
|
|
796
1716
|
end
|
|
797
1717
|
|
|
798
1718
|
it "raises an error if unsuccessful" do
|
|
@@ -803,210 +1723,209 @@ describe Braintree::Customer do
|
|
|
803
1723
|
end
|
|
804
1724
|
end
|
|
805
1725
|
|
|
806
|
-
describe "
|
|
807
|
-
it "
|
|
1726
|
+
describe "default_payment_method" do
|
|
1727
|
+
it "should return the default credit card for a given customer" do
|
|
808
1728
|
customer = Braintree::Customer.create!(
|
|
809
|
-
:
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1729
|
+
:credit_card => {
|
|
1730
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1731
|
+
:expiration_date => "12/2015",
|
|
1732
|
+
:options => {
|
|
1733
|
+
:make_default => false
|
|
1734
|
+
}
|
|
1735
|
+
},
|
|
815
1736
|
)
|
|
816
|
-
update_result.success?.should == true
|
|
817
|
-
update_result.customer.should == customer
|
|
818
|
-
updated_customer = update_result.customer
|
|
819
|
-
updated_customer.first_name.should == "Mr. Joe"
|
|
820
|
-
updated_customer.last_name.should == "Super Cool"
|
|
821
|
-
end
|
|
822
1737
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
:
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
1738
|
+
default_payment_method = Braintree::CreditCard.create!(
|
|
1739
|
+
:customer_id => customer.id,
|
|
1740
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1741
|
+
:expiration_date => "11/2015",
|
|
1742
|
+
:options => {
|
|
1743
|
+
:make_default => true
|
|
1744
|
+
},
|
|
829
1745
|
)
|
|
830
|
-
|
|
831
|
-
|
|
1746
|
+
|
|
1747
|
+
customer = Braintree::Customer.find(customer.id)
|
|
1748
|
+
|
|
1749
|
+
expect(customer.default_payment_method).to eq(default_payment_method)
|
|
832
1750
|
end
|
|
833
1751
|
end
|
|
834
1752
|
|
|
835
|
-
describe "
|
|
836
|
-
|
|
837
|
-
customer
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
customer
|
|
846
|
-
|
|
847
|
-
|
|
1753
|
+
describe "paypal" do
|
|
1754
|
+
context "future" do
|
|
1755
|
+
it "creates a customer with a future paypal account" do
|
|
1756
|
+
result = Braintree::Customer.create(
|
|
1757
|
+
:payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
|
|
1758
|
+
)
|
|
1759
|
+
|
|
1760
|
+
expect(result).to be_success
|
|
1761
|
+
end
|
|
1762
|
+
|
|
1763
|
+
it "updates a customer with a future paypal account" do
|
|
1764
|
+
customer = Braintree::Customer.create!(
|
|
1765
|
+
:credit_card => {
|
|
1766
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1767
|
+
:expiration_date => "12/2015",
|
|
1768
|
+
:options => {
|
|
1769
|
+
:make_default => true
|
|
1770
|
+
}
|
|
1771
|
+
},
|
|
1772
|
+
)
|
|
1773
|
+
|
|
1774
|
+
paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
|
|
1775
|
+
nonce = nonce_for_paypal_account(
|
|
1776
|
+
:consent_code => "PAYPAL_CONSENT_CODE",
|
|
1777
|
+
:token => paypal_account_token,
|
|
1778
|
+
:options => {
|
|
1779
|
+
:make_default => true
|
|
1780
|
+
},
|
|
1781
|
+
)
|
|
1782
|
+
|
|
1783
|
+
result = Braintree::Customer.update(
|
|
1784
|
+
customer.id,
|
|
1785
|
+
:payment_method_nonce => nonce,
|
|
1786
|
+
)
|
|
1787
|
+
|
|
1788
|
+
expect(result).to be_success
|
|
1789
|
+
expect(result.customer.default_payment_method.token).to eq(paypal_account_token)
|
|
1790
|
+
end
|
|
848
1791
|
end
|
|
849
1792
|
|
|
850
|
-
|
|
851
|
-
customer
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
1793
|
+
context "limited use" do
|
|
1794
|
+
it "creates a customer with payment_method_nonce and paypal options" do
|
|
1795
|
+
paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
|
|
1796
|
+
nonce = nonce_for_paypal_account(
|
|
1797
|
+
:consent_code => "PAYPAL_CONSENT_CODE",
|
|
1798
|
+
:token => paypal_account_token,
|
|
1799
|
+
:options => {
|
|
1800
|
+
:make_default => true
|
|
1801
|
+
},
|
|
1802
|
+
)
|
|
1803
|
+
|
|
1804
|
+
result = Braintree::Customer.create(
|
|
1805
|
+
:payment_method_nonce => nonce,
|
|
1806
|
+
:options => {
|
|
1807
|
+
:paypal => {
|
|
1808
|
+
:payee_email => "payee@example.com",
|
|
1809
|
+
:order_id => "merchant-order-id",
|
|
1810
|
+
:custom_field => "custom merchant field",
|
|
1811
|
+
:description => "merchant description",
|
|
1812
|
+
:amount => "1.23",
|
|
1813
|
+
:shipping => {
|
|
1814
|
+
:first_name => "first",
|
|
1815
|
+
:last_name => "last",
|
|
1816
|
+
:locality => "Austin",
|
|
1817
|
+
:postal_code => "78729",
|
|
1818
|
+
:street_address => "7700 W Parmer Ln",
|
|
1819
|
+
:country_name => "US",
|
|
1820
|
+
:region => "TX",
|
|
1821
|
+
},
|
|
1822
|
+
},
|
|
1823
|
+
},
|
|
1824
|
+
)
|
|
1825
|
+
|
|
1826
|
+
expect(result).to be_success
|
|
1827
|
+
end
|
|
1828
|
+
|
|
1829
|
+
it "updates a customer with payment_method_nonce and paypal options" do
|
|
1830
|
+
customer = Braintree::Customer.create!(
|
|
1831
|
+
:credit_card => {
|
|
1832
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1833
|
+
:expiration_date => "12/2015",
|
|
1834
|
+
:options => {
|
|
1835
|
+
:make_default => true
|
|
1836
|
+
}
|
|
1837
|
+
},
|
|
1838
|
+
)
|
|
1839
|
+
|
|
1840
|
+
paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
|
|
1841
|
+
nonce = nonce_for_paypal_account(
|
|
1842
|
+
:consent_code => "PAYPAL_CONSENT_CODE",
|
|
1843
|
+
:token => paypal_account_token,
|
|
1844
|
+
:options => {
|
|
1845
|
+
:make_default => true
|
|
1846
|
+
},
|
|
1847
|
+
)
|
|
1848
|
+
|
|
1849
|
+
result = Braintree::Customer.update(
|
|
1850
|
+
customer.id,
|
|
1851
|
+
:payment_method_nonce => nonce,
|
|
1852
|
+
:options => {
|
|
1853
|
+
:paypal => {
|
|
1854
|
+
:payee_email => "payee@example.com",
|
|
1855
|
+
:order_id => "merchant-order-id",
|
|
1856
|
+
:custom_field => "custom merchant field",
|
|
1857
|
+
:description => "merchant description",
|
|
1858
|
+
:amount => "1.23",
|
|
1859
|
+
:shipping => {
|
|
1860
|
+
:first_name => "first",
|
|
1861
|
+
:last_name => "last",
|
|
1862
|
+
:locality => "Austin",
|
|
1863
|
+
:postal_code => "78729",
|
|
1864
|
+
:street_address => "7700 W Parmer Ln",
|
|
1865
|
+
:country_name => "US",
|
|
1866
|
+
:region => "TX",
|
|
1867
|
+
},
|
|
1868
|
+
},
|
|
1869
|
+
},
|
|
1870
|
+
)
|
|
1871
|
+
|
|
1872
|
+
expect(result).to be_success
|
|
1873
|
+
expect(result.customer.default_payment_method.token).to eq(paypal_account_token)
|
|
1874
|
+
end
|
|
857
1875
|
end
|
|
858
|
-
end
|
|
859
1876
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
original_customer = result.customer
|
|
873
|
-
params = {
|
|
874
|
-
:customer => {
|
|
875
|
-
:first_name => "New First",
|
|
876
|
-
:last_name => "New Last",
|
|
877
|
-
:company => "New Company",
|
|
878
|
-
:email => "new@email.com",
|
|
879
|
-
:phone => "888.111.2222",
|
|
880
|
-
:fax => "999.222.3333",
|
|
881
|
-
:website => "new.website.com"
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
tr_data_params = {
|
|
885
|
-
:customer_id => original_customer.id
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
|
889
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.update_customer_url)
|
|
890
|
-
result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
|
|
891
|
-
|
|
892
|
-
result.success?.should == true
|
|
893
|
-
customer = result.customer
|
|
894
|
-
customer.id.should == original_customer.id
|
|
895
|
-
customer.first_name.should == "New First"
|
|
896
|
-
customer.last_name.should == "New Last"
|
|
897
|
-
customer.company.should == "New Company"
|
|
898
|
-
customer.email.should == "new@email.com"
|
|
899
|
-
customer.phone.should == "888.111.2222"
|
|
900
|
-
customer.fax.should == "999.222.3333"
|
|
901
|
-
customer.website.should == "new.website.com"
|
|
902
|
-
end
|
|
903
|
-
|
|
904
|
-
it "returns a successful result when updating an existing credit card" do
|
|
905
|
-
result = Braintree::Customer.create(
|
|
906
|
-
:first_name => "Old First",
|
|
907
|
-
:last_name => "Old Last",
|
|
908
|
-
:company => "Old Company",
|
|
909
|
-
:email => "old@email.com",
|
|
910
|
-
:phone => "000.111.2222",
|
|
911
|
-
:fax => "000.222.3333",
|
|
912
|
-
:website => "old.website.com",
|
|
913
|
-
:credit_card => {
|
|
914
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
915
|
-
:expiration_date => "12/2009",
|
|
916
|
-
:billing_address => {
|
|
917
|
-
:first_name => "Joe",
|
|
918
|
-
:postal_code => "60622"
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
)
|
|
922
|
-
result.success?.should == true
|
|
923
|
-
original_customer = result.customer
|
|
924
|
-
|
|
925
|
-
tr_data_params = {
|
|
926
|
-
:customer_id => original_customer.id,
|
|
927
|
-
:customer => {
|
|
928
|
-
:first_name => "New First",
|
|
929
|
-
:last_name => "New Last",
|
|
930
|
-
:company => "New Company",
|
|
931
|
-
:email => "new@email.com",
|
|
932
|
-
:phone => "888.111.2222",
|
|
933
|
-
:fax => "999.222.3333",
|
|
934
|
-
:website => "new.website.com",
|
|
1877
|
+
context "onetime" do
|
|
1878
|
+
it "does not create a customer with a onetime paypal account" do
|
|
1879
|
+
result = Braintree::Customer.create(
|
|
1880
|
+
:payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
|
|
1881
|
+
)
|
|
1882
|
+
|
|
1883
|
+
expect(result).not_to be_success
|
|
1884
|
+
end
|
|
1885
|
+
|
|
1886
|
+
it "does not update a customer with a onetime paypal account" do
|
|
1887
|
+
credit_card_token = rand(36**3).to_s(36)
|
|
1888
|
+
customer = Braintree::Customer.create!(
|
|
935
1889
|
:credit_card => {
|
|
936
|
-
:
|
|
937
|
-
:
|
|
938
|
-
:
|
|
939
|
-
|
|
940
|
-
:
|
|
941
|
-
:options => { :update_existing => true }
|
|
1890
|
+
:token => credit_card_token,
|
|
1891
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1892
|
+
:expiration_date => "12/2015",
|
|
1893
|
+
:options => {
|
|
1894
|
+
:make_default => true
|
|
942
1895
|
}
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
}
|
|
1896
|
+
},
|
|
1897
|
+
)
|
|
946
1898
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
1899
|
+
paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
|
|
1900
|
+
nonce = nonce_for_paypal_account(
|
|
1901
|
+
:access_token => "PAYPAL_ACCESS_TOKEN",
|
|
1902
|
+
:token => paypal_account_token,
|
|
1903
|
+
:options => {
|
|
1904
|
+
:make_default => true
|
|
1905
|
+
},
|
|
1906
|
+
)
|
|
950
1907
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
customer.fax.should == "999.222.3333"
|
|
960
|
-
customer.website.should == "new.website.com"
|
|
961
|
-
|
|
962
|
-
credit_card = customer.credit_cards.first
|
|
963
|
-
credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa.slice(0, 6)
|
|
964
|
-
credit_card.cardholder_name.should == "New Joe Cardholder"
|
|
965
|
-
|
|
966
|
-
credit_card.billing_address.first_name.should == "Joe"
|
|
967
|
-
credit_card.billing_address.last_name.should == "Cool"
|
|
968
|
-
credit_card.billing_address.postal_code.should == "60666"
|
|
969
|
-
end
|
|
970
|
-
|
|
971
|
-
it "can pass any attribute through tr_data" do
|
|
972
|
-
original_customer = Braintree::Customer.create!(
|
|
973
|
-
:first_name => "Old First",
|
|
974
|
-
:last_name => "Old Last",
|
|
975
|
-
:company => "Old Company",
|
|
976
|
-
:email => "old@email.com",
|
|
977
|
-
:phone => "000.111.2222",
|
|
978
|
-
:fax => "000.222.3333",
|
|
979
|
-
:website => "old.website.com"
|
|
980
|
-
)
|
|
981
|
-
new_customer_id = "customer_#{rand(1_000_000)}"
|
|
982
|
-
tr_data_params = {
|
|
983
|
-
:customer_id => original_customer.id,
|
|
984
|
-
:customer => {
|
|
985
|
-
:id => new_customer_id,
|
|
986
|
-
:first_name => "New First",
|
|
987
|
-
:last_name => "New Last",
|
|
988
|
-
:company => "New Company",
|
|
989
|
-
:email => "new@email.com",
|
|
990
|
-
:phone => "888.111.2222",
|
|
991
|
-
:fax => "999.222.3333",
|
|
992
|
-
:website => "new.website.com"
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
|
997
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
|
|
998
|
-
result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
|
|
999
|
-
|
|
1000
|
-
result.success?.should == true
|
|
1001
|
-
customer = result.customer
|
|
1002
|
-
customer.id.should == new_customer_id
|
|
1003
|
-
customer.first_name.should == "New First"
|
|
1004
|
-
customer.last_name.should == "New Last"
|
|
1005
|
-
customer.company.should == "New Company"
|
|
1006
|
-
customer.email.should == "new@email.com"
|
|
1007
|
-
customer.phone.should == "888.111.2222"
|
|
1008
|
-
customer.fax.should == "999.222.3333"
|
|
1009
|
-
customer.website.should == "new.website.com"
|
|
1908
|
+
result = Braintree::Customer.update(
|
|
1909
|
+
customer.id,
|
|
1910
|
+
:payment_method_nonce => nonce,
|
|
1911
|
+
)
|
|
1912
|
+
|
|
1913
|
+
expect(result).not_to be_success
|
|
1914
|
+
expect(customer.default_payment_method.token).to eq(credit_card_token)
|
|
1915
|
+
end
|
|
1010
1916
|
end
|
|
1011
1917
|
end
|
|
1918
|
+
|
|
1919
|
+
it "returns prepaid_reloadable from VisaCheckoutCard" do
|
|
1920
|
+
result = Braintree::Customer.create(
|
|
1921
|
+
:payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutVisa,
|
|
1922
|
+
)
|
|
1923
|
+
expect(result.success?).to eq(true)
|
|
1924
|
+
|
|
1925
|
+
found_customer = Braintree::Customer.find(result.customer.id)
|
|
1926
|
+
expect(found_customer.visa_checkout_cards).not_to be_nil
|
|
1927
|
+
visa_checkout_card = found_customer.visa_checkout_cards.first
|
|
1928
|
+
expect(visa_checkout_card).to be_a Braintree::VisaCheckoutCard
|
|
1929
|
+
expect(visa_checkout_card.prepaid_reloadable).not_to be_nil
|
|
1930
|
+
end
|
|
1012
1931
|
end
|