public function testCreate_fromPaymentMethodToken() { $customer = Braintree\Customer::createNoValidate(); $card = Braintree\CreditCard::create(['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); }
public function test_GatewayRespectsMakeDefault() { $result = Braintree\Customer::create(); $this->assertTrue($result->success); $customerId = $result->customer->id; $result = Braintree\CreditCard::create(array('customerId' => $customerId, 'number' => '4111111111111111', 'expirationDate' => '11/2099')); $this->assertTrue($result->success); $clientToken = Test\Helper::decodedClientToken(array("customerId" => $customerId, "options" => array("makeDefault" => true))); $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint; $http = new HttpClientApi(Braintree\Configuration::$global); $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode(array("credit_card" => array("number" => "4242424242424242", "expirationDate" => "11/2099"), "authorization_fingerprint" => $authorizationFingerprint, "shared_customer_identifier" => "fake_identifier", "shared_customer_identifier_type" => "testing"))); $this->assertEquals(201, $response["status"]); $customer = Braintree\Customer::find($customerId); $this->assertEquals(2, count($customer->creditCards)); foreach ($customer->creditCards as $creditCard) { if ($creditCard->last4 == "4242") { $this->assertTrue($creditCard->default); } } }
public function testUpdateAndMakeDefault() { $customer = Braintree\Customer::createNoValidate(); $creditCardResult = Braintree\CreditCard::create(['customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/12']); $this->assertTrue($creditCardResult->success); $http = new HttpClientApi(Braintree\Configuration::$global); $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'PAYPAL_CONSENT_CODE']]); $createResult = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $nonce]); $this->assertTrue($createResult->success); $updateResult = Braintree\PayPalAccount::update($createResult->paymentMethod->token, ['options' => ['makeDefault' => true]]); $this->assertTrue($updateResult->success); $this->assertTrue($updateResult->paypalAccount->isDefault()); }
public function testCreate_throwsIfInvalidKey() { $this->setExpectedException('InvalidArgumentException', 'invalid keys: invalidKey'); Braintree\CreditCard::create(['invalidKey' => 'foo']); }
public function testUnknownCardTypeIndicators() { $customer = Braintree\Customer::createNoValidate(); $result = Braintree\CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => 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); }
public function testDelete_worksWithCreditCards() { $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand()); $customer = Braintree\Customer::createNoValidate(); $creditCardResult = Braintree\CreditCard::create(['customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/2011', 'token' => $paymentMethodToken]); $this->assertTrue($creditCardResult->success); Braintree\PaymentMethod::delete($paymentMethodToken); $this->setExpectedException('Braintree\\Exception\\NotFound'); Braintree\PaymentMethod::find($paymentMethodToken); self::integrationMerchantConfig(); }
/** * @param User $user * @param $request * @return boolean */ public function addCard(User $user, $request) { $result = BraintreeCreditCard::create(["customerId" => $this->getCustomerId($user), "number" => $request->request->get("number"), "cvv" => $request->request->get("cvv"), "expirationMonth" => $request->request->get("month"), "expirationYear" => $request->request->get("year")]); return $result->success; }
public function test_rangeNode_amount() { $customer = Braintree\Customer::createNoValidate(); $creditCard = Braintree\CreditCard::create(['customerId' => $customer->id, 'cardholderName' => 'Jane Everywoman' . rand(), 'number' => '5105105105105100', 'expirationDate' => '05/12'])->creditCard; $t_1000 = Braintree\Transaction::saleNoValidate(['amount' => '1000.00', 'paymentMethodToken' => $creditCard->token]); $t_1500 = Braintree\Transaction::saleNoValidate(['amount' => '1500.00', 'paymentMethodToken' => $creditCard->token]); $t_1800 = Braintree\Transaction::saleNoValidate(['amount' => '1800.00', 'paymentMethodToken' => $creditCard->token]); $collection = Braintree\Transaction::search([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([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([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); }
public function testUpdateCreditCardFromTransparentRedirect() { $customer = Braintree\Customer::create(array('firstName' => 'Mike', 'lastName' => 'Jonez'))->customer; $creditCard = Braintree\CreditCard::create(array('customerId' => $customer->id, 'number' => Braintree\Test\CreditCardNumbers::$masterCard, 'expirationMonth' => '10', 'expirationYear' => '10'))->creditCard; $params = array('credit_card' => array('number' => Braintree\Test\CreditCardNumbers::$visa)); $trParams = array('paymentMethodToken' => $creditCard->token, 'creditCard' => array('expirationMonth' => '11', 'expirationYear' => '11')); $trData = Braintree\TransparentRedirect::updateCreditCardData(array_merge($trParams, array("redirectUrl" => "http://www.example.com"))); $queryString = Test\Helper::submitTrRequest(Braintree\TransparentRedirect::url(), $params, $trData); Braintree\TransparentRedirect::confirm($queryString); $creditCard = Braintree\CreditCard::find($creditCard->token); $this->assertequals('401288', $creditCard->bin); $this->assertequals('1881', $creditCard->last4); $this->assertequals('11/2011', $creditCard->expirationDate); }
/** * This save credit cart to braintree. * @return array */ public function saveCreditCard() { $sendArray = $this->options['creditCard']; if (isset($this->options['billing'])) { $sendArray['billingAddress'] = $this->options['billing']; } if (isset($this->options['customerId'])) { $sendArray['customerId'] = $this->options['customerId']; } $result = CreditCard::create($sendArray); if ($result->success) { return ['status' => true, 'result' => $result]; } else { return ['status' => false, 'result' => $result]; } }