sale() 공개 정적인 메소드

public static sale ( $attribs )
예제 #1
0
 /**
  * Make a "one off" charge on the customer for the given amount.
  *
  * @param  int  $amount
  * @param  array  $options
  * @return \Braintree\Transaction
  */
 public function charge($amount, array $options = [])
 {
     $customer = $this->asBraintreeCustomer();
     $response = BraintreeTransaction::sale(array_merge(['amount' => $amount * (1 + $this->taxPercentage() / 100), 'paymentMethodToken' => $customer->paymentMethods[0]->token, 'options' => ['submitForSettlement' => true], 'recurring' => true], $options));
     if (!$response->success) {
         throw new Exception('Braintree was unable to perform a charge: ' . $response->message);
     }
     return $response;
 }
예제 #2
0
 /**
  * Make a "one off" charge on the customer for the given amount.
  *
  * @param int    $amount
  * @param string $nonce
  * @param array  $options
  *
  * @return bool|mixed
  */
 public function charge($amount, $nonce, array $options = [])
 {
     $options = array_merge(['amount' => $amount, 'paymentMethodNonce' => $nonce, 'options' => ['submitForSettlement' => true]], $options);
     $result = Transaction::sale($options);
     if ($result->success) {
         return $result->transaction;
     }
     return false;
 }
 /**
  * @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"
     */
 }
예제 #4
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()]));
             }
         }
     }
 }
 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"
     */
 }
 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);
 }
 /**
  * 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]));
 }
 /**
  * @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;
 }
예제 #9
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]));
 }
 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);
 }
예제 #12
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]));
 }
예제 #13
0
 public function saleWithPaymentNonce($amount, $paymentMethodNonce)
 {
     $result = Transaction::sale(['amount' => $amount, 'paymentMethodNonce' => $paymentMethodNonce, 'options' => ['submitForSettlement' => true, 'storeInVaultOnSuccess' => true]]);
     return $result;
 }
예제 #14
0
 /**
  * @param array $attributes
  * @return \Braintree\Result\Successful|\Braintree\Result\Error
  */
 public function sale(array $attributes)
 {
     return Transaction::sale($attributes);
 }
예제 #15
0
 public function testBillingPostalCodeIsReturnedWhenRequestedOnTransactionsCreatedViaNonceGranting()
 {
     $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', 'billingAddress' => ['firstName' => 'Adam', 'lastName' => 'Davis', 'postalCode' => '95131']])->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, ['allow_vaulting' => false, 'include_billing_postal_code' => true]);
     $result = Braintree\Transaction::sale(['amount' => '100.00', 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce]);
     $this->assertEquals($result->transaction->billing["postalCode"], "95131");
 }