Пример #1
0
 public function testSale_createsASaleUsingGivenToken()
 {
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = Test\Helper::generateValidUsBankAccountNonce();
     $result = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $nonce]);
     $result = Braintree\UsBankAccount::sale($result->paymentMethod->token, ['merchantAccountId' => 'us_bank_merchant_account', 'amount' => '100.00']);
     $this->assertTrue($result->success);
     $transaction = $result->transaction;
     $this->assertEquals(Braintree\Transaction::SETTLEMENT_PENDING, $transaction->status);
     $this->assertEquals(Braintree\Transaction::SALE, $transaction->type);
     $this->assertEquals('100.00', $transaction->amount);
     $this->assertEquals('021000021', $transaction->usBankAccount->routingNumber);
     $this->assertEquals('1234', $transaction->usBankAccount->last4);
     $this->assertEquals('checking', $transaction->usBankAccount->accountType);
     $this->assertEquals('PayPal Checking - 1234', $transaction->usBankAccount->accountDescription);
     $this->assertEquals('Dan Schulman', $transaction->usBankAccount->accountHolderName);
     $this->assertRegExp('/CHASE/', $transaction->usBankAccount->bankName);
 }
 public function testDelete()
 {
     $paymentMethodToken = 'PAYPALToken-' . strval(rand());
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken]]);
     Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $nonce]);
     Braintree\PayPalAccount::delete($paymentMethodToken);
     $this->setExpectedException('Braintree\\Exception\\NotFound');
     Braintree\PayPalAccount::find($paymentMethodToken);
 }
Пример #3
0
 /**
  * Update customer's credit card.
  *
  * @param  string  $token
  * @return void
  */
 public function updateCard($token)
 {
     $customer = $this->asBraintreeCustomer();
     $response = PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $token, 'options' => ['makeDefault' => true, 'verifyCard' => true]]);
     if (!$response->success) {
         throw new Exception('Braintree was unable to create a payment method: ' . $response->message);
     }
     $paypalAccount = $response->paymentMethod instanceof PaypalAccount;
     $this->forceFill(['paypal_email' => $paypalAccount ? $response->paymentMethod->email : null, 'card_brand' => $paypalAccount ? null : $response->paymentMethod->cardType, 'card_last_four' => $paypalAccount ? null : $response->paymentMethod->last4])->save();
     $this->updateSubscriptionsToPaymentMethod($response->paymentMethod->token);
 }
 public function testCreate_throwsIfInvalidKey()
 {
     $this->setExpectedException('InvalidArgumentException', 'invalid keys: invalidKey');
     Braintree\PaymentMethod::create(['invalidKey' => 'foo']);
 }
Пример #5
0
 public function testCreate_fromPayPalACcount()
 {
     $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
     $customer = Braintree\Customer::createNoValidate();
     $plan = SubscriptionHelper::triallessPlan();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken]]);
     $paypalResult = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $nonce]);
     $subscriptionResult = Braintree\Subscription::create(['paymentMethodToken' => $paymentMethodToken, 'planId' => $plan['id']]);
     $this->assertTrue($subscriptionResult->success);
     $transaction = $subscriptionResult->subscription->transactions[0];
     $this->assertEquals('*****@*****.**', $transaction->paypalDetails->payerEmail);
 }
 public function testGrant_returnsANonceThatIsVaultable()
 {
     $partnerMerchantGateway = new Braintree\Gateway(['environment' => 'development', 'merchantId' => 'integration_merchant_public_id', 'publicKey' => 'oauth_app_partner_user_public_key', 'privateKey' => 'oauth_app_partner_user_private_key']);
     $customer = $partnerMerchantGateway->customer()->create(['firstName' => 'Joe', 'lastName' => 'Brown'])->customer;
     $creditCard = $partnerMerchantGateway->creditCard()->create(['customerId' => $customer->id, 'cardholderName' => 'Adam Davis', 'number' => '4111111111111111', 'expirationDate' => '05/2009'])->creditCard;
     $oauthAppGateway = new Braintree\Gateway(['clientId' => 'client_id$development$integration_client_id', 'clientSecret' => 'client_secret$development$integration_client_secret']);
     $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, ['merchant_public_id' => 'integration_merchant_id', 'scope' => 'grant_payment_method']);
     $credentials = $oauthAppGateway->oauth()->createTokenFromCode(['code' => $code]);
     $grantingGateway = new Braintree\Gateway(['accessToken' => $credentials->accessToken]);
     $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, true);
     $customer = Braintree\Customer::create(['firstName' => 'Bob', 'lastName' => 'Rob'])->customer;
     $result = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $grantResult->nonce]);
     $this->assertTrue($result->success);
 }
Пример #7
0
 public function savePaymentMethod()
 {
     $result = PaymentMethod::create($this->options['paymentMethod']);
     if ($result->success) {
         return ['status' => true, 'result' => $result];
     } else {
         return ['status' => false, 'result' => $result];
     }
 }
Пример #8
0
 /**
  * Update customer's credit card.
  *
  * @param string $token
  * @param array $options
  *
  * @throws Exception
  */
 public function updateCard($token, array $options = [])
 {
     $customer = $this->asBraintreeCustomer();
     $response = PaymentMethod::create(array_replace_recursive(['customerId' => $customer->id, 'paymentMethodNonce' => $token, 'options' => ['makeDefault' => true, 'verifyCard' => true]], $options));
     if (!$response->success) {
         throw new Exception('Braintree was unable to create a payment method: ' . $response->message);
     }
     $paypalAccount = $response->paymentMethod instanceof PayPalAccount;
     $this->paypalEmail = $paypalAccount ? $response->paymentMethod->email : null;
     $this->cardBrand = $paypalAccount ? null : $response->paymentMethod->cardType;
     $this->cardLastFour = $paypalAccount ? null : $response->paymentMethod->last4;
     $this->save();
     $this->updateSubscriptionsToPaymentMethod($response->paymentMethod->token);
 }
 public function testDelete_worksWithPayPalAccounts()
 {
     $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->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);
 }
Пример #10
0
 public function testUpdateDefaultPaymentMethodFromOptions()
 {
     $result = Braintree\Customer::create(['firstName' => 'Old First', 'lastName' => 'Old Last']);
     $this->assertEquals(true, $result->success);
     $customer = $result->customer;
     $token1 = 'TOKEN-' . strval(rand());
     $result = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => Braintree\Test\Nonces::$transactableVisa, 'token' => $token1]);
     $updateResult = Braintree\Customer::update($customer->id, ['creditCard' => ['options' => ['updateExistingToken' => $token1, 'makeDefault' => true]]]);
     $this->assertEquals(true, $updateResult->success);
     $this->assertEquals($updateResult->customer->defaultPaymentMethod()->token, $token1);
     $token2 = 'TOKEN-' . strval(rand());
     $result = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => Braintree\Test\Nonces::$transactableMasterCard, 'token' => $token2]);
     $updateResult = Braintree\Customer::update($customer->id, ['creditCard' => ['options' => ['updateExistingToken' => $token2, 'makeDefault' => true]]]);
     $this->assertEquals(true, $updateResult->success);
     $this->assertEquals($updateResult->customer->defaultPaymentMethod()->token, $token2);
 }
Пример #11
0
 public function testCreate_withVaultedPayPal()
 {
     $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken]]);
     Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $nonce]);
     $result = Braintree\Transaction::sale(['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);
 }