function testCreate_fromPaymentMethodToken() { $customer = Braintree_Customer::createNoValidate(); $card = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard; $result = Braintree_PaymentMethodNonce::create($card->token); $this->assertTrue($result->success); $this->assertNotNull($result->paymentMethodNonce); $this->assertNotNull($result->paymentMethodNonce->nonce); }
function test_createdAt() { $customer = Braintree_Customer::createNoValidate(); $past = clone $customer->createdAt; $past->modify("-1 hour"); $future = clone $customer->createdAt; $future->modify("+1 hour"); $collection = Braintree_Customer::search(array(Braintree_CustomerSearch::id()->is($customer->id), Braintree_CustomerSearch::createdAt()->between($past, $future))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($customer->id, $collection->firstItem()->id); $collection = Braintree_Customer::search(array(Braintree_CustomerSearch::id()->is($customer->id), Braintree_CustomerSearch::createdAt()->lessThanOrEqualTo($future))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($customer->id, $collection->firstItem()->id); $collection = Braintree_Customer::search(array(Braintree_CustomerSearch::id()->is($customer->id), Braintree_CustomerSearch::createdAt()->greaterThanOrEqualTo($past))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($customer->id, $collection->firstItem()->id); }
function testUnknownCardTypeIndicators() { $customer = Braintree_Customer::createNoValidate(); $result = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::UNKNOWN, 'expirationDate' => '05/12', 'options' => array('verifyCard' => true))); $this->assertEquals(Braintree_CreditCard::PREPAID_UNKNOWN, $result->creditCard->prepaid); $this->assertEquals(Braintree_CreditCard::DURBIN_REGULATED_UNKNOWN, $result->creditCard->durbinRegulated); $this->assertEquals(Braintree_CreditCard::PAYROLL_UNKNOWN, $result->creditCard->payroll); $this->assertEquals(Braintree_CreditCard::DEBIT_UNKNOWN, $result->creditCard->debit); $this->assertEquals(Braintree_CreditCard::HEALTHCARE_UNKNOWN, $result->creditCard->healthcare); $this->assertEquals(Braintree_CreditCard::COMMERCIAL_UNKNOWN, $result->creditCard->commercial); $this->assertEquals(Braintree_CreditCard::COUNTRY_OF_ISSUANCE_UNKNOWN, $result->creditCard->countryOfIssuance); $this->assertEquals(Braintree_CreditCard::ISSUING_BANK_UNKNOWN, $result->creditCard->issuingBank); }
function test_rangeNode_amount() { $customer = Braintree_Customer::createNoValidate(); $creditCard = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Jane Everywoman' . rand(), 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard; $t_1000 = Braintree_Transaction::saleNoValidate(array('amount' => '1000.00', 'paymentMethodToken' => $creditCard->token)); $t_1500 = Braintree_Transaction::saleNoValidate(array('amount' => '1500.00', 'paymentMethodToken' => $creditCard->token)); $t_1800 = Braintree_Transaction::saleNoValidate(array('amount' => '1800.00', 'paymentMethodToken' => $creditCard->token)); $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->greaterThanOrEqualTo('1700'))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($t_1800->id, $collection->firstItem()->id); $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->lessThanOrEqualTo('1250'))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($t_1000->id, $collection->firstItem()->id); $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->between('1100', '1600'))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($t_1500->id, $collection->firstItem()->id); }
function testCreditNoValidate_throwsIfInvalid() { $customer = Braintree_Customer::createNoValidate(array('creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12'))); $creditCard = $customer->creditCards[0]; $this->setExpectedException('Braintree_Exception_ValidationsFailed'); Braintree_Customer::creditNoValidate($customer->id, array('amount' => 'invalid')); }
function testUpdateNoValidate() { $customer = Braintree_Customer::createNoValidate(); $createdAddress = Braintree_Address::createNoValidate(array('customerId' => $customer->id, 'firstName' => 'Old First', 'lastName' => 'Old Last', 'company' => 'Old Company', 'streetAddress' => '1 E Old St', 'extendedAddress' => 'Apt Old', 'locality' => 'Old Chicago', 'region' => 'Old Region', 'postalCode' => 'Old Postal', 'countryName' => 'United States of America')); $address = Braintree_Address::updateNoValidate($customer->id, $createdAddress->id, array('firstName' => 'New First', 'lastName' => 'New Last', 'company' => 'New Company', 'streetAddress' => '1 E New St', 'extendedAddress' => 'Apt New', 'locality' => 'New Chicago', 'region' => 'New Region', 'postalCode' => 'New Postal', 'countryName' => 'Mexico')); $this->assertEquals('New First', $address->firstName); $this->assertEquals('New Last', $address->lastName); $this->assertEquals('New Company', $address->company); $this->assertEquals('1 E New St', $address->streetAddress); $this->assertEquals('Apt New', $address->extendedAddress); $this->assertEquals('New Chicago', $address->locality); $this->assertEquals('New Region', $address->region); $this->assertEquals('New Postal', $address->postalCode); $this->assertEquals('Mexico', $address->countryName); }
function testDelete_worksWithPayPalAccounts() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); $paypalAccountResult = Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $this->assertTrue($paypalAccountResult->success); Braintree_PaymentMethod::delete($paymentMethodToken); $this->setExpectedException('Braintree_Exception_NotFound'); Braintree_PaymentMethod::find($paymentMethodToken); }
function testCreate_fromPayPalACcount() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $plan = Braintree_SubscriptionTestHelper::triallessPlan(); $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); $paypalResult = Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $subscriptionResult = Braintree_Subscription::create(array('paymentMethodToken' => $paymentMethodToken, 'planId' => $plan['id'])); $this->assertTrue($subscriptionResult->success); $transaction = $subscriptionResult->subscription->transactions[0]; $this->assertEquals('*****@*****.**', $transaction->paypalDetails->payerEmail); }
function testCreate_withVaultedPayPal() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $result = Braintree_Transaction::sale(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'paymentMethodToken' => $paymentMethodToken)); $this->assertTrue($result->success); $transaction = $result->transaction; $this->assertEquals('*****@*****.**', $transaction->paypalDetails->payerEmail); $this->assertNotNull($transaction->paypalDetails->imageUrl); $this->assertNotNull($transaction->paypalDetails->debugId); }
static function createCreditCard() { $customer = Braintree_Customer::createNoValidate(array('creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/2010'))); return $customer->creditCards[0]; }
function testGatewayRejectionIsNullOnProcessorDecline() { $old_merchant_id = Braintree_Configuration::merchantId(); $old_public_key = Braintree_Configuration::publicKey(); $old_private_key = Braintree_Configuration::privateKey(); Braintree_Configuration::merchantId('processing_rules_merchant_id'); Braintree_Configuration::publicKey('processing_rules_public_key'); Braintree_Configuration::privateKey('processing_rules_private_key'); $customer = Braintree_Customer::createNoValidate(); $result = Braintree_CreditCard::create(array('customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/2011', 'cvv' => '200', 'options' => array('verifyCard' => true))); Braintree_Configuration::merchantId($old_merchant_id); Braintree_Configuration::publicKey($old_public_key); Braintree_Configuration::privateKey($old_private_key); $this->assertFalse($result->success); $this->assertNull($result->creditCardVerification->gatewayRejectionReason); }
function testSale_createsASaleUsingGivenToken() { $nonce = Braintree_Test_Nonces::$paypalFuturePayment; $customer = Braintree_Customer::createNoValidate(array('paymentMethodNonce' => $nonce)); $paypalAccount = $customer->paypalAccounts[0]; $result = Braintree_PayPalAccount::sale($paypalAccount->token, array('amount' => '100.00')); $this->assertTrue($result->success); $this->assertEquals('100.00', $result->transaction->amount); $this->assertEquals($customer->id, $result->transaction->customerDetails->id); $this->assertEquals($paypalAccount->token, $result->transaction->paypalDetails->token); }