function testCreateTransactionReturnsPaymentInstrumentType() { $nonce = Braintree_HttpClientApi::nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"), "share" => true)); $result = Braintree_Transaction::sale(array('amount' => '47.00', 'paymentMethodNonce' => $nonce)); $this->assertTrue($result->success); $transaction = $result->transaction; $this->assertEquals(Braintree_PaymentInstrumentType::CREDIT_CARD, $transaction->paymentInstrumentType); }
function testCreateCustomerWithCardUsingNonce() { $nonce = Braintree_HttpClientApi::nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"), "share" => true)); $result = Braintree_Customer::create(array('creditCard' => array('paymentMethodNonce' => $nonce))); $this->assertTrue($result->success); $this->assertSame("411111", $result->customer->creditCards[0]->bin); $this->assertSame("1111", $result->customer->creditCards[0]->last4); }
function testFind_exposesNullThreeDSecureInfoIfNoneExists() { $http = new Braintree_HttpClientApi(Braintree_Configuration::$global); $nonce = $http->nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"))); $foundNonce = Braintree_PaymentMethodNonce::find($nonce); $info = $foundNonce->threeDSecureInfo; $this->assertEquals($nonce, $foundNonce->nonce); $this->assertNull($info); }
function testCreateTransactionUsingNonce() { $nonce = Braintree_HttpClientApi::nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"), "share" => true)); $result = Braintree_Transaction::sale(array('amount' => '47.00', 'paymentMethodNonce' => $nonce)); $this->assertTrue($result->success); $transaction = $result->transaction; $this->assertEquals(Braintree_Transaction::AUTHORIZED, $transaction->status); $this->assertEquals(Braintree_Transaction::SALE, $transaction->type); $this->assertEquals('47.00', $transaction->amount); }
function testFromNonce_ReturnsErrorWhenNonceIsConsumed() { $customer = Braintree_Customer::createNoValidate(); $http = new Braintree_HttpClientApi(Braintree_Configuration::$global); $nonce = $http->nonce_for_new_card(array("credit_card" => array("number" => "4009348888881881", "expirationMonth" => "11", "expirationYear" => "2099"), "customerId" => $customer->id)); Braintree_CreditCard::fromNonce($nonce); $this->setExpectedException('Braintree_Exception_NotFound', "consumed"); Braintree_CreditCard::fromNonce($nonce); }
function testCreate_allowsPassingABillingAddressIdOutsideOfTheNonce() { $customer = Braintree_Customer::createNoValidate(); $nonce = Braintree_HttpClientApi::nonce_for_new_card(array('credit_card' => array('number' => '4111111111111111', 'expirationMonth' => '12', 'expirationYear' => '2020', 'options' => array('validate' => false)))); $address = Braintree_Address::create(array('customerId' => $customer->id, 'firstName' => 'Bobby', 'lastName' => 'Tables'))->address; $result = Braintree_PaymentMethod::create(array('paymentMethodNonce' => $nonce, 'customerId' => $customer->id, 'billingAddressId' => $address->id)); $this->assertTrue($result->success); $this->assertTrue(is_a($result->paymentMethod, 'Braintree_CreditCard')); $token = $result->paymentMethod->token; $foundCreditCard = Braintree_CreditCard::find($token); $this->assertTrue(NULL != $foundCreditCard); $this->assertEquals('Bobby', $foundCreditCard->billingAddress->firstName); $this->assertEquals('Tables', $foundCreditCard->billingAddress->lastName); }
function testUpdate_canUpdatePaymentMethodWithPaymentMethodNonce() { $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard(); $plan = Braintree_SubscriptionTestHelper::triallessPlan(); $subscription = Braintree_Subscription::create(array('paymentMethodToken' => $oldCreditCard->token, 'price' => '54.99', 'planId' => $plan['id']))->subscription; $customerId = Braintree_Customer::create()->customer->id; $nonce = Braintree_HttpClientApi::nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"), "customerId" => $oldCreditCard->customerId, "share" => true)); $result = Braintree_Subscription::update($subscription->id, array('paymentMethodNonce' => $nonce)); $this->assertTrue($result->success); $newCreditCard = Braintree_CreditCard::find($result->subscription->paymentMethodToken); $this->assertEquals("1111", $newCreditCard->last4); $this->assertNotEquals($oldCreditCard->last4, $newCreditCard->last4); }
function testSale_withThreeDSecureOptionRequired() { $http = new Braintree_HttpClientApi(Braintree_Configuration::$global); $nonce = $http->nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"))); $result = Braintree_Transaction::sale(array('merchantAccountId' => Braintree_TestHelper::threeDSecureMerchantAccountId(), 'amount' => '100.00', 'creditCard' => array('number' => '4111111111111111', 'expirationDate' => '05/09'), 'options' => array('three_d_secure' => array('required' => true)))); $this->assertFalse($result->success); $this->assertEquals(Braintree_Transaction::THREE_D_SECURE, $result->transaction->gatewayRejectionReason); }