find() public static method

public static find ( $id )
示例#1
0
 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()]));
             }
         }
     }
 }
示例#2
0
 /**
  * Find an invoice by ID.
  *
  * @param  string  $id
  * @return \Laravel\Cashier\Invoice|null
  */
 public function findInvoice($id)
 {
     try {
         $invoice = BraintreeTransaction::find($id);
         if ($invoice->customerDetails->id != $this->braintree_id) {
             return;
         }
         return new Invoice($this, $invoice);
     } catch (Exception $e) {
         //
     }
 }
示例#3
0
 /**
  * Find an invoice for subscription by transaction ID.
  *
  * @param string $id
  *
  * @return \LimeDeck\CashierBraintree\Invoice|null
  */
 public function findInvoice($plan, $id)
 {
     $subscription = BraintreeSubscription::search(SubscriptionSearch::planId($plan));
     $transaction = Transaction::find($id);
     try {
         return new Invoice($this, $subscription, $transaction);
     } catch (Exception $e) {
         return null;
     }
 }
 public function test_rangeNode_settledAt()
 {
     $transaction = Braintree\Transaction::saleNoValidate(['amount' => '1000.00', 'creditCard' => ['number' => '4111111111111111', 'expirationDate' => '05/12'], 'options' => ['submitForSettlement' => true]]);
     $http = new Braintree\Http(Braintree\Configuration::$global);
     $path = Braintree\Configuration::$global->merchantPath() . '/transactions/' . $transaction->id . '/settle';
     $http->put($path);
     $transaction = Braintree\Transaction::find($transaction->id);
     $twenty_min_ago = date_create("now -20 minutes", new DateTimeZone("UTC"));
     $ten_min_ago = date_create("now -10 minutes", new DateTimeZone("UTC"));
     $ten_min_from_now = date_create("now +10 minutes", new DateTimeZone("UTC"));
     $collection = Braintree\Transaction::search([Braintree\TransactionSearch::id()->is($transaction->id), Braintree\TransactionSearch::settledAt()->between($twenty_min_ago, $ten_min_ago)]);
     $this->assertEquals(0, $collection->maximumCount());
     $collection = Braintree\Transaction::search([Braintree\TransactionSearch::id()->is($transaction->id), Braintree\TransactionSearch::settledAt()->between($ten_min_ago, $ten_min_from_now)]);
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($transaction->id, $collection->firstItem()->id);
 }
示例#5
0
 /**
  * Finds transaction by id.
  * @param string $id
  * @return Transaction
  */
 public function findTransaction($id)
 {
     return Transaction::find($id);
 }
 public function testErrorsWhenFindWithWhitespaceString()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree\Transaction::find('\\t');
 }
 public function testSubmitForPartialSettlement()
 {
     $authorizedTransaction = Braintree\Transaction::saleNoValidate(['amount' => '100.00', 'creditCard' => ['number' => '5105105105105100', 'expirationDate' => '05/12']]);
     $this->assertEquals(Braintree\Transaction::AUTHORIZED, $authorizedTransaction->status);
     $partialSettlementResult1 = Braintree\Transaction::submitForPartialSettlement($authorizedTransaction->id, '60.00');
     $this->assertTrue($partialSettlementResult1->success);
     $this->assertEquals(Braintree\Transaction::SUBMITTED_FOR_SETTLEMENT, $partialSettlementResult1->transaction->status);
     $this->assertEquals('60.00', $partialSettlementResult1->transaction->amount);
     $partialSettlementResult2 = Braintree\Transaction::submitForPartialSettlement($authorizedTransaction->id, '40.00');
     $this->assertTrue($partialSettlementResult2->success);
     $this->assertEquals(Braintree\Transaction::SUBMITTED_FOR_SETTLEMENT, $partialSettlementResult2->transaction->status);
     $this->assertEquals('40.00', $partialSettlementResult2->transaction->amount);
     $refreshedAuthorizedTransaction = Braintree\Transaction::find($authorizedTransaction->id);
     $this->assertEquals(2, count($refreshedAuthorizedTransaction->partialSettlementTransactionIds));
 }