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
|
@@ -0,0 +1,2146 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
|
|
3
|
+
|
|
4
|
+
def make_token
|
|
5
|
+
SecureRandom.uuid
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe Braintree::PaymentMethod do
|
|
9
|
+
describe "self.create" do
|
|
10
|
+
it "creates a payment method from a vaulted credit card nonce" do
|
|
11
|
+
config = Braintree::Configuration.instantiate
|
|
12
|
+
customer = Braintree::Customer.create.customer
|
|
13
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
|
14
|
+
client_token = decode_client_token(raw_client_token)
|
|
15
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
|
16
|
+
http = ClientApiHttp.new(
|
|
17
|
+
config,
|
|
18
|
+
:authorization_fingerprint => authorization_fingerprint,
|
|
19
|
+
:shared_customer_identifier => "fake_identifier",
|
|
20
|
+
:shared_customer_identifier_type => "testing",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
response = http.create_credit_card(
|
|
24
|
+
:number => 4111111111111111,
|
|
25
|
+
:expirationMonth => 12,
|
|
26
|
+
:expirationYear => 2020,
|
|
27
|
+
)
|
|
28
|
+
expect(response.code).to eq("201")
|
|
29
|
+
|
|
30
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
|
31
|
+
result = Braintree::PaymentMethod.create(
|
|
32
|
+
:payment_method_nonce => nonce,
|
|
33
|
+
:customer_id => customer.id,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
expect(result).to be_success
|
|
37
|
+
expect(result.payment_method).to be_a(Braintree::CreditCard)
|
|
38
|
+
token = result.payment_method.token
|
|
39
|
+
|
|
40
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
|
41
|
+
expect(found_credit_card).not_to be_nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "creates a payment method from an unvalidated credit card nonce" do
|
|
45
|
+
config = Braintree::Configuration.instantiate
|
|
46
|
+
customer = Braintree::Customer.create.customer
|
|
47
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
|
48
|
+
client_token = decode_client_token(raw_client_token)
|
|
49
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
|
50
|
+
http = ClientApiHttp.new(
|
|
51
|
+
config,
|
|
52
|
+
:authorization_fingerprint => authorization_fingerprint,
|
|
53
|
+
:shared_customer_identifier => "fake_identifier",
|
|
54
|
+
:shared_customer_identifier_type => "testing",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
response = http.create_credit_card(
|
|
58
|
+
:number => "4111111111111111",
|
|
59
|
+
:expirationMonth => "12",
|
|
60
|
+
:expirationYear => "2020",
|
|
61
|
+
:options => {:validate => false},
|
|
62
|
+
)
|
|
63
|
+
expect(response.code).to eq("202")
|
|
64
|
+
|
|
65
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
|
66
|
+
result = Braintree::PaymentMethod.create(
|
|
67
|
+
:payment_method_nonce => nonce,
|
|
68
|
+
:customer_id => customer.id,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
expect(result).to be_success
|
|
72
|
+
expect(result.payment_method).to be_a(Braintree::CreditCard)
|
|
73
|
+
token = result.payment_method.token
|
|
74
|
+
|
|
75
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
|
76
|
+
expect(found_credit_card).not_to be_nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "creates a payment method from a fake apple pay nonce" do
|
|
80
|
+
customer = Braintree::Customer.create.customer
|
|
81
|
+
token = SecureRandom.hex(16)
|
|
82
|
+
result = Braintree::PaymentMethod.create(
|
|
83
|
+
:payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
|
|
84
|
+
:customer_id => customer.id,
|
|
85
|
+
:token => token,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
expect(result).to be_success
|
|
89
|
+
apple_pay_card = result.payment_method
|
|
90
|
+
expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
|
|
91
|
+
expect(apple_pay_card).not_to be_nil
|
|
92
|
+
expect(apple_pay_card.bin).not_to be_nil
|
|
93
|
+
expect(apple_pay_card.token).to eq(token)
|
|
94
|
+
expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::AmEx)
|
|
95
|
+
expect(apple_pay_card.payment_instrument_name).to eq("AmEx 41002")
|
|
96
|
+
expect(apple_pay_card.source_description).to eq("AmEx 41002")
|
|
97
|
+
expect(apple_pay_card.default).to eq(true)
|
|
98
|
+
expect(apple_pay_card.image_url).to match(/apple_pay/)
|
|
99
|
+
expect(apple_pay_card.expiration_month.to_i).to be > 0
|
|
100
|
+
expect(apple_pay_card.expiration_year.to_i).to be > 0
|
|
101
|
+
expect(apple_pay_card.customer_id).to eq(customer.id)
|
|
102
|
+
expect(apple_pay_card.commercial).not_to be_nil
|
|
103
|
+
expect(apple_pay_card.country_of_issuance).not_to be_nil
|
|
104
|
+
expect(apple_pay_card.debit).not_to be_nil
|
|
105
|
+
expect(apple_pay_card.durbin_regulated).not_to be_nil
|
|
106
|
+
expect(apple_pay_card.healthcare).not_to be_nil
|
|
107
|
+
expect(apple_pay_card.issuing_bank).not_to be_nil
|
|
108
|
+
expect(apple_pay_card.payroll).not_to be_nil
|
|
109
|
+
expect(apple_pay_card.prepaid).not_to be_nil
|
|
110
|
+
expect(apple_pay_card.product_id).not_to be_nil
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "creates a payment method from a fake apple pay mpan nonce" do
|
|
114
|
+
customer = Braintree::Customer.create.customer
|
|
115
|
+
token = SecureRandom.hex(16)
|
|
116
|
+
result = Braintree::PaymentMethod.create(
|
|
117
|
+
:payment_method_nonce => Braintree::Test::Nonce::ApplePayMpan,
|
|
118
|
+
:customer_id => customer.id,
|
|
119
|
+
:token => token,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
expect(result).to be_success
|
|
123
|
+
apple_pay_card = result.payment_method
|
|
124
|
+
expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
|
|
125
|
+
expect(apple_pay_card).not_to be_nil
|
|
126
|
+
expect(apple_pay_card.bin).not_to be_nil
|
|
127
|
+
expect(apple_pay_card.token).to eq(token)
|
|
128
|
+
expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::Visa)
|
|
129
|
+
expect(apple_pay_card.payment_instrument_name).to eq("Visa 8886")
|
|
130
|
+
expect(apple_pay_card.source_description).to eq("Visa 8886")
|
|
131
|
+
expect(apple_pay_card.default).to eq(true)
|
|
132
|
+
expect(apple_pay_card.image_url).to match(/apple_pay/)
|
|
133
|
+
expect(apple_pay_card.expiration_month.to_i).to be > 0
|
|
134
|
+
expect(apple_pay_card.expiration_year.to_i).to be > 0
|
|
135
|
+
expect(apple_pay_card.customer_id).to eq(customer.id)
|
|
136
|
+
expect(apple_pay_card.commercial).not_to be_nil
|
|
137
|
+
expect(apple_pay_card.country_of_issuance).not_to be_nil
|
|
138
|
+
expect(apple_pay_card.debit).not_to be_nil
|
|
139
|
+
expect(apple_pay_card.durbin_regulated).not_to be_nil
|
|
140
|
+
expect(apple_pay_card.healthcare).not_to be_nil
|
|
141
|
+
expect(apple_pay_card.issuing_bank).not_to be_nil
|
|
142
|
+
expect(apple_pay_card.payroll).not_to be_nil
|
|
143
|
+
expect(apple_pay_card.prepaid).not_to be_nil
|
|
144
|
+
expect(apple_pay_card.product_id).not_to be_nil
|
|
145
|
+
expect(apple_pay_card.merchant_token_identifier).not_to be_nil
|
|
146
|
+
expect(apple_pay_card.source_card_last4).not_to be_nil
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "creates a payment method from a fake google pay proxy card nonce" do
|
|
150
|
+
customer = Braintree::Customer.create.customer
|
|
151
|
+
token = SecureRandom.hex(16)
|
|
152
|
+
result = Braintree::PaymentMethod.create(
|
|
153
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
|
154
|
+
:customer_id => customer.id,
|
|
155
|
+
:token => token,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
expect(result).to be_success
|
|
159
|
+
google_pay_card = result.payment_method
|
|
160
|
+
expect(google_pay_card).to be_a(Braintree::GooglePayCard)
|
|
161
|
+
expect(google_pay_card).not_to be_nil
|
|
162
|
+
expect(google_pay_card.token).to eq(token)
|
|
163
|
+
expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::Discover)
|
|
164
|
+
expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::Discover)
|
|
165
|
+
expect(google_pay_card.expiration_month.to_i).to be > 0
|
|
166
|
+
expect(google_pay_card.expiration_year.to_i).to be > 0
|
|
167
|
+
expect(google_pay_card.default).to eq(true)
|
|
168
|
+
expect(google_pay_card.image_url).to match(/android_pay/)
|
|
169
|
+
expect(google_pay_card.is_network_tokenized?).to eq(false)
|
|
170
|
+
expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::Discover)
|
|
171
|
+
expect(google_pay_card.source_card_last_4).to eq("1111")
|
|
172
|
+
expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
|
|
173
|
+
expect(google_pay_card.source_description).to eq("Discover 1111")
|
|
174
|
+
expect(google_pay_card.customer_id).to eq(customer.id)
|
|
175
|
+
expect(google_pay_card.commercial).not_to be_nil
|
|
176
|
+
expect(google_pay_card.country_of_issuance).not_to be_nil
|
|
177
|
+
expect(google_pay_card.debit).not_to be_nil
|
|
178
|
+
expect(google_pay_card.durbin_regulated).not_to be_nil
|
|
179
|
+
expect(google_pay_card.healthcare).not_to be_nil
|
|
180
|
+
expect(google_pay_card.issuing_bank).not_to be_nil
|
|
181
|
+
expect(google_pay_card.payroll).not_to be_nil
|
|
182
|
+
expect(google_pay_card.prepaid).not_to be_nil
|
|
183
|
+
expect(google_pay_card.product_id).not_to be_nil
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "creates a payment method from a google pay network token nonce" do
|
|
187
|
+
customer = Braintree::Customer.create.customer
|
|
188
|
+
token = SecureRandom.hex(16)
|
|
189
|
+
result = Braintree::PaymentMethod.create(
|
|
190
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
|
|
191
|
+
:customer_id => customer.id,
|
|
192
|
+
:token => token,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
expect(result).to be_success
|
|
196
|
+
google_pay_card = result.payment_method
|
|
197
|
+
expect(google_pay_card).to be_a(Braintree::GooglePayCard)
|
|
198
|
+
expect(google_pay_card).not_to be_nil
|
|
199
|
+
expect(google_pay_card.token).to eq(token)
|
|
200
|
+
expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
|
|
201
|
+
expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
|
|
202
|
+
expect(google_pay_card.expiration_month.to_i).to be > 0
|
|
203
|
+
expect(google_pay_card.expiration_year.to_i).to be > 0
|
|
204
|
+
expect(google_pay_card.default).to eq(true)
|
|
205
|
+
expect(google_pay_card.image_url).to match(/android_pay/)
|
|
206
|
+
expect(google_pay_card.is_network_tokenized?).to eq(true)
|
|
207
|
+
expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
|
|
208
|
+
expect(google_pay_card.source_card_last_4).to eq("4444")
|
|
209
|
+
expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
|
|
210
|
+
expect(google_pay_card.source_description).to eq("MasterCard 4444")
|
|
211
|
+
expect(google_pay_card.customer_id).to eq(customer.id)
|
|
212
|
+
expect(google_pay_card.commercial).not_to be_nil
|
|
213
|
+
expect(google_pay_card.country_of_issuance).not_to be_nil
|
|
214
|
+
expect(google_pay_card.debit).not_to be_nil
|
|
215
|
+
expect(google_pay_card.durbin_regulated).not_to be_nil
|
|
216
|
+
expect(google_pay_card.healthcare).not_to be_nil
|
|
217
|
+
expect(google_pay_card.issuing_bank).not_to be_nil
|
|
218
|
+
expect(google_pay_card.payroll).not_to be_nil
|
|
219
|
+
expect(google_pay_card.prepaid).not_to be_nil
|
|
220
|
+
expect(google_pay_card.product_id).not_to be_nil
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it "creates a payment method from venmo account nonce" do
|
|
224
|
+
customer = Braintree::Customer.create.customer
|
|
225
|
+
token = SecureRandom.hex(16)
|
|
226
|
+
result = Braintree::PaymentMethod.create(
|
|
227
|
+
:payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
|
|
228
|
+
:customer_id => customer.id,
|
|
229
|
+
:token => token,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
expect(result).to be_success
|
|
233
|
+
venmo_account = result.payment_method
|
|
234
|
+
expect(venmo_account).to be_a(Braintree::VenmoAccount)
|
|
235
|
+
|
|
236
|
+
expect(venmo_account.default).to eq(true)
|
|
237
|
+
expect(venmo_account.token).to eq(token)
|
|
238
|
+
expect(venmo_account.username).to eq("venmojoe")
|
|
239
|
+
expect(venmo_account.venmo_user_id).to eq("1234567891234567891")
|
|
240
|
+
expect(venmo_account.image_url).to include(".png")
|
|
241
|
+
expect(venmo_account.source_description).to eq("Venmo Account: venmojoe")
|
|
242
|
+
expect(venmo_account.customer_id).to eq(customer.id)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "allows passing the make_default option alongside the nonce" do
|
|
246
|
+
customer = Braintree::Customer.create!
|
|
247
|
+
result = Braintree::CreditCard.create(
|
|
248
|
+
:customer_id => customer.id,
|
|
249
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
250
|
+
:expiration_date => "05/2009",
|
|
251
|
+
:cvv => "100",
|
|
252
|
+
)
|
|
253
|
+
expect(result.success?).to eq(true)
|
|
254
|
+
original_payment_method = result.credit_card
|
|
255
|
+
expect(original_payment_method).to be_default
|
|
256
|
+
|
|
257
|
+
nonce = nonce_for_paypal_account(:consent_code => "PAYPAL_CONSENT_CODE")
|
|
258
|
+
result = Braintree::PaymentMethod.create(
|
|
259
|
+
:payment_method_nonce => nonce,
|
|
260
|
+
:customer_id => customer.id,
|
|
261
|
+
:options => {:make_default => true},
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
expect(result).to be_success
|
|
265
|
+
new_payment_method = result.payment_method
|
|
266
|
+
expect(new_payment_method).to be_default
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
it "overrides the token in the nonce" do
|
|
270
|
+
customer = Braintree::Customer.create!
|
|
271
|
+
|
|
272
|
+
first_token = make_token
|
|
273
|
+
second_token = make_token
|
|
274
|
+
nonce = nonce_for_paypal_account(
|
|
275
|
+
:consent_code => "PAYPAL_CONSENT_CODE",
|
|
276
|
+
:token => first_token,
|
|
277
|
+
)
|
|
278
|
+
result = Braintree::PaymentMethod.create(
|
|
279
|
+
:payment_method_nonce => nonce,
|
|
280
|
+
:customer_id => customer.id,
|
|
281
|
+
:token => second_token,
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
expect(result).to be_success
|
|
285
|
+
payment_method = result.payment_method
|
|
286
|
+
expect(payment_method.token).to eq(second_token)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it "respects verify_card and verification_merchant_account_id when included outside of the nonce" do
|
|
290
|
+
nonce = nonce_for_new_payment_method(
|
|
291
|
+
:credit_card => {
|
|
292
|
+
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
|
|
293
|
+
:expiration_month => "11",
|
|
294
|
+
:expiration_year => "2099",
|
|
295
|
+
},
|
|
296
|
+
)
|
|
297
|
+
customer = Braintree::Customer.create!
|
|
298
|
+
result = Braintree::PaymentMethod.create(
|
|
299
|
+
:payment_method_nonce => nonce,
|
|
300
|
+
:customer_id => customer.id,
|
|
301
|
+
:options => {
|
|
302
|
+
:verify_card => true,
|
|
303
|
+
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
|
|
304
|
+
},
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
expect(result).not_to be_success
|
|
308
|
+
expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
|
309
|
+
expect(result.credit_card_verification.processor_response_code).to eq("2000")
|
|
310
|
+
expect(result.credit_card_verification.processor_response_text).to eq("Do Not Honor")
|
|
311
|
+
expect(result.credit_card_verification.merchant_account_id).to eq(SpecHelper::NonDefaultMerchantAccountId)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
it "respects verification amount when included outside of the nonce" do
|
|
315
|
+
nonce = nonce_for_new_payment_method(
|
|
316
|
+
:credit_card => {
|
|
317
|
+
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
|
|
318
|
+
:expiration_month => "11",
|
|
319
|
+
:expiration_year => "2099",
|
|
320
|
+
},
|
|
321
|
+
)
|
|
322
|
+
customer = Braintree::Customer.create!
|
|
323
|
+
result = Braintree::PaymentMethod.create(
|
|
324
|
+
:payment_method_nonce => nonce,
|
|
325
|
+
:customer_id => customer.id,
|
|
326
|
+
:options => {
|
|
327
|
+
:verify_card => true,
|
|
328
|
+
:verification_amount => "100.00"
|
|
329
|
+
},
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
expect(result).not_to be_success
|
|
333
|
+
expect(result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
|
334
|
+
expect(result.credit_card_verification.processor_response_code).to eq("2000")
|
|
335
|
+
expect(result.credit_card_verification.processor_response_text).to eq("Do Not Honor")
|
|
336
|
+
expect(result.credit_card_verification.amount).to eq(BigDecimal("100.00"))
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
it "validates presence of three_d_secure_version in 3ds pass thru params" do
|
|
340
|
+
customer = Braintree::Customer.create!
|
|
341
|
+
result = Braintree::PaymentMethod.create(
|
|
342
|
+
:customer_id => customer.id,
|
|
343
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
|
344
|
+
:three_d_secure_pass_thru => {
|
|
345
|
+
:eci_flag => "05",
|
|
346
|
+
:cavv => "some_cavv",
|
|
347
|
+
:xid => "some_xid",
|
|
348
|
+
:three_d_secure_version => "xx",
|
|
349
|
+
:authentication_response => "Y",
|
|
350
|
+
:directory_response => "Y",
|
|
351
|
+
:cavv_algorithm => "2",
|
|
352
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
353
|
+
},
|
|
354
|
+
:options => {:verify_card => true},
|
|
355
|
+
)
|
|
356
|
+
expect(result).not_to be_success
|
|
357
|
+
error = result.errors.for(:verification).first
|
|
358
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
|
|
359
|
+
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`).")
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
it "accepts three_d_secure pass thru params in the request" do
|
|
363
|
+
customer = Braintree::Customer.create!
|
|
364
|
+
result = Braintree::PaymentMethod.create(
|
|
365
|
+
:customer_id => customer.id,
|
|
366
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
|
367
|
+
:three_d_secure_pass_thru => {
|
|
368
|
+
:eci_flag => "05",
|
|
369
|
+
:cavv => "some_cavv",
|
|
370
|
+
:xid => "some_xid",
|
|
371
|
+
:three_d_secure_version => "1.0.2",
|
|
372
|
+
:authentication_response => "Y",
|
|
373
|
+
:directory_response => "Y",
|
|
374
|
+
:cavv_algorithm => "2",
|
|
375
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
376
|
+
},
|
|
377
|
+
:options => {:verify_card => true},
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
expect(result).to be_success
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
it "returns 3DS info on cc verification" do
|
|
384
|
+
customer = Braintree::Customer.create.customer
|
|
385
|
+
result = Braintree::PaymentMethod.create(
|
|
386
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
|
387
|
+
:options => {:verify_card => true},
|
|
388
|
+
:customer_id => customer.id,
|
|
389
|
+
)
|
|
390
|
+
expect(result.success?).to eq(true)
|
|
391
|
+
|
|
392
|
+
three_d_secure_info = result.payment_method.verification.three_d_secure_info
|
|
393
|
+
expect(three_d_secure_info.status).to eq("authenticate_successful")
|
|
394
|
+
expect(three_d_secure_info).to be_liability_shifted
|
|
395
|
+
expect(three_d_secure_info).to be_liability_shift_possible
|
|
396
|
+
expect(three_d_secure_info.enrolled).to be_a(String)
|
|
397
|
+
expect(three_d_secure_info.cavv).to be_a(String)
|
|
398
|
+
expect(three_d_secure_info.xid).to be_a(String)
|
|
399
|
+
expect(three_d_secure_info.eci_flag).to be_a(String)
|
|
400
|
+
expect(three_d_secure_info.three_d_secure_version).to be_a(String)
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
it "respects fail_on_duplicate_payment_method when included outside of the nonce" do
|
|
404
|
+
customer = Braintree::Customer.create!
|
|
405
|
+
result = Braintree::CreditCard.create(
|
|
406
|
+
:customer_id => customer.id,
|
|
407
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
408
|
+
:expiration_date => "05/2012",
|
|
409
|
+
)
|
|
410
|
+
expect(result).to be_success
|
|
411
|
+
|
|
412
|
+
nonce = nonce_for_new_payment_method(
|
|
413
|
+
:credit_card => {
|
|
414
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
415
|
+
:expiration_date => "05/2012"
|
|
416
|
+
},
|
|
417
|
+
)
|
|
418
|
+
result = Braintree::PaymentMethod.create(
|
|
419
|
+
:payment_method_nonce => nonce,
|
|
420
|
+
:customer_id => customer.id,
|
|
421
|
+
:options => {
|
|
422
|
+
:fail_on_duplicate_payment_method => true
|
|
423
|
+
},
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
expect(result).not_to be_success
|
|
427
|
+
expect(result.errors.first.code).to eq("81724")
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
it "respects fail_on_duplicate_payment_method_for_customer when included outside of the nonce" do
|
|
431
|
+
customer = Braintree::Customer.create!
|
|
432
|
+
result = Braintree::CreditCard.create(
|
|
433
|
+
:customer_id => customer.id,
|
|
434
|
+
:number => 4111111111111111,
|
|
435
|
+
:expiration_date => "05/2012",
|
|
436
|
+
)
|
|
437
|
+
expect(result).to be_success
|
|
438
|
+
|
|
439
|
+
nonce = nonce_for_new_payment_method(
|
|
440
|
+
:credit_card => {
|
|
441
|
+
:number => 4111111111111111,
|
|
442
|
+
:expiration_date => "05/2012"
|
|
443
|
+
},
|
|
444
|
+
)
|
|
445
|
+
result = Braintree::PaymentMethod.create(
|
|
446
|
+
:payment_method_nonce => nonce,
|
|
447
|
+
:customer_id => customer.id,
|
|
448
|
+
:options => {
|
|
449
|
+
:fail_on_duplicate_payment_method_for_customer => true
|
|
450
|
+
},
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
expect(result).not_to be_success
|
|
454
|
+
expect(result.errors.first.code).to eq("81763")
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
it "allows passing the billing address outside of the nonce" do
|
|
458
|
+
config = Braintree::Configuration.instantiate
|
|
459
|
+
customer = Braintree::Customer.create.customer
|
|
460
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
|
461
|
+
client_token = decode_client_token(raw_client_token)
|
|
462
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
|
463
|
+
http = ClientApiHttp.new(
|
|
464
|
+
config,
|
|
465
|
+
:authorization_fingerprint => authorization_fingerprint,
|
|
466
|
+
:shared_customer_identifier => "fake_identifier",
|
|
467
|
+
:shared_customer_identifier_type => "testing",
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
response = http.create_credit_card(
|
|
471
|
+
:number => "4111111111111111",
|
|
472
|
+
:expirationMonth => "12",
|
|
473
|
+
:expirationYear => "2020",
|
|
474
|
+
:options => {:validate => false},
|
|
475
|
+
)
|
|
476
|
+
expect(response.code).to eq("202")
|
|
477
|
+
|
|
478
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
|
479
|
+
result = Braintree::PaymentMethod.create(
|
|
480
|
+
:payment_method_nonce => nonce,
|
|
481
|
+
:customer_id => customer.id,
|
|
482
|
+
:billing_address => {
|
|
483
|
+
:street_address => "123 Abc Way",
|
|
484
|
+
:international_phone => {:country_code => "1", :national_number => "3121234567"},
|
|
485
|
+
},
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
expect(result).to be_success
|
|
489
|
+
expect(result.payment_method).to be_a(Braintree::CreditCard)
|
|
490
|
+
token = result.payment_method.token
|
|
491
|
+
|
|
492
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
|
493
|
+
expect(found_credit_card).not_to be_nil
|
|
494
|
+
expect(found_credit_card.billing_address.street_address).to eq("123 Abc Way")
|
|
495
|
+
expect(found_credit_card.billing_address.international_phone[:country_code]).to eq("1")
|
|
496
|
+
expect(found_credit_card.billing_address.international_phone[:national_number]).to eq("3121234567")
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
it "allows passing a billing address id outside of the nonce" do
|
|
500
|
+
config = Braintree::Configuration.instantiate
|
|
501
|
+
customer = Braintree::Customer.create.customer
|
|
502
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
|
503
|
+
client_token = decode_client_token(raw_client_token)
|
|
504
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
|
505
|
+
http = ClientApiHttp.new(
|
|
506
|
+
config,
|
|
507
|
+
:authorization_fingerprint => authorization_fingerprint,
|
|
508
|
+
:shared_customer_identifier => "fake_identifier",
|
|
509
|
+
:shared_customer_identifier_type => "testing",
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
response = http.create_credit_card(
|
|
513
|
+
:number => "4111111111111111",
|
|
514
|
+
:expirationMonth => "12",
|
|
515
|
+
:expirationYear => "2020",
|
|
516
|
+
:options => {:validate => false},
|
|
517
|
+
)
|
|
518
|
+
expect(response.code).to eq("202")
|
|
519
|
+
|
|
520
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
|
521
|
+
|
|
522
|
+
address = Braintree::Address.create!(:customer_id => customer.id, :first_name => "Bobby", :last_name => "Tables")
|
|
523
|
+
result = Braintree::PaymentMethod.create(
|
|
524
|
+
:payment_method_nonce => nonce,
|
|
525
|
+
:customer_id => customer.id,
|
|
526
|
+
:billing_address_id => address.id,
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
expect(result).to be_success
|
|
530
|
+
expect(result.payment_method).to be_a(Braintree::CreditCard)
|
|
531
|
+
token = result.payment_method.token
|
|
532
|
+
|
|
533
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
|
534
|
+
expect(found_credit_card).not_to be_nil
|
|
535
|
+
expect(found_credit_card.billing_address.first_name).to eq("Bobby")
|
|
536
|
+
expect(found_credit_card.billing_address.last_name).to eq("Tables")
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
it "overrides the billing address in the nonce" do
|
|
540
|
+
config = Braintree::Configuration.instantiate
|
|
541
|
+
customer = Braintree::Customer.create.customer
|
|
542
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
|
543
|
+
client_token = decode_client_token(raw_client_token)
|
|
544
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
|
545
|
+
http = ClientApiHttp.new(
|
|
546
|
+
config,
|
|
547
|
+
:authorization_fingerprint => authorization_fingerprint,
|
|
548
|
+
:shared_customer_identifier => "fake_identifier",
|
|
549
|
+
:shared_customer_identifier_type => "testing",
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
response = http.create_credit_card(
|
|
553
|
+
:number => "4111111111111111",
|
|
554
|
+
:expirationMonth => "12",
|
|
555
|
+
:expirationYear => "2020",
|
|
556
|
+
:options => {:validate => false},
|
|
557
|
+
:billing_address => {
|
|
558
|
+
:street_address => "456 Xyz Way"
|
|
559
|
+
},
|
|
560
|
+
)
|
|
561
|
+
expect(response.code).to eq("202")
|
|
562
|
+
|
|
563
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
|
564
|
+
result = Braintree::PaymentMethod.create(
|
|
565
|
+
:payment_method_nonce => nonce,
|
|
566
|
+
:customer_id => customer.id,
|
|
567
|
+
:billing_address => {
|
|
568
|
+
:street_address => "123 Abc Way"
|
|
569
|
+
},
|
|
570
|
+
)
|
|
571
|
+
|
|
572
|
+
expect(result).to be_success
|
|
573
|
+
expect(result.payment_method).to be_a(Braintree::CreditCard)
|
|
574
|
+
token = result.payment_method.token
|
|
575
|
+
|
|
576
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
|
577
|
+
expect(found_credit_card).not_to be_nil
|
|
578
|
+
expect(found_credit_card.billing_address.street_address).to eq("123 Abc Way")
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
it "does not override the billing address for a vaulted credit card" do
|
|
582
|
+
config = Braintree::Configuration.instantiate
|
|
583
|
+
customer = Braintree::Customer.create.customer
|
|
584
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
|
585
|
+
client_token = decode_client_token(raw_client_token)
|
|
586
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
|
587
|
+
http = ClientApiHttp.new(
|
|
588
|
+
config,
|
|
589
|
+
:authorization_fingerprint => authorization_fingerprint,
|
|
590
|
+
:shared_customer_identifier => "fake_identifier",
|
|
591
|
+
:shared_customer_identifier_type => "testing",
|
|
592
|
+
)
|
|
593
|
+
|
|
594
|
+
response = http.create_credit_card(
|
|
595
|
+
:number => 4111111111111111,
|
|
596
|
+
:expirationMonth => 12,
|
|
597
|
+
:expirationYear => 2020,
|
|
598
|
+
:billing_address => {
|
|
599
|
+
:street_address => "456 Xyz Way"
|
|
600
|
+
},
|
|
601
|
+
)
|
|
602
|
+
expect(response.code).to eq("201")
|
|
603
|
+
|
|
604
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
|
605
|
+
result = Braintree::PaymentMethod.create(
|
|
606
|
+
:payment_method_nonce => nonce,
|
|
607
|
+
:customer_id => customer.id,
|
|
608
|
+
:billing_address => {
|
|
609
|
+
:street_address => "123 Abc Way"
|
|
610
|
+
},
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
expect(result).to be_success
|
|
614
|
+
expect(result.payment_method).to be_a(Braintree::CreditCard)
|
|
615
|
+
token = result.payment_method.token
|
|
616
|
+
|
|
617
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
|
618
|
+
expect(found_credit_card).not_to be_nil
|
|
619
|
+
expect(found_credit_card.billing_address.street_address).to eq("456 Xyz Way")
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
it "includes risk data when skip_advanced_fraud_checking is false" do
|
|
623
|
+
with_fraud_protection_enterprise_merchant do
|
|
624
|
+
customer = Braintree::Customer.create!
|
|
625
|
+
|
|
626
|
+
nonce = nonce_for_new_payment_method(
|
|
627
|
+
:credit_card => {
|
|
628
|
+
:cvv => "123",
|
|
629
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
630
|
+
:expiration_date => "05/2009",
|
|
631
|
+
},
|
|
632
|
+
)
|
|
633
|
+
result = Braintree::PaymentMethod.create(
|
|
634
|
+
:payment_method_nonce => nonce,
|
|
635
|
+
:customer_id => customer.id,
|
|
636
|
+
:options => {
|
|
637
|
+
:verify_card => true,
|
|
638
|
+
:skip_advanced_fraud_checking => false,
|
|
639
|
+
},
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
expect(result).to be_success
|
|
643
|
+
verification = result.payment_method.verification
|
|
644
|
+
expect(verification.risk_data).not_to be_nil
|
|
645
|
+
end
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
it "does not include risk data when skip_advanced_fraud_checking is true" do
|
|
649
|
+
with_fraud_protection_enterprise_merchant do
|
|
650
|
+
customer = Braintree::Customer.create!
|
|
651
|
+
|
|
652
|
+
nonce = nonce_for_new_payment_method(
|
|
653
|
+
:credit_card => {
|
|
654
|
+
:cvv => "123",
|
|
655
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
656
|
+
:expiration_date => "05/2009",
|
|
657
|
+
},
|
|
658
|
+
)
|
|
659
|
+
result = Braintree::PaymentMethod.create(
|
|
660
|
+
:payment_method_nonce => nonce,
|
|
661
|
+
:customer_id => customer.id,
|
|
662
|
+
:options => {
|
|
663
|
+
:verify_card => true,
|
|
664
|
+
:skip_advanced_fraud_checking => true,
|
|
665
|
+
},
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
expect(result).to be_success
|
|
669
|
+
verification = result.payment_method.verification
|
|
670
|
+
expect(verification.risk_data).to be_nil
|
|
671
|
+
end
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
context "account_type" do
|
|
675
|
+
it "verifies card with account_type debit" do
|
|
676
|
+
nonce = nonce_for_new_payment_method(
|
|
677
|
+
:credit_card => {
|
|
678
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
679
|
+
:expiration_month => "11",
|
|
680
|
+
:expiration_year => "2099",
|
|
681
|
+
},
|
|
682
|
+
)
|
|
683
|
+
customer = Braintree::Customer.create!
|
|
684
|
+
result = Braintree::PaymentMethod.create(
|
|
685
|
+
:payment_method_nonce => nonce,
|
|
686
|
+
:customer_id => customer.id,
|
|
687
|
+
:options => {
|
|
688
|
+
:verify_card => true,
|
|
689
|
+
:verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
|
|
690
|
+
:verification_account_type => "debit",
|
|
691
|
+
},
|
|
692
|
+
)
|
|
693
|
+
|
|
694
|
+
expect(result).to be_success
|
|
695
|
+
expect(result.payment_method.verification.credit_card[:account_type]).to eq("debit")
|
|
696
|
+
end
|
|
697
|
+
|
|
698
|
+
it "verifies card with account_type credit" do
|
|
699
|
+
nonce = nonce_for_new_payment_method(
|
|
700
|
+
:credit_card => {
|
|
701
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
702
|
+
:expiration_month => "11",
|
|
703
|
+
:expiration_year => "2099",
|
|
704
|
+
},
|
|
705
|
+
)
|
|
706
|
+
customer = Braintree::Customer.create!
|
|
707
|
+
result = Braintree::PaymentMethod.create(
|
|
708
|
+
:payment_method_nonce => nonce,
|
|
709
|
+
:customer_id => customer.id,
|
|
710
|
+
:options => {
|
|
711
|
+
:verify_card => true,
|
|
712
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
|
713
|
+
:verification_account_type => "credit",
|
|
714
|
+
},
|
|
715
|
+
)
|
|
716
|
+
|
|
717
|
+
expect(result).to be_success
|
|
718
|
+
expect(result.payment_method.verification.credit_card[:account_type]).to eq("credit")
|
|
719
|
+
end
|
|
720
|
+
|
|
721
|
+
it "errors with invalid account_type" do
|
|
722
|
+
nonce = nonce_for_new_payment_method(
|
|
723
|
+
:credit_card => {
|
|
724
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
725
|
+
:expiration_month => "11",
|
|
726
|
+
:expiration_year => "2099",
|
|
727
|
+
},
|
|
728
|
+
)
|
|
729
|
+
customer = Braintree::Customer.create!
|
|
730
|
+
result = Braintree::PaymentMethod.create(
|
|
731
|
+
:payment_method_nonce => nonce,
|
|
732
|
+
:customer_id => customer.id,
|
|
733
|
+
:options => {
|
|
734
|
+
:verify_card => true,
|
|
735
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
|
736
|
+
:verification_account_type => "ach",
|
|
737
|
+
},
|
|
738
|
+
)
|
|
739
|
+
|
|
740
|
+
expect(result).not_to be_success
|
|
741
|
+
expect(result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq(Braintree::ErrorCodes::CreditCard::VerificationAccountTypeIsInvalid)
|
|
742
|
+
end
|
|
743
|
+
|
|
744
|
+
it "errors when account_type not supported by merchant" do
|
|
745
|
+
nonce = nonce_for_new_payment_method(
|
|
746
|
+
:credit_card => {
|
|
747
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
748
|
+
:expiration_month => "11",
|
|
749
|
+
:expiration_year => "2099",
|
|
750
|
+
},
|
|
751
|
+
)
|
|
752
|
+
customer = Braintree::Customer.create!
|
|
753
|
+
result = Braintree::PaymentMethod.create(
|
|
754
|
+
:payment_method_nonce => nonce,
|
|
755
|
+
:customer_id => customer.id,
|
|
756
|
+
:options => {
|
|
757
|
+
:verify_card => true,
|
|
758
|
+
:verification_account_type => "credit",
|
|
759
|
+
},
|
|
760
|
+
)
|
|
761
|
+
|
|
762
|
+
expect(result).not_to be_success
|
|
763
|
+
expect(result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code).to eq(Braintree::ErrorCodes::CreditCard::VerificationAccountTypeNotSupported)
|
|
764
|
+
end
|
|
765
|
+
|
|
766
|
+
it "updates the credit card with account_type credit" do
|
|
767
|
+
customer = Braintree::Customer.create!
|
|
768
|
+
credit_card = Braintree::CreditCard.create!(
|
|
769
|
+
:cardholder_name => "Original Holder",
|
|
770
|
+
:customer_id => customer.id,
|
|
771
|
+
:cvv => "123",
|
|
772
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
773
|
+
:expiration_date => "05/2012",
|
|
774
|
+
)
|
|
775
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
776
|
+
:cardholder_name => "New Holder",
|
|
777
|
+
:cvv => "456",
|
|
778
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
779
|
+
:expiration_date => "06/2013",
|
|
780
|
+
:options => {
|
|
781
|
+
:verify_card => true,
|
|
782
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
|
783
|
+
:verification_account_type => "credit",
|
|
784
|
+
},
|
|
785
|
+
)
|
|
786
|
+
expect(update_result.success?).to eq(true)
|
|
787
|
+
expect(update_result.payment_method.verification.credit_card[:account_type]).to eq("credit")
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
it "updates the credit card with account_type debit" do
|
|
791
|
+
customer = Braintree::Customer.create!
|
|
792
|
+
credit_card = Braintree::CreditCard.create!(
|
|
793
|
+
:cardholder_name => "Original Holder",
|
|
794
|
+
:customer_id => customer.id,
|
|
795
|
+
:cvv => "123",
|
|
796
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
797
|
+
:expiration_date => "05/2012",
|
|
798
|
+
)
|
|
799
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
800
|
+
:cardholder_name => "New Holder",
|
|
801
|
+
:cvv => "456",
|
|
802
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
|
803
|
+
:expiration_date => "06/2013",
|
|
804
|
+
:options => {
|
|
805
|
+
:verify_card => true,
|
|
806
|
+
:verification_merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
|
|
807
|
+
:verification_account_type => "debit",
|
|
808
|
+
},
|
|
809
|
+
)
|
|
810
|
+
expect(update_result.success?).to eq(true)
|
|
811
|
+
expect(update_result.payment_method.verification.credit_card[:account_type]).to eq("debit")
|
|
812
|
+
end
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
context "paypal" do
|
|
816
|
+
it "creates a payment method from an unvalidated future paypal account nonce" do
|
|
817
|
+
nonce = nonce_for_paypal_account(:consent_code => "PAYPAL_CONSENT_CODE")
|
|
818
|
+
customer = Braintree::Customer.create.customer
|
|
819
|
+
result = Braintree::PaymentMethod.create(
|
|
820
|
+
:payment_method_nonce => nonce,
|
|
821
|
+
:customer_id => customer.id,
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
expect(result).to be_success
|
|
825
|
+
expect(result.payment_method).to be_a(Braintree::PayPalAccount)
|
|
826
|
+
expect(result.payment_method.image_url).not_to be_nil
|
|
827
|
+
token = result.payment_method.token
|
|
828
|
+
|
|
829
|
+
found_paypal_account = Braintree::PayPalAccount.find(token)
|
|
830
|
+
expect(found_paypal_account).not_to be_nil
|
|
831
|
+
end
|
|
832
|
+
|
|
833
|
+
it "creates a limited use payment method from a paypal account nonce for a paypal intent==order payment" do
|
|
834
|
+
nonce = nonce_for_paypal_account(
|
|
835
|
+
:intent => "order",
|
|
836
|
+
:payment_token => "fake-payment-token",
|
|
837
|
+
:payer_id => "fake-payer-id",
|
|
838
|
+
)
|
|
839
|
+
customer = Braintree::Customer.create.customer
|
|
840
|
+
result = Braintree::PaymentMethod.create(
|
|
841
|
+
:payment_method_nonce => nonce,
|
|
842
|
+
:customer_id => customer.id,
|
|
843
|
+
:options => {
|
|
844
|
+
:paypal => {
|
|
845
|
+
:payee_email => "payee@example.com",
|
|
846
|
+
:order_id => "merchant-order-id",
|
|
847
|
+
:custom_field => "custom merchant field",
|
|
848
|
+
:description => "merchant description",
|
|
849
|
+
:amount => "1.23",
|
|
850
|
+
:shipping => {
|
|
851
|
+
:first_name => "first",
|
|
852
|
+
:last_name => "last",
|
|
853
|
+
:locality => "Austin",
|
|
854
|
+
:postal_code => "78729",
|
|
855
|
+
:street_address => "7700 W Parmer Ln",
|
|
856
|
+
:country_name => "US",
|
|
857
|
+
:region => "TX",
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
},
|
|
861
|
+
)
|
|
862
|
+
|
|
863
|
+
expect(result).to be_success
|
|
864
|
+
expect(result.payment_method).to be_a(Braintree::PayPalAccount)
|
|
865
|
+
expect(result.payment_method.image_url).not_to be_nil
|
|
866
|
+
expect(result.payment_method.payer_id).not_to be_nil
|
|
867
|
+
token = result.payment_method.token
|
|
868
|
+
|
|
869
|
+
found_paypal_account = Braintree::PayPalAccount.find(token)
|
|
870
|
+
expect(found_paypal_account).not_to be_nil
|
|
871
|
+
expect(found_paypal_account.payer_id).not_to be_nil
|
|
872
|
+
end
|
|
873
|
+
|
|
874
|
+
it "creates a billing agreement payment method from a refresh token" do
|
|
875
|
+
customer = Braintree::Customer.create.customer
|
|
876
|
+
result = Braintree::PaymentMethod.create(
|
|
877
|
+
:customer_id => customer.id,
|
|
878
|
+
:paypal_refresh_token => "some_future_payment_token",
|
|
879
|
+
)
|
|
880
|
+
|
|
881
|
+
expect(result).to be_success
|
|
882
|
+
expect(result.payment_method).to be_a(Braintree::PayPalAccount)
|
|
883
|
+
expect(result.payment_method.billing_agreement_id).to eq("B_FAKE_ID")
|
|
884
|
+
expect(result.payment_method.payer_id).not_to be_nil
|
|
885
|
+
token = result.payment_method.token
|
|
886
|
+
|
|
887
|
+
found_paypal_account = Braintree::PayPalAccount.find(token)
|
|
888
|
+
expect(found_paypal_account).not_to be_nil
|
|
889
|
+
expect(found_paypal_account.billing_agreement_id).to eq("B_FAKE_ID")
|
|
890
|
+
expect(found_paypal_account.payer_id).not_to be_nil
|
|
891
|
+
end
|
|
892
|
+
|
|
893
|
+
it "does not create a payment method from an unvalidated onetime paypal account nonce" do
|
|
894
|
+
customer = Braintree::Customer.create.customer
|
|
895
|
+
nonce = nonce_for_paypal_account(:access_token => "PAYPAL_ACCESS_TOKEN")
|
|
896
|
+
result = Braintree::PaymentMethod.create(
|
|
897
|
+
:payment_method_nonce => nonce,
|
|
898
|
+
:customer_id => customer.id,
|
|
899
|
+
)
|
|
900
|
+
|
|
901
|
+
expect(result).not_to be_success
|
|
902
|
+
expect(result.errors.first.code).to eq("82902")
|
|
903
|
+
end
|
|
904
|
+
|
|
905
|
+
it "ignores passed billing address params" do
|
|
906
|
+
nonce = nonce_for_paypal_account(:consent_code => "PAYPAL_CONSENT_CODE")
|
|
907
|
+
customer = Braintree::Customer.create.customer
|
|
908
|
+
result = Braintree::PaymentMethod.create(
|
|
909
|
+
:payment_method_nonce => nonce,
|
|
910
|
+
:customer_id => customer.id,
|
|
911
|
+
:billing_address => {
|
|
912
|
+
:street_address => "123 Abc Way"
|
|
913
|
+
},
|
|
914
|
+
)
|
|
915
|
+
|
|
916
|
+
expect(result).to be_success
|
|
917
|
+
expect(result.payment_method).to be_a(Braintree::PayPalAccount)
|
|
918
|
+
expect(result.payment_method.image_url).not_to be_nil
|
|
919
|
+
token = result.payment_method.token
|
|
920
|
+
|
|
921
|
+
found_paypal_account = Braintree::PayPalAccount.find(token)
|
|
922
|
+
expect(found_paypal_account).not_to be_nil
|
|
923
|
+
end
|
|
924
|
+
|
|
925
|
+
it "ignores passed billing address id" do
|
|
926
|
+
nonce = nonce_for_paypal_account(:consent_code => "PAYPAL_CONSENT_CODE")
|
|
927
|
+
customer = Braintree::Customer.create.customer
|
|
928
|
+
result = Braintree::PaymentMethod.create(
|
|
929
|
+
:payment_method_nonce => nonce,
|
|
930
|
+
:customer_id => customer.id,
|
|
931
|
+
:billing_address_id => "address_id",
|
|
932
|
+
)
|
|
933
|
+
|
|
934
|
+
expect(result).to be_success
|
|
935
|
+
expect(result.payment_method).to be_a(Braintree::PayPalAccount)
|
|
936
|
+
expect(result.payment_method.image_url).not_to be_nil
|
|
937
|
+
token = result.payment_method.token
|
|
938
|
+
|
|
939
|
+
found_paypal_account = Braintree::PayPalAccount.find(token)
|
|
940
|
+
expect(found_paypal_account).not_to be_nil
|
|
941
|
+
end
|
|
942
|
+
|
|
943
|
+
it "returns appropriate validation errors" do
|
|
944
|
+
customer = Braintree::Customer.create.customer
|
|
945
|
+
nonce = nonce_for_paypal_account(:token => "PAYPAL_TOKEN")
|
|
946
|
+
result = Braintree::PaymentMethod.create(
|
|
947
|
+
:payment_method_nonce => nonce,
|
|
948
|
+
:customer_id => customer.id,
|
|
949
|
+
)
|
|
950
|
+
|
|
951
|
+
expect(result).not_to be_success
|
|
952
|
+
errors = result.errors.map(&:code)
|
|
953
|
+
expect(errors).to include("82901")
|
|
954
|
+
expect(errors).to include("82902")
|
|
955
|
+
end
|
|
956
|
+
|
|
957
|
+
it "doesn't return an error if credit card options are present for a paypal nonce" do
|
|
958
|
+
customer = Braintree::Customer.create!
|
|
959
|
+
original_token = random_payment_method_token
|
|
960
|
+
nonce = nonce_for_paypal_account(
|
|
961
|
+
:consent_code => "consent-code",
|
|
962
|
+
:token => original_token,
|
|
963
|
+
)
|
|
964
|
+
|
|
965
|
+
result = Braintree::PaymentMethod.create(
|
|
966
|
+
:payment_method_nonce => nonce,
|
|
967
|
+
:customer_id => customer.id,
|
|
968
|
+
:options => {
|
|
969
|
+
:verify_card => true,
|
|
970
|
+
:fail_on_duplicate_payment_method => true,
|
|
971
|
+
:verification_merchant_account_id => "not_a_real_merchant_account_id"
|
|
972
|
+
},
|
|
973
|
+
)
|
|
974
|
+
|
|
975
|
+
expect(result).to be_success
|
|
976
|
+
end
|
|
977
|
+
end
|
|
978
|
+
|
|
979
|
+
context "Unknown payment methods" do
|
|
980
|
+
it "creates an unknown payment method from a nonce" do
|
|
981
|
+
customer = Braintree::Customer.create.customer
|
|
982
|
+
token = SecureRandom.hex(16)
|
|
983
|
+
result = Braintree::PaymentMethod.create(
|
|
984
|
+
:payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
|
|
985
|
+
:customer_id => customer.id,
|
|
986
|
+
:token => token,
|
|
987
|
+
)
|
|
988
|
+
|
|
989
|
+
expect(result).to be_success
|
|
990
|
+
payment_method = result.payment_method
|
|
991
|
+
expect(payment_method).not_to be_nil
|
|
992
|
+
expect(payment_method.token).to eq(token)
|
|
993
|
+
expect(payment_method).to be_a Braintree::UnknownPaymentMethod
|
|
994
|
+
end
|
|
995
|
+
end
|
|
996
|
+
|
|
997
|
+
context "verification_currency_iso_code" do
|
|
998
|
+
it "validates verification_currency_iso_code against currency configured in default merchant account" do
|
|
999
|
+
nonce = nonce_for_new_payment_method(
|
|
1000
|
+
:credit_card => {
|
|
1001
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1002
|
+
:expiration_month => "11",
|
|
1003
|
+
:expiration_year => "2099",
|
|
1004
|
+
},
|
|
1005
|
+
)
|
|
1006
|
+
customer = Braintree::Customer.create!
|
|
1007
|
+
result = Braintree::PaymentMethod.create(
|
|
1008
|
+
:payment_method_nonce => nonce,
|
|
1009
|
+
:customer_id => customer.id,
|
|
1010
|
+
:options => {
|
|
1011
|
+
:verify_card => true,
|
|
1012
|
+
:verification_currency_iso_code => "USD"
|
|
1013
|
+
},
|
|
1014
|
+
)
|
|
1015
|
+
|
|
1016
|
+
expect(result).to be_success
|
|
1017
|
+
result.payment_method.verification.currency_iso_code == "USD"
|
|
1018
|
+
end
|
|
1019
|
+
|
|
1020
|
+
it "validates verification_currency_iso_code against currency configured in verification_merchant_account_id" do
|
|
1021
|
+
nonce = nonce_for_new_payment_method(
|
|
1022
|
+
:credit_card => {
|
|
1023
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1024
|
+
:expiration_month => "11",
|
|
1025
|
+
:expiration_year => "2099",
|
|
1026
|
+
},
|
|
1027
|
+
)
|
|
1028
|
+
customer = Braintree::Customer.create!
|
|
1029
|
+
result = Braintree::PaymentMethod.create(
|
|
1030
|
+
:payment_method_nonce => nonce,
|
|
1031
|
+
:customer_id => customer.id,
|
|
1032
|
+
:options => {
|
|
1033
|
+
:verify_card => true,
|
|
1034
|
+
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
|
1035
|
+
:verification_currency_iso_code => "USD"
|
|
1036
|
+
},
|
|
1037
|
+
)
|
|
1038
|
+
|
|
1039
|
+
expect(result).to be_success
|
|
1040
|
+
result.payment_method.verification.currency_iso_code == "USD"
|
|
1041
|
+
result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
|
|
1042
|
+
end
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in default merchant account" do
|
|
1046
|
+
nonce = nonce_for_new_payment_method(
|
|
1047
|
+
:credit_card => {
|
|
1048
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1049
|
+
:expiration_month => "11",
|
|
1050
|
+
:expiration_year => "2099",
|
|
1051
|
+
},
|
|
1052
|
+
)
|
|
1053
|
+
customer = Braintree::Customer.create!
|
|
1054
|
+
result = Braintree::PaymentMethod.create(
|
|
1055
|
+
:payment_method_nonce => nonce,
|
|
1056
|
+
:customer_id => customer.id,
|
|
1057
|
+
:options => {
|
|
1058
|
+
:verify_card => true,
|
|
1059
|
+
:verification_currency_iso_code => "GBP"
|
|
1060
|
+
},
|
|
1061
|
+
)
|
|
1062
|
+
expect(result).not_to be_success
|
|
1063
|
+
expect(result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
|
|
1064
|
+
end
|
|
1065
|
+
|
|
1066
|
+
it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in verification_merchant_account_id" do
|
|
1067
|
+
nonce = nonce_for_new_payment_method(
|
|
1068
|
+
:credit_card => {
|
|
1069
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1070
|
+
:expiration_month => "11",
|
|
1071
|
+
:expiration_year => "2099",
|
|
1072
|
+
},
|
|
1073
|
+
)
|
|
1074
|
+
customer = Braintree::Customer.create!
|
|
1075
|
+
result = Braintree::PaymentMethod.create(
|
|
1076
|
+
:payment_method_nonce => nonce,
|
|
1077
|
+
:customer_id => customer.id,
|
|
1078
|
+
:options => {
|
|
1079
|
+
:verify_card => true,
|
|
1080
|
+
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
|
1081
|
+
:verification_currency_iso_code => "GBP"
|
|
1082
|
+
},
|
|
1083
|
+
)
|
|
1084
|
+
|
|
1085
|
+
expect(result).not_to be_success
|
|
1086
|
+
expect(result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
|
|
1087
|
+
end
|
|
1088
|
+
end
|
|
1089
|
+
end
|
|
1090
|
+
|
|
1091
|
+
describe "self.create!" do
|
|
1092
|
+
it "creates a payment method from a vaulted credit card nonce" do
|
|
1093
|
+
config = Braintree::Configuration.instantiate
|
|
1094
|
+
customer = Braintree::Customer.create.customer
|
|
1095
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
|
1096
|
+
client_token = decode_client_token(raw_client_token)
|
|
1097
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
|
1098
|
+
http = ClientApiHttp.new(
|
|
1099
|
+
config,
|
|
1100
|
+
:authorization_fingerprint => authorization_fingerprint,
|
|
1101
|
+
:shared_customer_identifier => "fake_identifier",
|
|
1102
|
+
:shared_customer_identifier_type => "testing",
|
|
1103
|
+
)
|
|
1104
|
+
|
|
1105
|
+
response = http.create_credit_card(
|
|
1106
|
+
:number => 4111111111111111,
|
|
1107
|
+
:expirationMonth => 12,
|
|
1108
|
+
:expirationYear => 2020,
|
|
1109
|
+
)
|
|
1110
|
+
expect(response.code).to eq("201")
|
|
1111
|
+
|
|
1112
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
|
1113
|
+
payment_method = Braintree::PaymentMethod.create!(
|
|
1114
|
+
:payment_method_nonce => nonce,
|
|
1115
|
+
:customer_id => customer.id,
|
|
1116
|
+
)
|
|
1117
|
+
|
|
1118
|
+
expect(payment_method).to be_a(Braintree::CreditCard)
|
|
1119
|
+
token = payment_method.token
|
|
1120
|
+
|
|
1121
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
|
1122
|
+
expect(found_credit_card).not_to be_nil
|
|
1123
|
+
end
|
|
1124
|
+
end
|
|
1125
|
+
|
|
1126
|
+
describe "self.find" do
|
|
1127
|
+
context "credit cards" do
|
|
1128
|
+
it "finds the payment method with the given token" do
|
|
1129
|
+
customer = Braintree::Customer.create.customer
|
|
1130
|
+
result = Braintree::CreditCard.create(
|
|
1131
|
+
:customer_id => customer.id,
|
|
1132
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1133
|
+
:expiration_date => "05/2012",
|
|
1134
|
+
)
|
|
1135
|
+
expect(result.success?).to eq(true)
|
|
1136
|
+
|
|
1137
|
+
credit_card = Braintree::PaymentMethod.find(result.credit_card.token)
|
|
1138
|
+
expect(credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::Visa[0, 6])
|
|
1139
|
+
expect(credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::Visa[-4..-1])
|
|
1140
|
+
expect(credit_card.token).to eq(result.credit_card.token)
|
|
1141
|
+
expect(credit_card.expiration_date).to eq("05/2012")
|
|
1142
|
+
end
|
|
1143
|
+
|
|
1144
|
+
it "returns associated subscriptions with the credit card" do
|
|
1145
|
+
customer = Braintree::Customer.create.customer
|
|
1146
|
+
credit_card = Braintree::CreditCard.create(
|
|
1147
|
+
:customer_id => customer.id,
|
|
1148
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1149
|
+
:expiration_date => "05/2012",
|
|
1150
|
+
).credit_card
|
|
1151
|
+
|
|
1152
|
+
subscription = Braintree::Subscription.create(
|
|
1153
|
+
:payment_method_token => credit_card.token,
|
|
1154
|
+
:plan_id => "integration_trialless_plan",
|
|
1155
|
+
:price => "1.00",
|
|
1156
|
+
).subscription
|
|
1157
|
+
|
|
1158
|
+
found_card = Braintree::PaymentMethod.find(credit_card.token)
|
|
1159
|
+
expect(found_card.subscriptions.first.id).to eq(subscription.id)
|
|
1160
|
+
expect(found_card.subscriptions.first.plan_id).to eq("integration_trialless_plan")
|
|
1161
|
+
expect(found_card.subscriptions.first.payment_method_token).to eq(credit_card.token)
|
|
1162
|
+
expect(found_card.subscriptions.first.price).to eq(BigDecimal("1.00"))
|
|
1163
|
+
end
|
|
1164
|
+
end
|
|
1165
|
+
|
|
1166
|
+
context "paypal accounts" do
|
|
1167
|
+
it "finds the payment method with the given token" do
|
|
1168
|
+
customer = Braintree::Customer.create!
|
|
1169
|
+
payment_method_token = make_token
|
|
1170
|
+
nonce = nonce_for_paypal_account(
|
|
1171
|
+
:consent_code => "consent-code",
|
|
1172
|
+
:token => payment_method_token,
|
|
1173
|
+
)
|
|
1174
|
+
result = Braintree::PaymentMethod.create(
|
|
1175
|
+
:payment_method_nonce => nonce,
|
|
1176
|
+
:customer_id => customer.id,
|
|
1177
|
+
)
|
|
1178
|
+
expect(result).to be_success
|
|
1179
|
+
|
|
1180
|
+
paypal_account = Braintree::PaymentMethod.find(payment_method_token)
|
|
1181
|
+
expect(paypal_account).to be_a(Braintree::PayPalAccount)
|
|
1182
|
+
expect(paypal_account.token).to eq(payment_method_token)
|
|
1183
|
+
expect(paypal_account.email).to eq("jane.doe@example.com")
|
|
1184
|
+
expect(paypal_account.customer_id).to eq(customer.id)
|
|
1185
|
+
end
|
|
1186
|
+
end
|
|
1187
|
+
|
|
1188
|
+
context "apple pay cards" do
|
|
1189
|
+
it "finds the payment method with the given token" do
|
|
1190
|
+
customer = Braintree::Customer.create!
|
|
1191
|
+
payment_method_token = make_token
|
|
1192
|
+
result = Braintree::PaymentMethod.create(
|
|
1193
|
+
:payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
|
|
1194
|
+
:customer_id => customer.id,
|
|
1195
|
+
:token => payment_method_token,
|
|
1196
|
+
)
|
|
1197
|
+
expect(result).to be_success
|
|
1198
|
+
|
|
1199
|
+
apple_pay_card = Braintree::PaymentMethod.find(payment_method_token)
|
|
1200
|
+
expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
|
|
1201
|
+
expect(apple_pay_card).not_to be_nil
|
|
1202
|
+
expect(apple_pay_card.token).to eq(payment_method_token)
|
|
1203
|
+
expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::AmEx)
|
|
1204
|
+
expect(apple_pay_card.default).to eq(true)
|
|
1205
|
+
expect(apple_pay_card.image_url).to match(/apple_pay/)
|
|
1206
|
+
expect(apple_pay_card.expiration_month.to_i).to be > 0
|
|
1207
|
+
expect(apple_pay_card.expiration_year.to_i).to be > 0
|
|
1208
|
+
expect(apple_pay_card.source_description).to eq("AmEx 41002")
|
|
1209
|
+
expect(apple_pay_card.customer_id).to eq(customer.id)
|
|
1210
|
+
end
|
|
1211
|
+
|
|
1212
|
+
it "finds the payment method with the given mpan token" do
|
|
1213
|
+
customer = Braintree::Customer.create!
|
|
1214
|
+
payment_method_token = make_token
|
|
1215
|
+
result = Braintree::PaymentMethod.create(
|
|
1216
|
+
:payment_method_nonce => Braintree::Test::Nonce::ApplePayMpan,
|
|
1217
|
+
:customer_id => customer.id,
|
|
1218
|
+
:token => payment_method_token,
|
|
1219
|
+
)
|
|
1220
|
+
expect(result).to be_success
|
|
1221
|
+
|
|
1222
|
+
apple_pay_card = Braintree::PaymentMethod.find(payment_method_token)
|
|
1223
|
+
expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
|
|
1224
|
+
expect(apple_pay_card).not_to be_nil
|
|
1225
|
+
expect(apple_pay_card.token).to eq(payment_method_token)
|
|
1226
|
+
expect(apple_pay_card.card_type).to eq(Braintree::ApplePayCard::CardType::Visa)
|
|
1227
|
+
expect(apple_pay_card.default).to eq(true)
|
|
1228
|
+
expect(apple_pay_card.image_url).to match(/apple_pay/)
|
|
1229
|
+
expect(apple_pay_card.expiration_month.to_i).to be > 0
|
|
1230
|
+
expect(apple_pay_card.expiration_year.to_i).to be > 0
|
|
1231
|
+
expect(apple_pay_card.source_description).to eq("Visa 8886")
|
|
1232
|
+
expect(apple_pay_card.customer_id).to eq(customer.id)
|
|
1233
|
+
apple_pay_card.merchant_token_identifier == "DNITHE302308980427388297"
|
|
1234
|
+
apple_pay_card.source_card_last4 == "2006"
|
|
1235
|
+
end
|
|
1236
|
+
end
|
|
1237
|
+
|
|
1238
|
+
context "venmo accounts" do
|
|
1239
|
+
it "finds the payment method with the given token" do
|
|
1240
|
+
customer = Braintree::Customer.create!
|
|
1241
|
+
payment_method_token = make_token
|
|
1242
|
+
result = Braintree::PaymentMethod.create(
|
|
1243
|
+
:payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
|
|
1244
|
+
:customer_id => customer.id,
|
|
1245
|
+
:token => payment_method_token,
|
|
1246
|
+
)
|
|
1247
|
+
expect(result).to be_success
|
|
1248
|
+
|
|
1249
|
+
venmo_account = Braintree::PaymentMethod.find(payment_method_token)
|
|
1250
|
+
expect(venmo_account).to be_a(Braintree::VenmoAccount)
|
|
1251
|
+
expect(venmo_account).not_to be_nil
|
|
1252
|
+
expect(venmo_account.token).to eq(payment_method_token)
|
|
1253
|
+
expect(venmo_account.default).to eq(true)
|
|
1254
|
+
expect(venmo_account.image_url).to match(/venmo/)
|
|
1255
|
+
expect(venmo_account.username).to eq("venmojoe")
|
|
1256
|
+
expect(venmo_account.venmo_user_id).to eq("1234567891234567891")
|
|
1257
|
+
expect(venmo_account.source_description).to eq("Venmo Account: venmojoe")
|
|
1258
|
+
expect(venmo_account.customer_id).to eq(customer.id)
|
|
1259
|
+
end
|
|
1260
|
+
end
|
|
1261
|
+
|
|
1262
|
+
context "google pay cards" do
|
|
1263
|
+
it "finds the proxy card payment method with the given token" do
|
|
1264
|
+
customer = Braintree::Customer.create!
|
|
1265
|
+
payment_method_token = make_token
|
|
1266
|
+
result = Braintree::PaymentMethod.create(
|
|
1267
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
|
1268
|
+
:customer_id => customer.id,
|
|
1269
|
+
:token => payment_method_token,
|
|
1270
|
+
)
|
|
1271
|
+
expect(result).to be_success
|
|
1272
|
+
|
|
1273
|
+
google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
|
|
1274
|
+
expect(google_pay_card).to be_a(Braintree::GooglePayCard)
|
|
1275
|
+
expect(google_pay_card).not_to be_nil
|
|
1276
|
+
expect(google_pay_card.token).to eq(payment_method_token)
|
|
1277
|
+
expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::Discover)
|
|
1278
|
+
expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::Discover)
|
|
1279
|
+
expect(google_pay_card.expiration_month.to_i).to be > 0
|
|
1280
|
+
expect(google_pay_card.expiration_year.to_i).to be > 0
|
|
1281
|
+
expect(google_pay_card.default).to eq(true)
|
|
1282
|
+
expect(google_pay_card.image_url).to match(/android_pay/)
|
|
1283
|
+
expect(google_pay_card.is_network_tokenized?).to eq(false)
|
|
1284
|
+
expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::Discover)
|
|
1285
|
+
expect(google_pay_card.source_card_last_4).to eq("1111")
|
|
1286
|
+
expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
|
|
1287
|
+
expect(google_pay_card.source_description).to eq("Discover 1111")
|
|
1288
|
+
expect(google_pay_card.customer_id).to eq(customer.id)
|
|
1289
|
+
end
|
|
1290
|
+
|
|
1291
|
+
it "finds the network token payment method with the given token" do
|
|
1292
|
+
customer = Braintree::Customer.create!
|
|
1293
|
+
payment_method_token = make_token
|
|
1294
|
+
result = Braintree::PaymentMethod.create(
|
|
1295
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
|
|
1296
|
+
:customer_id => customer.id,
|
|
1297
|
+
:token => payment_method_token,
|
|
1298
|
+
)
|
|
1299
|
+
expect(result).to be_success
|
|
1300
|
+
|
|
1301
|
+
google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
|
|
1302
|
+
expect(google_pay_card).to be_a(Braintree::GooglePayCard)
|
|
1303
|
+
expect(google_pay_card).not_to be_nil
|
|
1304
|
+
expect(google_pay_card.token).to eq(payment_method_token)
|
|
1305
|
+
expect(google_pay_card.card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
|
|
1306
|
+
expect(google_pay_card.virtual_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
|
|
1307
|
+
expect(google_pay_card.expiration_month.to_i).to be > 0
|
|
1308
|
+
expect(google_pay_card.expiration_year.to_i).to be > 0
|
|
1309
|
+
expect(google_pay_card.default).to eq(true)
|
|
1310
|
+
expect(google_pay_card.image_url).to match(/android_pay/)
|
|
1311
|
+
expect(google_pay_card.is_network_tokenized?).to eq(true)
|
|
1312
|
+
expect(google_pay_card.source_card_type).to eq(Braintree::CreditCard::CardType::MasterCard)
|
|
1313
|
+
expect(google_pay_card.source_card_last_4).to eq("4444")
|
|
1314
|
+
expect(google_pay_card.google_transaction_id).to eq("google_transaction_id")
|
|
1315
|
+
expect(google_pay_card.source_description).to eq("MasterCard 4444")
|
|
1316
|
+
expect(google_pay_card.customer_id).to eq(customer.id)
|
|
1317
|
+
end
|
|
1318
|
+
end
|
|
1319
|
+
|
|
1320
|
+
context "unknown payment methods" do
|
|
1321
|
+
it "finds the payment method with the given token" do
|
|
1322
|
+
customer = Braintree::Customer.create!
|
|
1323
|
+
payment_method_token = make_token
|
|
1324
|
+
result = Braintree::PaymentMethod.create(
|
|
1325
|
+
:payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
|
|
1326
|
+
:customer_id => customer.id,
|
|
1327
|
+
:token => payment_method_token,
|
|
1328
|
+
)
|
|
1329
|
+
expect(result).to be_success
|
|
1330
|
+
|
|
1331
|
+
payment_method = Braintree::PaymentMethod.find(payment_method_token)
|
|
1332
|
+
expect(payment_method).not_to be_nil
|
|
1333
|
+
expect(payment_method.token).to eq(payment_method_token)
|
|
1334
|
+
expect(payment_method.image_url).not_to be_nil
|
|
1335
|
+
expect(payment_method).to be_a Braintree::UnknownPaymentMethod
|
|
1336
|
+
expect(payment_method.customer_id).to eq(customer.id)
|
|
1337
|
+
end
|
|
1338
|
+
end
|
|
1339
|
+
|
|
1340
|
+
it "raises a NotFoundError exception if payment method cannot be found" do
|
|
1341
|
+
expect do
|
|
1342
|
+
Braintree::PaymentMethod.find("invalid-token")
|
|
1343
|
+
end.to raise_error(Braintree::NotFoundError, 'payment method with token "invalid-token" not found')
|
|
1344
|
+
end
|
|
1345
|
+
end
|
|
1346
|
+
|
|
1347
|
+
describe "self.delete" do
|
|
1348
|
+
it "deletes an google pay card" do
|
|
1349
|
+
customer = Braintree::Customer.create!
|
|
1350
|
+
|
|
1351
|
+
create_result = Braintree::PaymentMethod.create(
|
|
1352
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
|
1353
|
+
:customer_id => customer.id,
|
|
1354
|
+
)
|
|
1355
|
+
|
|
1356
|
+
token = create_result.payment_method.token
|
|
1357
|
+
|
|
1358
|
+
google_card = Braintree::PaymentMethod.find(token)
|
|
1359
|
+
expect(google_card).to be_a(Braintree::GooglePayCard)
|
|
1360
|
+
|
|
1361
|
+
delete_result = Braintree::PaymentMethod.delete(token)
|
|
1362
|
+
expect(delete_result.success?).to eq(true)
|
|
1363
|
+
|
|
1364
|
+
expect do
|
|
1365
|
+
Braintree::PaymentMethod.find(token)
|
|
1366
|
+
end.to raise_error(Braintree::NotFoundError)
|
|
1367
|
+
end
|
|
1368
|
+
|
|
1369
|
+
it "deletes an apple pay card" do
|
|
1370
|
+
customer = Braintree::Customer.create!
|
|
1371
|
+
|
|
1372
|
+
create_result = Braintree::PaymentMethod.create(
|
|
1373
|
+
:payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
|
|
1374
|
+
:customer_id => customer.id,
|
|
1375
|
+
)
|
|
1376
|
+
token = create_result.payment_method.token
|
|
1377
|
+
|
|
1378
|
+
apple_pay_card = Braintree::PaymentMethod.find(token)
|
|
1379
|
+
expect(apple_pay_card).to be_a(Braintree::ApplePayCard)
|
|
1380
|
+
|
|
1381
|
+
delete_result = Braintree::PaymentMethod.delete(token)
|
|
1382
|
+
expect(delete_result.success?).to eq(true)
|
|
1383
|
+
|
|
1384
|
+
expect do
|
|
1385
|
+
Braintree::PaymentMethod.find(token)
|
|
1386
|
+
end.to raise_error(Braintree::NotFoundError)
|
|
1387
|
+
end
|
|
1388
|
+
|
|
1389
|
+
it "deletes a paypal account" do
|
|
1390
|
+
customer = Braintree::Customer.create!
|
|
1391
|
+
paypal_account_token = make_token
|
|
1392
|
+
|
|
1393
|
+
nonce = nonce_for_paypal_account(
|
|
1394
|
+
:consent_code => "PAYPAL_CONSENT_CODE",
|
|
1395
|
+
:token => paypal_account_token,
|
|
1396
|
+
)
|
|
1397
|
+
Braintree::PaymentMethod.create(
|
|
1398
|
+
:payment_method_nonce => nonce,
|
|
1399
|
+
:customer_id => customer.id,
|
|
1400
|
+
)
|
|
1401
|
+
|
|
1402
|
+
paypal_account = Braintree::PaymentMethod.find(paypal_account_token)
|
|
1403
|
+
expect(paypal_account).to be_a(Braintree::PayPalAccount)
|
|
1404
|
+
|
|
1405
|
+
result = Braintree::PaymentMethod.delete(paypal_account_token, {:revoke_all_grants => false})
|
|
1406
|
+
expect(result.success?).to eq(true)
|
|
1407
|
+
|
|
1408
|
+
expect do
|
|
1409
|
+
Braintree::PaymentMethod.find(paypal_account_token)
|
|
1410
|
+
end.to raise_error(Braintree::NotFoundError, "payment method with token \"#{paypal_account_token}\" not found")
|
|
1411
|
+
end
|
|
1412
|
+
|
|
1413
|
+
it "deletes a credit card" do
|
|
1414
|
+
token = make_token
|
|
1415
|
+
customer = Braintree::Customer.create!
|
|
1416
|
+
nonce = nonce_for_new_payment_method({
|
|
1417
|
+
:credit_card => {
|
|
1418
|
+
:number => "4111111111111111",
|
|
1419
|
+
:expiration_month => "11",
|
|
1420
|
+
:expiration_year => "2099",
|
|
1421
|
+
:token => token
|
|
1422
|
+
},
|
|
1423
|
+
:client_token_options => {:customer_id => customer.id}
|
|
1424
|
+
})
|
|
1425
|
+
|
|
1426
|
+
Braintree::PaymentMethod.create(
|
|
1427
|
+
:payment_method_nonce => nonce,
|
|
1428
|
+
:customer_id => customer.id,
|
|
1429
|
+
)
|
|
1430
|
+
|
|
1431
|
+
result = Braintree::PaymentMethod.delete(token)
|
|
1432
|
+
expect(result.success?).to eq(true)
|
|
1433
|
+
|
|
1434
|
+
expect do
|
|
1435
|
+
Braintree::PaymentMethod.find(token)
|
|
1436
|
+
end.to raise_error(Braintree::NotFoundError, "payment method with token \"#{token}\" not found")
|
|
1437
|
+
end
|
|
1438
|
+
|
|
1439
|
+
it "raises a NotFoundError exception if payment method cannot be found" do
|
|
1440
|
+
token = make_token
|
|
1441
|
+
|
|
1442
|
+
expect do
|
|
1443
|
+
Braintree::PaymentMethod.delete(token)
|
|
1444
|
+
end.to raise_error(Braintree::NotFoundError)
|
|
1445
|
+
end
|
|
1446
|
+
end
|
|
1447
|
+
|
|
1448
|
+
describe "self.update" do
|
|
1449
|
+
context "credit cards" do
|
|
1450
|
+
it "throws validation error when passing invalid pass thru params" do
|
|
1451
|
+
customer = Braintree::Customer.create!
|
|
1452
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1453
|
+
:customer_id => customer.id,
|
|
1454
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
|
1455
|
+
:options => {:verify_card => true},
|
|
1456
|
+
)
|
|
1457
|
+
|
|
1458
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1459
|
+
:cardholder_name => "New Holder",
|
|
1460
|
+
:cvv => "456",
|
|
1461
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1462
|
+
:expiration_date => "06/2013",
|
|
1463
|
+
:three_d_secure_pass_thru => {
|
|
1464
|
+
:eci_flag => "02",
|
|
1465
|
+
:cavv => "some_cavv",
|
|
1466
|
+
:xid => "some_xid",
|
|
1467
|
+
:three_d_secure_version => "xx",
|
|
1468
|
+
:authentication_response => "Y",
|
|
1469
|
+
:directory_response => "Y",
|
|
1470
|
+
:cavv_algorithm => "2",
|
|
1471
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
1472
|
+
},
|
|
1473
|
+
:options => {:verify_card => true},
|
|
1474
|
+
)
|
|
1475
|
+
expect(update_result).to_not be_success
|
|
1476
|
+
error = update_result.errors.for(:verification).first
|
|
1477
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
|
|
1478
|
+
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`).")
|
|
1479
|
+
end
|
|
1480
|
+
|
|
1481
|
+
it "updates the credit card with three_d_secure pass thru params" do
|
|
1482
|
+
customer = Braintree::Customer.create!
|
|
1483
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1484
|
+
:customer_id => customer.id,
|
|
1485
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
|
1486
|
+
:options => {:verify_card => true},
|
|
1487
|
+
)
|
|
1488
|
+
|
|
1489
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1490
|
+
:cardholder_name => "New Holder",
|
|
1491
|
+
:cvv => "456",
|
|
1492
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1493
|
+
:expiration_date => "06/2013",
|
|
1494
|
+
:three_d_secure_pass_thru => {
|
|
1495
|
+
:eci_flag => "02",
|
|
1496
|
+
:cavv => "some_cavv",
|
|
1497
|
+
:xid => "some_xid",
|
|
1498
|
+
:three_d_secure_version => "1.0.2",
|
|
1499
|
+
:authentication_response => "Y",
|
|
1500
|
+
:directory_response => "Y",
|
|
1501
|
+
:cavv_algorithm => "2",
|
|
1502
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
|
1503
|
+
},
|
|
1504
|
+
:options => {:verify_card => true},
|
|
1505
|
+
)
|
|
1506
|
+
expect(update_result.success?).to eq(true)
|
|
1507
|
+
expect(update_result.payment_method).to eq(credit_card)
|
|
1508
|
+
updated_credit_card = update_result.payment_method
|
|
1509
|
+
expect(updated_credit_card.cardholder_name).to eq("New Holder")
|
|
1510
|
+
expect(updated_credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
|
|
1511
|
+
expect(updated_credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
|
|
1512
|
+
expect(updated_credit_card.expiration_date).to eq("06/2013")
|
|
1513
|
+
end
|
|
1514
|
+
|
|
1515
|
+
it "updates the credit card" do
|
|
1516
|
+
customer = Braintree::Customer.create!
|
|
1517
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1518
|
+
:cardholder_name => "Original Holder",
|
|
1519
|
+
:customer_id => customer.id,
|
|
1520
|
+
:cvv => "123",
|
|
1521
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1522
|
+
:expiration_date => "05/2012",
|
|
1523
|
+
)
|
|
1524
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1525
|
+
:cardholder_name => "New Holder",
|
|
1526
|
+
:cvv => "456",
|
|
1527
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1528
|
+
:expiration_date => "06/2013",
|
|
1529
|
+
)
|
|
1530
|
+
expect(update_result.success?).to eq(true)
|
|
1531
|
+
expect(update_result.payment_method).to eq(credit_card)
|
|
1532
|
+
updated_credit_card = update_result.payment_method
|
|
1533
|
+
expect(updated_credit_card.cardholder_name).to eq("New Holder")
|
|
1534
|
+
expect(updated_credit_card.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
|
|
1535
|
+
expect(updated_credit_card.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
|
|
1536
|
+
expect(updated_credit_card.expiration_date).to eq("06/2013")
|
|
1537
|
+
end
|
|
1538
|
+
|
|
1539
|
+
it "includes risk data when skip_advanced_fraud_checking is false" do
|
|
1540
|
+
with_fraud_protection_enterprise_merchant do
|
|
1541
|
+
customer = Braintree::Customer.create!
|
|
1542
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1543
|
+
:customer_id => customer.id,
|
|
1544
|
+
:cvv => "123",
|
|
1545
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1546
|
+
:expiration_date => "05/2012",
|
|
1547
|
+
)
|
|
1548
|
+
update_result = Braintree::PaymentMethod.update(
|
|
1549
|
+
credit_card.token,
|
|
1550
|
+
:cvv => "456",
|
|
1551
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1552
|
+
:expiration_date => "06/2013",
|
|
1553
|
+
:options => {
|
|
1554
|
+
:verify_card => true,
|
|
1555
|
+
:skip_advanced_fraud_checking => false
|
|
1556
|
+
},
|
|
1557
|
+
)
|
|
1558
|
+
|
|
1559
|
+
expect(update_result).to be_success
|
|
1560
|
+
verification = update_result.payment_method.verification
|
|
1561
|
+
expect(verification.risk_data).not_to be_nil
|
|
1562
|
+
end
|
|
1563
|
+
end
|
|
1564
|
+
|
|
1565
|
+
it "does not include risk data when skip_advanced_fraud_checking is true" do
|
|
1566
|
+
with_fraud_protection_enterprise_merchant do
|
|
1567
|
+
customer = Braintree::Customer.create!
|
|
1568
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1569
|
+
:customer_id => customer.id,
|
|
1570
|
+
:cvv => "123",
|
|
1571
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1572
|
+
:expiration_date => "05/2012",
|
|
1573
|
+
)
|
|
1574
|
+
update_result = Braintree::PaymentMethod.update(
|
|
1575
|
+
credit_card.token,
|
|
1576
|
+
:cvv => "456",
|
|
1577
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1578
|
+
:expiration_date => "06/2013",
|
|
1579
|
+
:options => {
|
|
1580
|
+
:verify_card => true,
|
|
1581
|
+
:skip_advanced_fraud_checking => true
|
|
1582
|
+
},
|
|
1583
|
+
)
|
|
1584
|
+
|
|
1585
|
+
expect(update_result).to be_success
|
|
1586
|
+
verification = update_result.payment_method.verification
|
|
1587
|
+
expect(verification.risk_data).to be_nil
|
|
1588
|
+
end
|
|
1589
|
+
end
|
|
1590
|
+
|
|
1591
|
+
context "verification_currency_iso_code" do
|
|
1592
|
+
it "validates verification_currency_iso_code and updates the credit card " do
|
|
1593
|
+
customer = Braintree::Customer.create!
|
|
1594
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1595
|
+
:cardholder_name => "Original Holder",
|
|
1596
|
+
:customer_id => customer.id,
|
|
1597
|
+
:cvv => "123",
|
|
1598
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1599
|
+
:expiration_date => "05/2012",
|
|
1600
|
+
)
|
|
1601
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1602
|
+
:cardholder_name => "New Holder",
|
|
1603
|
+
:cvv => "456",
|
|
1604
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1605
|
+
:expiration_date => "06/2013",
|
|
1606
|
+
:options => {:verify_card => true, :verification_currency_iso_code => "USD"},
|
|
1607
|
+
)
|
|
1608
|
+
expect(update_result.success?).to eq(true)
|
|
1609
|
+
update_result.payment_method.verification.currency_iso_code == "USD"
|
|
1610
|
+
end
|
|
1611
|
+
|
|
1612
|
+
it "validates verification_currency_iso_code against the given verification_merchant_account_id and updates the credit card " do
|
|
1613
|
+
customer = Braintree::Customer.create!
|
|
1614
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1615
|
+
:cardholder_name => "Original Holder",
|
|
1616
|
+
:customer_id => customer.id,
|
|
1617
|
+
:cvv => "123",
|
|
1618
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1619
|
+
:expiration_date => "05/2012",
|
|
1620
|
+
)
|
|
1621
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1622
|
+
:cardholder_name => "New Holder",
|
|
1623
|
+
:cvv => "456",
|
|
1624
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1625
|
+
:expiration_date => "06/2013",
|
|
1626
|
+
:options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"},
|
|
1627
|
+
)
|
|
1628
|
+
expect(update_result.success?).to eq(true)
|
|
1629
|
+
update_result.payment_method.verification.currency_iso_code == "USD"
|
|
1630
|
+
update_result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
|
|
1631
|
+
end
|
|
1632
|
+
|
|
1633
|
+
it "throws validation error when passing invalid verification_currency_iso_code" do
|
|
1634
|
+
customer = Braintree::Customer.create!
|
|
1635
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1636
|
+
:cardholder_name => "Original Holder",
|
|
1637
|
+
:customer_id => customer.id,
|
|
1638
|
+
:cvv => "123",
|
|
1639
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1640
|
+
:expiration_date => "05/2012",
|
|
1641
|
+
)
|
|
1642
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1643
|
+
:cardholder_name => "New Holder",
|
|
1644
|
+
:cvv => "456",
|
|
1645
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1646
|
+
:expiration_date => "06/2013",
|
|
1647
|
+
:options => {:verify_card => true, :verification_currency_iso_code => "GBP"},
|
|
1648
|
+
)
|
|
1649
|
+
expect(update_result).to_not be_success
|
|
1650
|
+
expect(update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
|
|
1651
|
+
end
|
|
1652
|
+
|
|
1653
|
+
it "throws validation error when passing invalid verification_currency_iso_code of the given verification merchant account id" do
|
|
1654
|
+
customer = Braintree::Customer.create!
|
|
1655
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1656
|
+
:cardholder_name => "Original Holder",
|
|
1657
|
+
:customer_id => customer.id,
|
|
1658
|
+
:cvv => "123",
|
|
1659
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1660
|
+
:expiration_date => "05/2012",
|
|
1661
|
+
)
|
|
1662
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1663
|
+
:cardholder_name => "New Holder",
|
|
1664
|
+
:cvv => "456",
|
|
1665
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1666
|
+
:expiration_date => "06/2013",
|
|
1667
|
+
:options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"},
|
|
1668
|
+
)
|
|
1669
|
+
expect(update_result).to_not be_success
|
|
1670
|
+
expect(update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq(Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount)
|
|
1671
|
+
end
|
|
1672
|
+
end
|
|
1673
|
+
|
|
1674
|
+
|
|
1675
|
+
context "billing address" do
|
|
1676
|
+
it "creates a new billing address by default" do
|
|
1677
|
+
customer = Braintree::Customer.create!
|
|
1678
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1679
|
+
:customer_id => customer.id,
|
|
1680
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1681
|
+
:expiration_date => "05/2012",
|
|
1682
|
+
:billing_address => {
|
|
1683
|
+
:street_address => "123 Nigeria Ave"
|
|
1684
|
+
},
|
|
1685
|
+
)
|
|
1686
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1687
|
+
:billing_address => {
|
|
1688
|
+
:region => "IL"
|
|
1689
|
+
},
|
|
1690
|
+
)
|
|
1691
|
+
expect(update_result.success?).to eq(true)
|
|
1692
|
+
updated_credit_card = update_result.payment_method
|
|
1693
|
+
expect(updated_credit_card.billing_address.region).to eq("IL")
|
|
1694
|
+
expect(updated_credit_card.billing_address.street_address).to eq(nil)
|
|
1695
|
+
expect(updated_credit_card.billing_address.id).not_to eq(credit_card.billing_address.id)
|
|
1696
|
+
end
|
|
1697
|
+
|
|
1698
|
+
it "updates the billing address if option is specified" do
|
|
1699
|
+
customer = Braintree::Customer.create!
|
|
1700
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1701
|
+
:customer_id => customer.id,
|
|
1702
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1703
|
+
:expiration_date => "05/2012",
|
|
1704
|
+
:billing_address => {
|
|
1705
|
+
:street_address => "123 Nigeria Ave"
|
|
1706
|
+
},
|
|
1707
|
+
)
|
|
1708
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1709
|
+
:billing_address => {
|
|
1710
|
+
:international_phone => {:country_code => "1", :national_number => "3121234567"},
|
|
1711
|
+
:region => "IL",
|
|
1712
|
+
:options => {:update_existing => true}
|
|
1713
|
+
},
|
|
1714
|
+
)
|
|
1715
|
+
expect(update_result.success?).to eq(true)
|
|
1716
|
+
updated_credit_card = update_result.payment_method
|
|
1717
|
+
expect(updated_credit_card.billing_address.international_phone[:country_code]).to eq("1")
|
|
1718
|
+
expect(updated_credit_card.billing_address.international_phone[:national_number]).to eq("3121234567")
|
|
1719
|
+
expect(updated_credit_card.billing_address.region).to eq("IL")
|
|
1720
|
+
expect(updated_credit_card.billing_address.street_address).to eq("123 Nigeria Ave")
|
|
1721
|
+
expect(updated_credit_card.billing_address.id).to eq(credit_card.billing_address.id)
|
|
1722
|
+
end
|
|
1723
|
+
|
|
1724
|
+
it "updates the country via codes" do
|
|
1725
|
+
customer = Braintree::Customer.create!
|
|
1726
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1727
|
+
:customer_id => customer.id,
|
|
1728
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1729
|
+
:expiration_date => "05/2012",
|
|
1730
|
+
:billing_address => {
|
|
1731
|
+
:street_address => "123 Nigeria Ave"
|
|
1732
|
+
},
|
|
1733
|
+
)
|
|
1734
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1735
|
+
:billing_address => {
|
|
1736
|
+
:country_name => "American Samoa",
|
|
1737
|
+
:country_code_alpha2 => "AS",
|
|
1738
|
+
:country_code_alpha3 => "ASM",
|
|
1739
|
+
:country_code_numeric => "016",
|
|
1740
|
+
:options => {:update_existing => true}
|
|
1741
|
+
},
|
|
1742
|
+
)
|
|
1743
|
+
expect(update_result.success?).to eq(true)
|
|
1744
|
+
updated_credit_card = update_result.payment_method
|
|
1745
|
+
expect(updated_credit_card.billing_address.country_name).to eq("American Samoa")
|
|
1746
|
+
expect(updated_credit_card.billing_address.country_code_alpha2).to eq("AS")
|
|
1747
|
+
expect(updated_credit_card.billing_address.country_code_alpha3).to eq("ASM")
|
|
1748
|
+
expect(updated_credit_card.billing_address.country_code_numeric).to eq("016")
|
|
1749
|
+
end
|
|
1750
|
+
end
|
|
1751
|
+
|
|
1752
|
+
it "can pass expiration_month and expiration_year" do
|
|
1753
|
+
customer = Braintree::Customer.create!
|
|
1754
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1755
|
+
:customer_id => customer.id,
|
|
1756
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1757
|
+
:expiration_date => "05/2012",
|
|
1758
|
+
)
|
|
1759
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1760
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1761
|
+
:expiration_month => "07",
|
|
1762
|
+
:expiration_year => "2011",
|
|
1763
|
+
)
|
|
1764
|
+
expect(update_result.success?).to eq(true)
|
|
1765
|
+
expect(update_result.payment_method).to eq(credit_card)
|
|
1766
|
+
expect(update_result.payment_method.expiration_month).to eq("07")
|
|
1767
|
+
expect(update_result.payment_method.expiration_year).to eq("2011")
|
|
1768
|
+
expect(update_result.payment_method.expiration_date).to eq("07/2011")
|
|
1769
|
+
end
|
|
1770
|
+
|
|
1771
|
+
it "verifies the update if options[verify_card]=true" do
|
|
1772
|
+
customer = Braintree::Customer.create!
|
|
1773
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1774
|
+
:cardholder_name => "Original Holder",
|
|
1775
|
+
:customer_id => customer.id,
|
|
1776
|
+
:cvv => "123",
|
|
1777
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1778
|
+
:expiration_date => "05/2012",
|
|
1779
|
+
)
|
|
1780
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1781
|
+
:cardholder_name => "New Holder",
|
|
1782
|
+
:cvv => "456",
|
|
1783
|
+
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
|
|
1784
|
+
:expiration_date => "06/2013",
|
|
1785
|
+
:options => {:verify_card => true},
|
|
1786
|
+
)
|
|
1787
|
+
expect(update_result.success?).to eq(false)
|
|
1788
|
+
expect(update_result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
|
1789
|
+
expect(update_result.credit_card_verification.gateway_rejection_reason).to be_nil
|
|
1790
|
+
end
|
|
1791
|
+
|
|
1792
|
+
it "accepts a custom verification amount" do
|
|
1793
|
+
customer = Braintree::Customer.create!
|
|
1794
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1795
|
+
:cardholder_name => "Card Holder",
|
|
1796
|
+
:customer_id => customer.id,
|
|
1797
|
+
:cvv => "123",
|
|
1798
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1799
|
+
:expiration_date => "05/2020",
|
|
1800
|
+
)
|
|
1801
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1802
|
+
:payment_method_nonce => Braintree::Test::Nonce::ProcessorDeclinedMasterCard,
|
|
1803
|
+
:options => {:verify_card => true, :verification_amount => "2.34"},
|
|
1804
|
+
)
|
|
1805
|
+
expect(update_result.success?).to eq(false)
|
|
1806
|
+
expect(update_result.credit_card_verification.status).to eq(Braintree::Transaction::Status::ProcessorDeclined)
|
|
1807
|
+
expect(update_result.credit_card_verification.gateway_rejection_reason).to be_nil
|
|
1808
|
+
expect(update_result.credit_card_verification.amount).to eq(BigDecimal("2.34"))
|
|
1809
|
+
end
|
|
1810
|
+
|
|
1811
|
+
it "can update the billing address" do
|
|
1812
|
+
customer = Braintree::Customer.create!
|
|
1813
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1814
|
+
:cardholder_name => "Original Holder",
|
|
1815
|
+
:customer_id => customer.id,
|
|
1816
|
+
:cvv => "123",
|
|
1817
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1818
|
+
:expiration_date => "05/2012",
|
|
1819
|
+
:billing_address => {
|
|
1820
|
+
:first_name => "Old First Name",
|
|
1821
|
+
:last_name => "Old Last Name",
|
|
1822
|
+
:company => "Old Company",
|
|
1823
|
+
:street_address => "123 Old St",
|
|
1824
|
+
:extended_address => "Apt Old",
|
|
1825
|
+
:locality => "Old City",
|
|
1826
|
+
:region => "Old State",
|
|
1827
|
+
:postal_code => "12345",
|
|
1828
|
+
:country_name => "Canada"
|
|
1829
|
+
},
|
|
1830
|
+
)
|
|
1831
|
+
result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1832
|
+
:options => {:verify_card => false},
|
|
1833
|
+
:billing_address => {
|
|
1834
|
+
:first_name => "New First Name",
|
|
1835
|
+
:last_name => "New Last Name",
|
|
1836
|
+
:company => "New Company",
|
|
1837
|
+
:street_address => "123 New St",
|
|
1838
|
+
:extended_address => "Apt New",
|
|
1839
|
+
:locality => "New City",
|
|
1840
|
+
:region => "New State",
|
|
1841
|
+
:postal_code => "56789",
|
|
1842
|
+
:country_name => "United States of America"
|
|
1843
|
+
},
|
|
1844
|
+
)
|
|
1845
|
+
expect(result.success?).to eq(true)
|
|
1846
|
+
address = result.payment_method.billing_address
|
|
1847
|
+
expect(address.first_name).to eq("New First Name")
|
|
1848
|
+
expect(address.last_name).to eq("New Last Name")
|
|
1849
|
+
expect(address.company).to eq("New Company")
|
|
1850
|
+
expect(address.street_address).to eq("123 New St")
|
|
1851
|
+
expect(address.extended_address).to eq("Apt New")
|
|
1852
|
+
expect(address.locality).to eq("New City")
|
|
1853
|
+
expect(address.region).to eq("New State")
|
|
1854
|
+
expect(address.postal_code).to eq("56789")
|
|
1855
|
+
expect(address.country_name).to eq("United States of America")
|
|
1856
|
+
end
|
|
1857
|
+
|
|
1858
|
+
it "returns an error response if invalid" do
|
|
1859
|
+
customer = Braintree::Customer.create!
|
|
1860
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1861
|
+
:cardholder_name => "Original Holder",
|
|
1862
|
+
:customer_id => customer.id,
|
|
1863
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1864
|
+
:expiration_date => "05/2012",
|
|
1865
|
+
)
|
|
1866
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
|
1867
|
+
:cardholder_name => "New Holder",
|
|
1868
|
+
:number => "invalid",
|
|
1869
|
+
:expiration_date => "05/2014",
|
|
1870
|
+
)
|
|
1871
|
+
expect(update_result.success?).to eq(false)
|
|
1872
|
+
expect(update_result.errors.for(:credit_card).on(:number)[0].message).to eq("Credit card number must be 12-19 digits.")
|
|
1873
|
+
end
|
|
1874
|
+
|
|
1875
|
+
it "can update the default" do
|
|
1876
|
+
customer = Braintree::Customer.create!
|
|
1877
|
+
card1 = Braintree::CreditCard.create(
|
|
1878
|
+
:customer_id => customer.id,
|
|
1879
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1880
|
+
:expiration_date => "05/2009",
|
|
1881
|
+
).credit_card
|
|
1882
|
+
card2 = Braintree::CreditCard.create(
|
|
1883
|
+
:customer_id => customer.id,
|
|
1884
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1885
|
+
:expiration_date => "05/2009",
|
|
1886
|
+
).credit_card
|
|
1887
|
+
|
|
1888
|
+
expect(card1).to be_default
|
|
1889
|
+
expect(card2).not_to be_default
|
|
1890
|
+
|
|
1891
|
+
Braintree::PaymentMethod.update(card2.token, :options => {:make_default => true})
|
|
1892
|
+
|
|
1893
|
+
expect(Braintree::CreditCard.find(card1.token)).not_to be_default
|
|
1894
|
+
expect(Braintree::CreditCard.find(card2.token)).to be_default
|
|
1895
|
+
end
|
|
1896
|
+
end
|
|
1897
|
+
|
|
1898
|
+
context "paypal accounts" do
|
|
1899
|
+
it "updates a paypal account's token" do
|
|
1900
|
+
customer = Braintree::Customer.create!
|
|
1901
|
+
original_token = random_payment_method_token
|
|
1902
|
+
nonce = nonce_for_paypal_account(
|
|
1903
|
+
:consent_code => "consent-code",
|
|
1904
|
+
:token => original_token,
|
|
1905
|
+
)
|
|
1906
|
+
original_result = Braintree::PaymentMethod.create(
|
|
1907
|
+
:payment_method_nonce => nonce,
|
|
1908
|
+
:customer_id => customer.id,
|
|
1909
|
+
)
|
|
1910
|
+
|
|
1911
|
+
updated_token = make_token
|
|
1912
|
+
Braintree::PaymentMethod.update(
|
|
1913
|
+
original_token,
|
|
1914
|
+
:token => updated_token,
|
|
1915
|
+
)
|
|
1916
|
+
|
|
1917
|
+
updated_paypal_account = Braintree::PayPalAccount.find(updated_token)
|
|
1918
|
+
expect(updated_paypal_account.email).to eq(original_result.payment_method.email)
|
|
1919
|
+
|
|
1920
|
+
expect do
|
|
1921
|
+
Braintree::PayPalAccount.find(original_token)
|
|
1922
|
+
end.to raise_error(Braintree::NotFoundError, "payment method with token \"#{original_token}\" not found")
|
|
1923
|
+
end
|
|
1924
|
+
|
|
1925
|
+
it "can make a paypal account the default payment method" do
|
|
1926
|
+
customer = Braintree::Customer.create!
|
|
1927
|
+
result = Braintree::CreditCard.create(
|
|
1928
|
+
:customer_id => customer.id,
|
|
1929
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1930
|
+
:expiration_date => "05/2009",
|
|
1931
|
+
:options => {:make_default => true},
|
|
1932
|
+
)
|
|
1933
|
+
expect(result).to be_success
|
|
1934
|
+
|
|
1935
|
+
nonce = nonce_for_paypal_account(:consent_code => "consent-code")
|
|
1936
|
+
original_token = Braintree::PaymentMethod.create(
|
|
1937
|
+
:payment_method_nonce => nonce,
|
|
1938
|
+
:customer_id => customer.id,
|
|
1939
|
+
).payment_method.token
|
|
1940
|
+
|
|
1941
|
+
Braintree::PaymentMethod.update(
|
|
1942
|
+
original_token,
|
|
1943
|
+
:options => {:make_default => true},
|
|
1944
|
+
)
|
|
1945
|
+
|
|
1946
|
+
updated_paypal_account = Braintree::PayPalAccount.find(original_token)
|
|
1947
|
+
expect(updated_paypal_account).to be_default
|
|
1948
|
+
end
|
|
1949
|
+
|
|
1950
|
+
it "returns an error if a token for account is used to attempt an update" do
|
|
1951
|
+
customer = Braintree::Customer.create!
|
|
1952
|
+
first_token = random_payment_method_token
|
|
1953
|
+
second_token = random_payment_method_token
|
|
1954
|
+
|
|
1955
|
+
first_nonce = nonce_for_paypal_account(
|
|
1956
|
+
:consent_code => "consent-code",
|
|
1957
|
+
:token => first_token,
|
|
1958
|
+
)
|
|
1959
|
+
Braintree::PaymentMethod.create(
|
|
1960
|
+
:payment_method_nonce => first_nonce,
|
|
1961
|
+
:customer_id => customer.id,
|
|
1962
|
+
)
|
|
1963
|
+
|
|
1964
|
+
second_nonce = nonce_for_paypal_account(
|
|
1965
|
+
:consent_code => "consent-code",
|
|
1966
|
+
:token => second_token,
|
|
1967
|
+
)
|
|
1968
|
+
Braintree::PaymentMethod.create(
|
|
1969
|
+
:payment_method_nonce => second_nonce,
|
|
1970
|
+
:customer_id => customer.id,
|
|
1971
|
+
)
|
|
1972
|
+
|
|
1973
|
+
updated_result = Braintree::PaymentMethod.update(
|
|
1974
|
+
first_token,
|
|
1975
|
+
:token => second_token,
|
|
1976
|
+
)
|
|
1977
|
+
|
|
1978
|
+
expect(updated_result).not_to be_success
|
|
1979
|
+
expect(updated_result.errors.first.code).to eq("92906")
|
|
1980
|
+
end
|
|
1981
|
+
end
|
|
1982
|
+
end
|
|
1983
|
+
|
|
1984
|
+
describe "self.update!" do
|
|
1985
|
+
it "updates the credit card" do
|
|
1986
|
+
customer = Braintree::Customer.create!
|
|
1987
|
+
credit_card = Braintree::CreditCard.create!(
|
|
1988
|
+
:cardholder_name => "Original Holder",
|
|
1989
|
+
:customer_id => customer.id,
|
|
1990
|
+
:cvv => "123",
|
|
1991
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1992
|
+
:expiration_date => "05/2012",
|
|
1993
|
+
)
|
|
1994
|
+
payment_method = Braintree::PaymentMethod.update!(credit_card.token,
|
|
1995
|
+
:cardholder_name => "New Holder",
|
|
1996
|
+
:cvv => "456",
|
|
1997
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
|
1998
|
+
:expiration_date => "06/2013",
|
|
1999
|
+
)
|
|
2000
|
+
expect(payment_method).to eq(credit_card)
|
|
2001
|
+
expect(payment_method.cardholder_name).to eq("New Holder")
|
|
2002
|
+
expect(payment_method.bin).to eq(Braintree::Test::CreditCardNumbers::MasterCard[0, 6])
|
|
2003
|
+
expect(payment_method.last_4).to eq(Braintree::Test::CreditCardNumbers::MasterCard[-4..-1])
|
|
2004
|
+
expect(payment_method.expiration_date).to eq("06/2013")
|
|
2005
|
+
end
|
|
2006
|
+
end
|
|
2007
|
+
|
|
2008
|
+
context "payment method grant and revoke" do
|
|
2009
|
+
before(:each) do
|
|
2010
|
+
@partner_merchant_gateway = Braintree::Gateway.new(
|
|
2011
|
+
:merchant_id => "integration_merchant_public_id",
|
|
2012
|
+
:public_key => "oauth_app_partner_user_public_key",
|
|
2013
|
+
:private_key => "oauth_app_partner_user_private_key",
|
|
2014
|
+
:environment => Braintree::Configuration.environment,
|
|
2015
|
+
:logger => Logger.new("/dev/null"),
|
|
2016
|
+
)
|
|
2017
|
+
customer = @partner_merchant_gateway.customer.create(
|
|
2018
|
+
:first_name => "Joe",
|
|
2019
|
+
:last_name => "Brown",
|
|
2020
|
+
:company => "ExampleCo",
|
|
2021
|
+
:email => "joe@example.com",
|
|
2022
|
+
:phone => "312.555.1234",
|
|
2023
|
+
:fax => "614.555.5678",
|
|
2024
|
+
:website => "www.example.com",
|
|
2025
|
+
).customer
|
|
2026
|
+
@credit_card = @partner_merchant_gateway.credit_card.create(
|
|
2027
|
+
:customer_id => customer.id,
|
|
2028
|
+
:cardholder_name => "Adam Davis",
|
|
2029
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
2030
|
+
:expiration_date => "05/2009",
|
|
2031
|
+
).credit_card
|
|
2032
|
+
|
|
2033
|
+
@oauth_gateway = Braintree::Gateway.new(
|
|
2034
|
+
:client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
|
|
2035
|
+
:client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
|
|
2036
|
+
:logger => Logger.new("/dev/null"),
|
|
2037
|
+
)
|
|
2038
|
+
access_token = Braintree::OAuthTestHelper.create_token(@oauth_gateway, {
|
|
2039
|
+
:merchant_public_id => "integration_merchant_id",
|
|
2040
|
+
:scope => "grant_payment_method"
|
|
2041
|
+
}).credentials.access_token
|
|
2042
|
+
|
|
2043
|
+
@granting_gateway = Braintree::Gateway.new(
|
|
2044
|
+
:access_token => access_token,
|
|
2045
|
+
:logger => Logger.new("/dev/null"),
|
|
2046
|
+
)
|
|
2047
|
+
end
|
|
2048
|
+
|
|
2049
|
+
describe "self.grant" do
|
|
2050
|
+
it "returns an error result when the grant doesn't succeed" do
|
|
2051
|
+
grant_result = @granting_gateway.payment_method.grant("payment_method_from_grant", true)
|
|
2052
|
+
expect(grant_result).not_to be_success
|
|
2053
|
+
end
|
|
2054
|
+
|
|
2055
|
+
it "returns a nonce that is transactable by a partner merchant exactly once" do
|
|
2056
|
+
grant_result = @granting_gateway.payment_method.grant(@credit_card.token, :allow_vaulting => false)
|
|
2057
|
+
expect(grant_result).to be_success
|
|
2058
|
+
|
|
2059
|
+
result = Braintree::Transaction.sale(
|
|
2060
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
|
2061
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
2062
|
+
)
|
|
2063
|
+
expect(result).to be_success
|
|
2064
|
+
|
|
2065
|
+
result2 = Braintree::Transaction.sale(
|
|
2066
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
|
2067
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
2068
|
+
)
|
|
2069
|
+
expect(result2).not_to be_success
|
|
2070
|
+
end
|
|
2071
|
+
|
|
2072
|
+
it "returns a nonce that is not vaultable" do
|
|
2073
|
+
grant_result = @granting_gateway.payment_method.grant(@credit_card.token, false)
|
|
2074
|
+
|
|
2075
|
+
customer_result = Braintree::Customer.create()
|
|
2076
|
+
|
|
2077
|
+
result = Braintree::PaymentMethod.create(
|
|
2078
|
+
:customer_id => customer_result.customer.id,
|
|
2079
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
|
2080
|
+
)
|
|
2081
|
+
expect(result).not_to be_success
|
|
2082
|
+
end
|
|
2083
|
+
|
|
2084
|
+
it "returns a nonce that is vaultable" do
|
|
2085
|
+
grant_result = @granting_gateway.payment_method.grant(@credit_card.token, :allow_vaulting => true)
|
|
2086
|
+
|
|
2087
|
+
customer_result = Braintree::Customer.create()
|
|
2088
|
+
|
|
2089
|
+
result = Braintree::PaymentMethod.create(
|
|
2090
|
+
:customer_id => customer_result.customer.id,
|
|
2091
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
|
2092
|
+
)
|
|
2093
|
+
expect(result).to be_success
|
|
2094
|
+
end
|
|
2095
|
+
|
|
2096
|
+
it "raises an error if the token isn't found" do
|
|
2097
|
+
expect do
|
|
2098
|
+
@granting_gateway.payment_method.grant("not_a_real_token", false)
|
|
2099
|
+
end.to raise_error(Braintree::NotFoundError)
|
|
2100
|
+
end
|
|
2101
|
+
|
|
2102
|
+
it "returns a valid nonce with no options set" do
|
|
2103
|
+
expect do
|
|
2104
|
+
grant_result = @granting_gateway.payment_method.grant(@credit_card.token)
|
|
2105
|
+
expect(grant_result).to be_success
|
|
2106
|
+
end
|
|
2107
|
+
end
|
|
2108
|
+
end
|
|
2109
|
+
|
|
2110
|
+
describe "self.revoke" do
|
|
2111
|
+
it "raises an error if the token isn't found" do
|
|
2112
|
+
expect do
|
|
2113
|
+
@granting_gateway.payment_method.revoke("not_a_real_token")
|
|
2114
|
+
end.to raise_error(Braintree::NotFoundError)
|
|
2115
|
+
end
|
|
2116
|
+
|
|
2117
|
+
it "renders a granted nonce useless" do
|
|
2118
|
+
grant_result = @granting_gateway.payment_method.grant(@credit_card.token)
|
|
2119
|
+
revoke_result = @granting_gateway.payment_method.revoke(@credit_card.token)
|
|
2120
|
+
expect(revoke_result).to be_success
|
|
2121
|
+
|
|
2122
|
+
customer_result = Braintree::Customer.create()
|
|
2123
|
+
|
|
2124
|
+
result = Braintree::PaymentMethod.create(
|
|
2125
|
+
:customer_id => customer_result.customer.id,
|
|
2126
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
|
2127
|
+
)
|
|
2128
|
+
expect(result).not_to be_success
|
|
2129
|
+
end
|
|
2130
|
+
|
|
2131
|
+
it "renders a granted nonce obtained uisng options hash, useless" do
|
|
2132
|
+
grant_result = @granting_gateway.payment_method.grant(@credit_card.token, :allow_vaulting => true)
|
|
2133
|
+
revoke_result = @granting_gateway.payment_method.revoke(@credit_card.token)
|
|
2134
|
+
expect(revoke_result).to be_success
|
|
2135
|
+
|
|
2136
|
+
customer_result = Braintree::Customer.create()
|
|
2137
|
+
|
|
2138
|
+
result = Braintree::PaymentMethod.create(
|
|
2139
|
+
:customer_id => customer_result.customer.id,
|
|
2140
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
|
2141
|
+
)
|
|
2142
|
+
expect(result).not_to be_success
|
|
2143
|
+
end
|
|
2144
|
+
end
|
|
2145
|
+
end
|
|
2146
|
+
end
|