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);
 }
 /**
  * @param string $subscription_id
  * @param bool $get_payment_method_info
  * @param int $numberOfTransactions
  * @return bool|\stdClass | {status, createdAt, updatedAt, cancelledAt, pastDue, daysPastDue, transactions}
  */
 public function getSubscriptionInfo($subscription_id, $get_payment_method_info = true, $numberOfTransactions = 5)
 {
     $subscription = Braintree_Subscription::find($subscription_id);
     if (!empty($subscription)) {
         $data = new \stdClass();
         $statuses = [Braintree_Subscription::ACTIVE => 'Active', Braintree_Subscription::CANCELED => 'Canceled', Braintree_Subscription::EXPIRED => 'Expired', Braintree_Subscription::PAST_DUE => 'Past due', Braintree_Subscription::PENDING => 'Pending'];
         $data->status = $statuses[$subscription->status];
         $data->createdAt = Carbon::instance($subscription->createdAt);
         $data->updatedAt = Carbon::instance($subscription->updatedAt);
         //The date/time the object was last updated. If a subscription has been cancelled, this value will represent the date/time of cancellation.
         if ($subscription->status == Braintree_Subscription::CANCELED) {
             $data->cancelledAt = Carbon::instance($data->updatedAt);
         } else {
             $data->cancelledAt = null;
         }
         $data->gracePeriod = $this->getGracePeriodFromSubscriptionInstance($subscription);
         $data->currentBillingCycle = $subscription->currentBillingCycle;
         $data->successfullyBilled = $data->currentBillingCycle > 0;
         $data->nextBill = new \stdClass();
         $data->nextBill->date = $subscription->nextBillingDate;
         $data->nextBill->amount = $subscription->nextBillingPeriodAmount;
         //String, The total subscription amount for the next billing period. This amount includes add-ons and discounts but does not include the current balance.
         if ($subscription->status == Braintree_Subscription::PAST_DUE) {
             $data->pastDue = true;
             $data->daysPastDue = $subscription->daysPastDue;
             //int, The number of days that the subscription is past due.
         } else {
             $data->pastDue = false;
             $data->daysPastDue = 0;
         }
         $data->transactions = [];
         $i = 0;
         $transactionStatuses = [Braintree_Transaction::AUTHORIZATION_EXPIRED => 'Authorization expired', Braintree_Transaction::AUTHORIZED => 'Authorized', Braintree_Transaction::AUTHORIZING => 'Authorizing', Braintree_Transaction::GATEWAY_REJECTED => 'Gateway rejected', Braintree_Transaction::FAILED => 'Failed', Braintree_Transaction::PROCESSOR_DECLINED => 'Processor declined', Braintree_Transaction::SETTLED => 'Settled', Braintree_Transaction::SETTLING => 'Settling', Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT => 'Submitted for settlement', Braintree_Transaction::VOIDED => 'Voided', Braintree_Transaction::UNRECOGNIZED => 'Unrecognized', Braintree_Transaction::SETTLEMENT_DECLINED => 'Settlement declined', Braintree_Transaction::SETTLEMENT_PENDING => 'Settlement pending', Braintree_Transaction::SETTLEMENT_CONFIRMED => 'Settlement confirmed'];
         foreach ($subscription->transactions as $transaction) {
             $data->transactions[] = (object) ['status' => $transactionStatuses[$transaction->status], 'amount' => $transaction->amount, 'date' => Carbon::instance($transaction->createdAt), 'credit_card' => (object) ['type' => $transaction->creditCardDetails->cardType, 'last4' => $transaction->creditCardDetails->last4]];
             $i++;
             if ($i >= $numberOfTransactions) {
                 break;
             }
         }
         $subscription->transactions;
         // Array of Braintree_Transaction objects, Transactions associated with the subscription, sorted by creation date with the most recent first.
         if ($get_payment_method_info) {
             $paymentMethod = Braintree_PaymentMethod::find($subscription->paymentMethodToken);
             $data->payment_method = new \stdClass();
             $data->payment_method->credit_card = (object) ['type' => $paymentMethod->cardType, 'last4' => $paymentMethod->last4, 'expiration_month' => $paymentMethod->expirationMonth, 'expiration_year' => $paymentMethod->expirationYear];
             $data->payment_method->billing_address = (object) ['first_name' => $paymentMethod->billingAddress->firstName, 'last_name' => $paymentMethod->billingAddress->lastName, 'address' => $paymentMethod->billingAddress->streetAddress, 'city' => $paymentMethod->billingAddress->locality, 'state' => $paymentMethod->billingAddress->region, 'zip' => $paymentMethod->billingAddress->postalCode];
         }
         return $data;
     }
     return false;
 }
 /**
  * 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 testErrorsOnFindWithWhitespaceCharacterArgument()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree\PaymentMethod::find('\\t');
 }
 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);
 }
Example #7
0
 /**
  * Update customer's credit card.
  *
  * @param string $nonce
  *
  * @return bool
  */
 public function updateCard($nonce)
 {
     $customer = $this->asBraintreeCustomer();
     $result = PaymentMethod::update($customer->paymentMethods[0]->token, ['paymentMethodNonce' => $nonce]);
     if ($result->success) {
         $card = $result->paymentMethod;
         $this->card_brand = $card->cardType;
         $this->card_last_four = $card->last4;
         $this->save();
     }
     return false;
 }
 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);
 }
Example #9
0
 public function deletePaymentMethod()
 {
     $result = PaymentMethod::delete($this->options['paymentMethodToken']);
     if ($result->success) {
         return ['status' => true, 'result' => $result];
     } else {
         return ['status' => false, 'result' => $result];
     }
 }
Example #10
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);
 }
Example #12
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);
 }
 public function testCreate_withOnetimePayPalAndDoesNotVault()
 {
     $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['access_token' => 'PAYPAL_ACCESS_TOKEN', 'token' => $paymentMethodToken]]);
     $result = Braintree\Transaction::sale(['amount' => Braintree\Test\TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce, 'options' => ['storeInVault' => true]]);
     $this->assertTrue($result->success);
     $transaction = $result->transaction;
     $this->assertEquals('*****@*****.**', $transaction->paypalDetails->payerEmail);
     $this->assertNotNull($transaction->paypalDetails->imageUrl);
     $this->assertNotNull($transaction->paypalDetails->debugId);
     $this->setExpectedException('Braintree\\Exception\\NotFound');
     Braintree\PaymentMethod::find($paymentMethodToken);
 }