At minimum, an amount, credit card number, and credit card expiration date are required. Minimalistic example: Transaction::saleNoValidate(array( 'amount' => '100.00', 'creditCard' => array( 'number' => '5105105105105100', 'expirationDate' => '05/12', ), )); Full example: Transaction::saleNoValidate(array( 'amount' => '100.00', 'orderId' => '123', 'channel' => 'MyShoppingCardProvider', 'creditCard' => array( if token is omitted, the gateway will generate a token 'token' => 'credit_card_123', 'number' => '5105105105105100', 'expirationDate' => '05/2011', 'cvv' => '123', ), 'customer' => array( if id is omitted, the gateway will generate an id 'id' => 'customer_123', 'firstName' => 'Dan', 'lastName' => 'Smith', 'company' => 'Braintree', 'email' => 'dan@example.com', 'phone' => '419-555-1234', 'fax' => '419-555-1235', 'website' => 'http://braintreepayments.com' ), 'billing' => array( 'firstName' => 'Carl', 'lastName' => 'Jones', 'company' => 'Braintree', 'streetAddress' => '123 E Main St', 'extendedAddress' => 'Suite 403', 'locality' => 'Chicago', 'region' => 'IL', 'postalCode' => '60622', 'countryName' => 'United States of America' ), 'shipping' => array( 'firstName' => 'Andrew', 'lastName' => 'Mason', 'company' => 'Braintree', 'streetAddress' => '456 W Main St', 'extendedAddress' => 'Apt 2F', 'locality' => 'Bartlett', 'region' => 'IL', 'postalCode' => '60103', 'countryName' => 'United States of America' ), 'customFields' => array( 'birthdate' => '11/13/1954' ) ) == Storing in the Vault == The customer and credit card information used for a transaction can be stored in the vault by setting transaction[options][storeInVault] to true. $transaction = Transaction::saleNoValidate(array( 'customer' => array( 'firstName' => 'Adam', 'lastName' => 'Williams' ), 'creditCard' => array( 'number' => '5105105105105100', 'expirationDate' => '05/2012' ), 'options' => array( 'storeInVault' => true ) )); echo $transaction->customerDetails->id '865534' echo $transaction->creditCardDetails->token '6b6m' To also store the billing address in the vault, pass the addBillingAddressToPaymentMethod option. Transaction.saleNoValidate(array( ... 'options' => array( 'storeInVault' => true 'addBillingAddressToPaymentMethod' => true ) )); == Submitting for Settlement== This can only be done when the transction's status is authorized. If amount is not specified, the full authorized amount will be settled. If you would like to settle less than the full authorized amount, pass the desired amount. You cannot settle more than the authorized amount. A transaction can be submitted for settlement when created by setting $transaction[options][submitForSettlement] to true. $transaction = Transaction::saleNoValidate(array( 'amount' => '100.00', 'creditCard' => array( 'number' => '5105105105105100', 'expirationDate' => '05/2012' ), 'options' => array( 'submitForSettlement' => true ) )); == More information == For more detailed information on Transactions, see {@link http://www.braintreepayments.com/gateway/transaction-api http://www.braintreepaymentsolutions.com/gateway/transaction-api}
상속: extends braintree\Base
예제 #1
1
 public function testIsset()
 {
     $t = Braintree\Transaction::factory(['creditCard' => ['expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100'], 'customer' => [], 'billing' => [], 'descriptor' => [], 'shipping' => [], 'subscription' => ['billingPeriodStartDate' => '1983-07-12'], 'statusHistory' => []]);
     $this->assertTrue(isset($t->creditCard));
     $this->assertFalse(empty($t->creditCard));
 }
예제 #2
0
 /**
  * overrides default constructor
  * @ignore
  * @param array $response gateway response array
  */
 public function __construct($response)
 {
     $this->_attributes = $response;
     $this->_set('errors', new ErrorCollection($response['errors']));
     if (isset($response['verification'])) {
         $this->_set('creditCardVerification', new CreditCardVerification($response['verification']));
     } else {
         $this->_set('creditCardVerification', null);
     }
     if (isset($response['transaction'])) {
         $this->_set('transaction', Transaction::factory($response['transaction']));
     } else {
         $this->_set('transaction', null);
     }
     if (isset($response['subscription'])) {
         $this->_set('subscription', Subscription::factory($response['subscription']));
     } else {
         $this->_set('subscription', null);
     }
     if (isset($response['merchantAccount'])) {
         $this->_set('merchantAccount', MerchantAccount::factory($response['merchantAccount']));
     } else {
         $this->_set('merchantAccount', null);
     }
 }
예제 #3
0
 public function test__isset()
 {
     $transaction = Braintree\Transaction::factory(['creditCard' => ['expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100', 'cardType' => 'MasterCard']]);
     $this->assertEquals('MasterCard', $transaction->creditCardDetails->cardType);
     $this->assertFalse(empty($transaction->creditCardDetails->cardType));
     $this->assertTrue(isset($transaction->creditCardDetails->cardType));
     $transaction = Braintree\Transaction::factory(['creditCard' => ['expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100']]);
     $this->assertTrue(empty($transaction->creditCardDetails->cardType));
     $this->assertFalse(isset($transaction->creditCardDetails->cardType));
 }
 public function testGenerate_canBeGroupedByACustomField()
 {
     $transaction = Braintree\Transaction::saleNoValidate(['amount' => '100.00', 'creditCard' => ['number' => '5105105105105100', 'expirationDate' => '05/12'], 'customFields' => ['store_me' => 'custom value'], 'options' => ['submitForSettlement' => true]]);
     Braintree\Test\Transaction::settle($transaction->id);
     $today = new Datetime();
     $result = Braintree\SettlementBatchSummary::generate(Test\Helper::nowInEastern(), 'store_me');
     $this->assertTrue($result->success);
     $this->assertTrue(count($result->settlementBatchSummary->records) > 0);
     $this->assertArrayHasKey('store_me', $result->settlementBatchSummary->records[0]);
 }
 public function testHandle()
 {
     $paymentDO = $this->getMock(PaymentDataObjectInterface::class);
     $paymentInfo = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock();
     $handlingSubject = ['payment' => $paymentDO];
     $transaction = \Braintree\Transaction::factory(['id' => 1]);
     $response = ['object' => new \Braintree\Result\Successful($transaction, 'transaction')];
     $subjectReader = $this->getMockBuilder(SubjectReader::class)->disableOriginalConstructor()->getMock();
     $subjectReader->expects(static::once())->method('readPayment')->with($handlingSubject)->willReturn($paymentDO);
     $paymentDO->expects(static::atLeastOnce())->method('getPayment')->willReturn($paymentInfo);
     $subjectReader->expects(static::once())->method('readTransaction')->with($response)->willReturn($transaction);
     $paymentInfo->expects(static::once())->method('setTransactionId')->with(1);
     $paymentInfo->expects(static::once())->method('setIsTransactionClosed')->with(false);
     $paymentInfo->expects(static::once())->method('setShouldCloseParentTransaction')->with(false);
     $handler = new TransactionIdHandler($subjectReader);
     $handler->handle($handlingSubject, $response);
 }
예제 #6
0
 /**
  * Get items
  *
  * @param array $transaction
  * @dataProvider getConfigDataProvider
  */
 public function testGetCustomAttributes($transaction)
 {
     $this->transactionStub = Transaction::factory($transaction);
     $fields = TransactionMap::$simpleFieldsMap;
     $fieldsQty = count($fields);
     $this->attributeValueFactoryMock->expects($this->exactly($fieldsQty))->method('create')->willReturnCallback(function () {
         return new AttributeValue();
     });
     $map = new TransactionMap($this->attributeValueFactoryMock, $this->transactionStub);
     /** @var AttributeValue[] $result */
     $result = $map->getCustomAttributes();
     $this->assertEquals($fieldsQty, count($result));
     $this->assertInstanceOf(AttributeValue::class, $result[1]);
     $this->assertEquals($transaction['id'], $result[0]->getValue());
     $this->assertEquals($transaction['paypalDetails']->paymentId, $result[4]->getValue());
     $this->assertEquals($transaction['createdAt']->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), $result[6]->getValue());
     $this->assertEquals(implode(', ', $transaction['refundIds']), $result[11]->getValue());
 }
 /**
  * Create Braintree transaction
  * @return \Braintree\Transaction
  */
 private function getBraintreeTransaction()
 {
     $attributes = ['creditCard' => ['bin' => '5421', 'cardType' => 'American Express', 'expirationMonth' => 12, 'expirationYear' => 21, 'last4' => 1231]];
     $transaction = Transaction::factory($attributes);
     return $transaction;
 }
 public function testSettlementPending()
 {
     $transaction = Braintree\Transaction::saleNoValidate(['amount' => '100.00', 'creditCard' => ['number' => '5105105105105100', 'expirationDate' => '05/12'], 'options' => ['submitForSettlement' => true]]);
     $transaction = Braintree\Test\Transaction::settlementPending($transaction->id);
     $this->assertEquals('settlement_pending', $transaction->status);
 }
 public function createSale($nonce, $price, $fname, $lname, $address, $city, $state, $zip, $merchantAccountId)
 {
     $result = Braintree_Transaction::sale(['amount' => $price, 'merchantAccountId' => $merchantAccountId, 'paymentMethodNonce' => $nonce, 'billing' => ['firstName' => $fname, 'lastName' => $lname, 'streetAddress' => $address, 'locality' => $city, 'region' => $state, 'postalCode' => $zip], 'options' => ['submitForSettlement' => True]]);
     /*
     echo "<hr>";
     print_r($result);
     echo "<hr>";
     */
     return $result;
     /**
     * $result->success
     		# true
     
     		$result->transaction->status
     		# e.g. 'submitted_for_settlement'
     
     		$result->transaction->type
     */
     /**
     		"authorization_expired"
     		"authorized"
     		"authorizing"
     		"settlement_pending"
     		"settlement_confirmed"
     		"settlement_declined"
     		"failed"
     		"gateway_rejected"
     		"processor_declined"
     		"settled"
     		"settling"
     		"submitted_for_settlement"
     		"voided"
     */
 }
예제 #10
0
 public function retryChargeSubscription($subscriptionId, $amount)
 {
     $retryResult = Subscription::retryCharge($subscriptionId, $amount);
     if ($retryResult->success) {
         $result = Transaction::submitForSettlement($retryResult->transaction->id);
         return $result;
     }
     return $retryResult;
 }
예제 #11
0
 /**
  * Get a collection of the entity's invoices.
  *
  * @param  bool  $includePending
  * @param  array  $parameters
  * @return \Illuminate\Support\Collection
  */
 public function invoices($includePending = false, $parameters = [])
 {
     $invoices = [];
     $customer = $this->asBraintreeCustomer();
     $parameters = array_merge([TransactionSearch::customerId()->is($customer->id), TransactionSearch::createdAt()->between(Carbon::today()->subYears(2)->format('m/d/Y H:s'), Carbon::tomorrow()->format('m/d/Y H:s'))], $parameters);
     $transactions = BraintreeTransaction::search($parameters);
     // Here we will loop through the Braintree invoices and create our own custom Invoice
     // instance that gets more helper methods and is generally more convenient to work
     // work than the plain Braintree objects are. Then, we'll return the full array.
     if (!is_null($transactions)) {
         foreach ($transactions as $transaction) {
             if ($transaction->status == BraintreeTransaction::SETTLED || $includePending) {
                 $invoices[] = new Invoice($this, $transaction);
             }
         }
     }
     return new Collection($invoices);
 }
예제 #12
0
파일: Braintree.php 프로젝트: pckg/payment
 public function postStartPartial()
 {
     $payment = (new BraintreeEntity())->where('braintree_hash', router()->get('payment'))->oneOrFail();
     $price = $this->order->getTotal();
     $order = $this->order->getOrder();
     /**
      * @T00D00
      */
     if (false && !$order->getIsConfirmedAttribute()) {
         $order->ordersUser->each(function (OrdersUser $ordersUser) {
             if (!$ordersUser->packet->getAvailableStockAttribute()) {
                 response()->bad('Sold out!');
             }
         });
     }
     $payment->price = $price;
     $payment->save();
     $braintreeNonce = request()->post('payment_method_nonce');
     if (!$braintreeNonce) {
         response()->bad('Missing payment method nonce.');
     }
     if ($braintreeNonce == $payment->braintree_payment_method_nonce) {
         //User pressed F5. Load existing transaction.
         $result = Transaction::find($payment->braintree_transaction_id);
     } else {
         //Create a new transaction
         $transactionSettings = ['amount' => $this->getTotal(), 'paymentMethodNonce' => $braintreeNonce, 'options' => ['submitForSettlement' => true]];
         /**this was never set in old code
          * if (defined('BRAINTREE_MERCHANT_ACCOUNT_ID') && BRAINTREE_MERCHANT_ACCOUNT_ID) {
          * $transactionSettings['merchantAccountId'] = BRAINTREE_MERCHANT_ACCOUNT_ID;
          * }*/
         $result = Transaction::sale($transactionSettings);
     }
     //Check for errors
     if (!$result->success) {
         $payment->set(["state" => 'error', "braintree_payment_method_nonce" => $braintreeNonce, "error" => json_encode($result)])->save();
         /**
          * @T00D00 - redirect to error page with error $result->message
          */
         $this->environment->redirect($this->environment->url('derive.payment.error', ['handler' => 'braintree', 'order' => $this->order->getOrder()]));
     }
     //If everything went fine, we got a transaction object
     $transaction = $result->transaction;
     //Write what we got to the database
     $payment->set(["braintree_transaction_id" => $transaction->id, "braintree_payment_method_nonce" => $braintreeNonce, "state" => 'BT:' . $transaction->status]);
     $payment->save();
     //SUBMITTED_FOR_SETTLEMENT means it's practically paid
     if ($transaction->status == Transaction::SUBMITTED_FOR_SETTLEMENT) {
         $this->order->getBills()->each(function (OrdersBill $ordersBill) use($transaction) {
             $ordersBill->confirm("Braintree #" . $transaction->id, 'braintree');
         });
         $this->environment->redirect($this->environment->url('derive.payment.success', ['handler' => 'braintree', 'order' => $this->order->getOrder()]));
     } else {
         if ($transaction->status == Transaction::PROCESSOR_DECLINED) {
             $payment->set(["state" => 'BT:' . $transaction->status, "error" => print_r(["processorResponseCode" => $transaction->processorResponseCode, "processorResponseText" => $transaction->processorResponseText, "additionalProcessorResponse" => $transaction->additionalProcessorResponse], true)]);
             $payment->save();
             /**
              * @T00D00 - redirect to error page with error $transaction->processorResponseText
              */
             $this->environment->redirect($this->environment->url('derive.payment.error', ['handler' => 'braintree', 'order' => $this->order->getOrder()]));
         } else {
             if ($transaction->status == Transaction::GATEWAY_REJECTED) {
                 $payment->set(["state" => 'BT:' . $transaction->status, "error" => print_r(["gatewayRejectionReason" => $transaction->gatewayRejectionReason], true)]);
                 $payment->save();
                 /**
                  * @T00D00 - redirect to error page with error $transaction->gatewayRejectionReason
                  */
                 $this->environment->redirect($this->environment->url('derive.payment.error', ['handler' => 'braintree', 'order' => $this->order->getOrder()]));
             } else {
                 /**
                  * @T00D00 - redirect to error page with error 'Unknown payment error'
                  */
                 $this->environment->redirect($this->environment->url('derive.payment.error', ['handler' => 'braintree', 'order' => $this->order->getOrder()]));
             }
         }
     }
 }
 /**
  * Create Braintree transaction
  * @return MockObject
  */
 private function getBraintreeTransaction()
 {
     $attributes = ['id' => self::TRANSACTION_ID, 'creditCardDetails' => $this->getCreditCardDetails()];
     $transaction = Transaction::factory($attributes);
     return $transaction;
 }
 /**
  * @param \AppBundle\Entity\User $user
  * @param float $amount
  * @return boolean
  */
 public function chargeUser(User $user, float $amount, $description)
 {
     //get braintree customer
     $customer = BraintreeCustomer::find($this->getCustomerId($user));
     $result = BraintreeTransaction::sale(['paymentMethodToken' => $customer->creditCards[0]->token, 'amount' => round($amount)]);
     $payment = new Payment();
     $payment->setUser($user);
     $payment->setSuccess(true);
     $payment->setDate(new \DateTime());
     $payment->setIntegration('braintree');
     $payment->setAmount($amount * 100);
     $payment->setReference($result->transaction->id);
     $this->persist($payment);
     $this->flush();
     return $result;
 }
예제 #15
0
 /**
  * create a new sale for the current card
  *
  * @param string $token
  * @param array $transactionAttribs
  * @return Result\Successful|Result\Error
  * @see Transaction::sale()
  */
 public function sale($token, $transactionAttribs)
 {
     $this->_validateId($token);
     return Transaction::sale(array_merge($transactionAttribs, ['paymentMethodToken' => $token]));
 }
예제 #16
0
 /**
  * Get a collection of the entity's invoices.
  *
  * @param bool  $includePending
  * @param array $parameters
  *
  * @return \Illuminate\Support\Collection
  */
 public function invoices($includePending = false, $parameters = [])
 {
     $invoices = new Collection();
     $customer = $this->asBraintreeCustomer();
     $parameters = array_merge([TransactionSearch::customerId()->is($customer->id)], $parameters);
     $braintreeTransactions = Transaction::search($parameters);
     $subscriptionIds = [];
     foreach ($braintreeTransactions as $braintreeTransaction) {
         $subscriptionIds[] = $braintreeTransaction->subscriptionId;
     }
     $braintreeSubscriptions = BraintreeSubscription::fetch([], array_unique($subscriptionIds));
     // Here we will loop through the Braintree invoices and create our own custom Invoice
     // instances that have more helper methods and are generally more convenient to
     // work with than the plain Braintree objects are. Then, we'll return the array.
     if (!is_null($braintreeSubscriptions)) {
         foreach ($braintreeSubscriptions as $subscription) {
             if ($subscription->status == BraintreeSubscription::ACTIVE || $includePending) {
                 foreach ($subscription->transactions as $transaction) {
                     $invoices->push(new Invoice($this, $subscription, $transaction));
                 }
             }
         }
     }
     return $invoices->sortByDesc(function ($invoice) {
         return $invoice->date();
     });
 }
 public function testHandlesPayPalAccounts()
 {
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['access_token' => 'PAYPAL_ACCESS_TOKEN']]);
     $result = Braintree\Transaction::sale(['amount' => Braintree\Test\TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce]);
     $this->assertTrue($result->success);
     $paypalDetails = $result->transaction->paypalDetails;
     $collection = Braintree\Transaction::search([Braintree\TransactionSearch::paypalPaymentId()->is($paypalDetails->paymentId), Braintree\TransactionSearch::paypalAuthorizationId()->is($paypalDetails->authorizationId), Braintree\TransactionSearch::paypalPayerEmail()->is($paypalDetails->payerEmail)]);
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($result->transaction->id, $collection->firstItem()->id);
 }
 public function sendData($data)
 {
     $response = Braintree\Transaction::sale($data);
     return $this->response = new Response($this, $response);
 }
예제 #19
0
 /**
  * create a new sale for a customer
  *
  * @param string $customerId
  * @param array $transactionAttribs
  * @return Result\Successful|Result\Error
  * @see Transaction::sale()
  */
 public function sale($customerId, $transactionAttribs)
 {
     $this->_validateId($customerId);
     return Transaction::sale(array_merge($transactionAttribs, ['customerId' => $customerId]));
 }
 /**
  * Create Braintree transaction
  * @return Transaction
  */
 private function getBraintreeTransaction()
 {
     $attributes = ['id' => '23ui8be', 'paypal' => ['paymentId' => 'u239dkv6n2lds', 'payerEmail' => '*****@*****.**']];
     $transaction = Transaction::factory($attributes);
     return $transaction;
 }
 /**
  * create a new sale for the current UsBank account
  *
  * @param string $token
  * @param array $transactionAttribs
  * @return Result\Successful|Result\Error
  * @see Transaction::sale()
  */
 public function sale($token, $transactionAttribs)
 {
     return Transaction::sale(array_merge($transactionAttribs, ['paymentMethodToken' => $token]));
 }
 /**
  * @covers \Magento\BraintreeTwo\Gateway\Helper\SubjectReader::readPayPal
  */
 public function testReadPayPal()
 {
     $paypal = ['paymentId' => '3ek7dk7fn0vi1', 'payerEmail' => '*****@*****.**'];
     $transaction = Transaction::factory(['id' => '4yr95vb', 'paypal' => $paypal]);
     static::assertEquals($paypal, $this->subjectReader->readPayPal($transaction));
 }
예제 #23
0
 /**
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 private function getBraintreeTransactionMock()
 {
     $transaction = \Braintree\Transaction::factory([]);
     $transaction->_set('riskData', RiskData::factory(['id' => 'test-id', 'decision' => 'test-decision']));
     return $transaction;
 }
 public function sendData($data)
 {
     $response = Braintree\Transaction::refund($data['transactionId'], $data['amount']);
     return $this->response = new Response($this, $response);
 }
 /**
  * Create Braintree transaction
  * @return Transaction
  */
 private function getBraintreeTransaction()
 {
     $attributes = ['id' => self::TRANSACTION_ID, 'avsPostalCodeResponseCode' => 'M', 'avsStreetAddressResponseCode' => 'M', 'cvvResponseCode' => 'M', 'processorAuthorizationCode' => 'W1V8XK', 'processorResponseCode' => '1000', 'processorResponseText' => 'Approved'];
     return Transaction::factory($attributes);
 }
예제 #26
0
 public function testGrant_returnsASingleUseNonce()
 {
     $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, false);
     $result = Braintree\Transaction::sale(['amount' => '100.00', 'paymentMethodNonce' => $grantResult->nonce]);
     $this->assertTrue($result->success);
     $secondResult = Braintree\Transaction::sale(['amount' => '100.00', 'paymentMethodNonce' => $grantResult->nonce]);
     $this->assertFalse($secondResult->success);
 }
 /**
  * @ignore
  */
 private function _verifyGatewayResponse($response)
 {
     if (isset($response['subscription'])) {
         return new Result\Successful(Subscription::factory($response['subscription']));
     } else {
         if (isset($response['transaction'])) {
             // return a populated instance of Transaction, for subscription retryCharge
             return new Result\Successful(Transaction::factory($response['transaction']));
         } else {
             if (isset($response['apiErrorResponse'])) {
                 return new Result\Error($response['apiErrorResponse']);
             } else {
                 throw new Exception\Unexpected("Expected subscription, transaction, or apiErrorResponse");
             }
         }
     }
 }
예제 #28
0
 /**
  * Clone original transaction
  * @param string $transactionId
  * @param array $attributes
  * @return mixed
  */
 public function cloneTransaction($transactionId, array $attributes)
 {
     return Transaction::cloneTransaction($transactionId, $attributes);
 }
 /**
  * @param string $customerData
  * @param float $price
  * @return bool | int
  * @throws Exception
  */
 public function createPurchase($customerData, $price)
 {
     $result = Braintree_Transaction::sale(['amount' => $price, 'paymentMethodNonce' => $customerData['nonce'], 'billing' => ['firstName' => $customerData['first_name'], 'lastName' => $customerData['last_name'], 'streetAddress' => $customerData['address'], 'locality' => $customerData['city'], 'region' => $customerData['state'], 'postalCode' => $customerData['zip']], 'options' => ['submitForSettlement' => True]]);
     if ($result->success) {
         return $result->transaction->id;
     } else {
         foreach ($result->errors->deepAll() as $error) {
             throw new Exception($error->code . ": " . $error->message . "\n");
         }
     }
     return false;
     /**
     * $result->success
     		# true
     
     		$result->transaction->status
     		# e.g. 'submitted_for_settlement'
     
     		$result->transaction->type
     */
     /**
     		"authorization_expired"
     		"authorized"
     		"authorizing"
     		"settlement_pending"
     		"settlement_confirmed"
     		"settlement_declined"
     		"failed"
     		"gateway_rejected"
     		"processor_declined"
     		"settled"
     		"settling"
     		"submitted_for_settlement"
     		"voided"
     */
 }
예제 #30
0
 public function testInitializationWithoutArguments()
 {
     $transaction = Braintree\Transaction::factory([]);
     $this->assertTrue($transaction instanceof Braintree\Transaction);
 }