def test_update_updates_a_paypal_accounts_token(self): customer_id = Customer.create().customer.id first_token = "paypal-account-" + str(randint(0,100000000)) second_token = "paypal-account-" + str(randint(0,100000000)) first_nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": first_token }) first_result = PaymentMethod.create({ "payment_method_nonce": first_nonce, "customer_id": customer_id }) second_nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": second_token }) second_result = PaymentMethod.create({ "payment_method_nonce": second_nonce, "customer_id": customer_id }) updated_result = PaymentMethod.update( first_token, {"token": second_token} ) self.assertTrue(updated_result.is_success == False) self.assertTrue(updated_result.errors.deep_errors[0].code == "92906")
def test_update_updates_a_paypal_accounts_token(self): customer_id = Customer.create().customer.id first_token = "paypal-account-" + str(randint(0, 100000000)) second_token = "paypal-account-" + str(randint(0, 100000000)) first_nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": first_token }) first_result = PaymentMethod.create({ "payment_method_nonce": first_nonce, "customer_id": customer_id }) second_nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": second_token }) second_result = PaymentMethod.create({ "payment_method_nonce": second_nonce, "customer_id": customer_id }) updated_result = PaymentMethod.update(first_token, {"token": second_token}) self.assertTrue(updated_result.is_success == False) self.assertTrue(updated_result.errors.deep_errors[0].code == "92906")
def test_update_can_make_a_paypal_account_the_default_payment_method(self): customer_id = Customer.create().customer.id credit_card_result = CreditCard.create({ "customer_id": customer_id, "number": CreditCardNumbers.Visa, "expiration_date": "05/2009", "options": {"make_default": "true"} }) self.assertTrue(credit_card_result.is_success) nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code" }) original_token = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id }).payment_method.token updated_result = PaymentMethod.update( original_token, {"options": {"make_default": "true"}} ) updated_paypal_account = PayPalAccount.find(original_token) self.assertTrue(updated_paypal_account.default == True)
def test_update_can_make_a_paypal_account_the_default_payment_method(self): customer_id = Customer.create().customer.id credit_card_result = CreditCard.create({ "customer_id": customer_id, "number": CreditCardNumbers.Visa, "expiration_date": "05/2009", "options": { "make_default": "true" } }) self.assertTrue(credit_card_result.is_success) nonce = Nonces.nonce_for_paypal_account( {"consent_code": "consent-code"}) original_token = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id }).payment_method.token updated_result = PaymentMethod.update( original_token, {"options": { "make_default": "true" }}) updated_paypal_account = PayPalAccount.find(original_token) self.assertTrue(updated_paypal_account.default == True)
def test_find_returns_subscriptions_associated_with_a_paypal_account(self): customer_id = Customer.create().customer.id payment_method_token = "paypal-account-" + str(int(time.time())) nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": payment_method_token }) result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id }) self.assertTrue(result.is_success) token = result.payment_method.token subscription1 = Subscription.create({ "payment_method_token": token, "plan_id": TestHelper.trialless_plan["id"] }).subscription subscription2 = Subscription.create({ "payment_method_token": token, "plan_id": TestHelper.trialless_plan["id"] }).subscription paypal_account = PayPalAccount.find(result.payment_method.token) self.assertTrue(subscription1.id in [s.id for s in paypal_account.subscriptions]) self.assertTrue(subscription2.id in [s.id for s in paypal_account.subscriptions])
def test_create_for_paypal_ignores_passed_billing_address_id(self): nonce = Nonces.nonce_for_paypal_account( {"consent_code": "consent-code"}) customer_id = Customer.create().customer.id result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id, "billing_address_id": "address_id" }) self.assertTrue(result.is_success) self.assertTrue(isinstance(result.payment_method, PayPalAccount)) self.assertFalse(result.payment_method.image_url is None) token = result.payment_method.token found_paypal_account = PayPalAccount.find(token) self.assertFalse(found_paypal_account is None)
def test_create_for_paypal_ignores_passed_billing_address_id(self): nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code" }) customer_id = Customer.create().customer.id result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id, "billing_address_id": "address_id" }) self.assertTrue(result.is_success) self.assertTrue(type(result.payment_method) is PayPalAccount) self.assertFalse(result.payment_method.image_url == None) token = result.payment_method.token found_paypal_account = PayPalAccount.find(token) self.assertFalse(found_paypal_account == None)
def test_create_does_not_return_an_error_if_credit_card_options_are_present_for_paypal_nonce(self): customer_id = Customer.create().customer.id original_token = "paypal-account-" + str(int(time.time())) nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": original_token }) result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id, "options": { "verify_card": "true", "fail_on_duplicate_payment_method": "true", "verification_merchant_account_id": "not_a_real_merchant_account_id" } }) self.assertTrue(result.is_success)
def test_create_for_paypal_ignores_passed_billing_address_params(self): nonce = Nonces.nonce_for_paypal_account( {"consent_code": "PAYPAL_CONSENT_CODE"}) customer_id = Customer.create().customer.id result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id, "billing_address": { "street_address": "123 Abc Way" } }) self.assertTrue(result.is_success) self.assertTrue(type(result.payment_method) is PayPalAccount) self.assertFalse(result.payment_method.image_url == None) token = result.payment_method.token found_paypal_account = PayPalAccount.find(token) self.assertFalse(found_paypal_account == None)
def test_update_updates_a_paypal_accounts_token(self): customer_id = Customer.create().customer.id original_token = "paypal-account-" + str(int(time.time())) nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": original_token }) original_result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id }) updated_token = "UPDATED_TOKEN-" + str(randint(0, 100000000)) updated_result = PaymentMethod.update(original_token, {"token": updated_token}) updated_paypal_account = PayPalAccount.find(updated_token) self.assertTrue(updated_paypal_account.email == original_result.payment_method.email) self.assertRaises(NotFoundError, PaymentMethod.find, original_token)
def test_update_updates_a_paypal_accounts_token(self): customer_id = Customer.create().customer.id original_token = "paypal-account-" + str(int(time.time())) nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": original_token }) original_result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id }) updated_token = "UPDATED_TOKEN-" + str(randint(0,100000000)) updated_result = PaymentMethod.update( original_token, {"token": updated_token} ) updated_paypal_account = PayPalAccount.find(updated_token) self.assertTrue(updated_paypal_account.email == original_result.payment_method.email) self.assertRaises(NotFoundError, PaymentMethod.find, original_token)
def test_create_does_not_return_an_error_if_credit_card_options_are_present_for_paypal_nonce( self): customer_id = Customer.create().customer.id original_token = "paypal-account-" + str(int(time.time())) nonce = Nonces.nonce_for_paypal_account({ "consent_code": "consent-code", "token": original_token }) result = PaymentMethod.create({ "payment_method_nonce": nonce, "customer_id": customer_id, "options": { "verify_card": "true", "fail_on_duplicate_payment_method": "true", "verification_merchant_account_id": "not_a_real_merchant_account_id" } }) self.assertTrue(result.is_success)