コード例 #1
9
 /**
  * @param string $stripeToken
  *
  * @throws \Exception
  *
  * @return Order
  */
 public function pay(string $stripeToken) : Order
 {
     Log::info(sprintf('Taking Stripe payment for %s (%s) with token `%s`.', $this->basket()->totalPrice()->formatted(), $this->basket()->totalPrice()->amount(), $stripeToken));
     $settlement = StripeSettlement::create(['token' => $stripeToken]);
     $order = $this->cashier->settle($this->basket(), $settlement);
     Log::info("Charging for order `{$order->publicId()}` with Stripe.");
     /** @var Charge $charge */
     $charge = $this->charge->create(['amount' => $this->basket()->totalPrice()->amount(), 'currency' => 'gbp', 'source' => $stripeToken, 'description' => "ching-shop.com order {$order->publicId()}"]);
     Log::info("Took payment for for order `{$order->publicId()}` with Stripe.");
     if ($charge instanceof Charge) {
         $settlement->fillFromCharge($charge)->save();
     }
     return $order;
 }
コード例 #2
0
 /**
  * @param string $paymentId
  * @param string $payerId
  *
  * @throws \Exception
  * @throws \InvalidArgumentException
  * @throws RuntimeException
  *
  * @return \ChingShop\Modules\Sales\Domain\Order\Order
  */
 public function executePayment(string $paymentId, string $payerId)
 {
     $settlement = PayPalSettlement::create(['payment_id' => $paymentId, 'payer_id' => $payerId]);
     $this->log->info("Executing PayPal payment {$paymentId} / {$payerId}");
     $execution = $this->createExecution($paymentId, $payerId);
     $order = $this->cashier->settle($execution->basket(), $settlement);
     if ($execution->approve()) {
         return $order;
     }
     throw new RuntimeException('PayPal payment was not approved.');
 }