diff --git a/src/Stripe/Api/Stripe.php b/src/Stripe/Api/Stripe.php index 6c1ca27..636d38f 100644 --- a/src/Stripe/Api/Stripe.php +++ b/src/Stripe/Api/Stripe.php @@ -79,6 +79,12 @@ public function getCustomer(string $customerId): Customer return $this->stripe->customers->retrieve($customerId); } + + public function checkConnection() + { + $this->stripe->customers->all(['limit' => 1]); + } + public function getInvoice(string $invoice): Invoice { return $this->stripe->invoices->retrieve($invoice); diff --git a/src/Stripe/StripePaymentBoard.php b/src/Stripe/StripePaymentBoard.php new file mode 100644 index 0000000..2e1862d --- /dev/null +++ b/src/Stripe/StripePaymentBoard.php @@ -0,0 +1,9 @@ + [ 'currency' => $transaction->getCurrency(), - 'unit_amount' => $item->priceWithTax() * 100, + 'unit_amount' => round($item->priceWithTax() * 100), 'product_data' => ["name" => $item->getName()] ], 'quantity' => $item->getQuantity(), @@ -92,7 +92,7 @@ public function execute(Transaction $transaction, Request $request, User $user) } - public function confirm(Transaction $transaction, Request $request, User $user){ + public function test(Transaction $transaction, Request $request, User $user){ $params = $request->getServerParams(); $signature = $params["HTTP_STRIPE_SIGNATURE"]; $webhook = $this->stripe->getWebhook($signature); @@ -108,24 +108,37 @@ public function confirm(Transaction $transaction, Request $request, User $user){ $this->service->changeState($transaction); $this->service->setReason($transaction); } else { - $this->service->complete($transaction); + + if ($this->service->isOrder($transaction)) { + $this->service->confirmOrder($transaction, $user->getId()); + } + $transaction->setState($transaction::COMPLETED); $this->service->changeState($transaction); return $transaction; } + } else if ($webhook->type === 'payment_intent.succeeded') { + + $object = $webhook->data->object; + $id = $webhook->id; + $transaction->setTransactionId($id); + $this->service->updateTransactionId($transaction); + return $transaction; + } } - public function success(Request $request){ + public function confirm(Request $request) + { $params = $request->getServerParams(); $signature = $params["HTTP_STRIPE_SIGNATURE"]; $webhook = $this->stripe->getWebhook($signature); - if ($webhook->type === 'payment_intent.succeeded'){ - + if ($webhook->type === 'payment_intent.succeeded') { $transaction = $this->service->getLastTransaction(); - $id = $webhook->id; + + $object = $webhook->data->object; + $id = $object->id; $transaction->setTransactionId($id); $this->service->updateTransactionId($transaction); - return $transaction; } } diff --git a/src/Stripe/config.php b/src/Stripe/config.php index 5bc43e9..34c3477 100644 --- a/src/Stripe/config.php +++ b/src/Stripe/config.php @@ -9,10 +9,11 @@ use function DI\get; return [ - 'auth.entity' => StripeUser::class, - 'payments.type' => add(get(StripePaymentType::class)), - 'csrf.except' => add(['stripe.webhook']), - Stripe::class => autowire() + 'auth.entity' => StripeUser::class, + 'payments.type' => add(get(StripePaymentType::class)), + 'csrf.except' => add(['stripe.webhook']), + 'payment.boards' => add(get(StripePaymentType::class)), + Stripe::class => autowire() ->constructorParameter('endpointkey', $_ENV['STRIPE_ENDPOINT'] ?? null) ->constructorParameter('privateKey', $_ENV['STRIPE_SECRET'] ?? null) ->constructorParameter('publicKey', $_ENV['STRIPE_PUBLIC'] ?? null)