Skip to content

Commit

Permalink
Update StripePaymentManager.php
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkIncognito85 authored Mar 4, 2022
1 parent dbf5540 commit af92055
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/Stripe/StripePaymentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function createStripeUser(StripeUser $stripeUser)
{
try {
/** @var StripeUser */
$user = $this->table->findBy('stripe_id', $stripeUser->getStripeId() ?? "");
$user = $this->table->findBy('stripe_id', json_encode($stripeUser->getStripeId(true)) ?? "");
$stripeUser->updateStripeId($user->getStripeId());
} catch (NoRecordException $e) {
$this->stripe->createCustomer($stripeUser);
Expand All @@ -91,30 +91,38 @@ public function execute(Transaction $transaction, Request $request, User $user)
{
}

/**
* @throws \Exception
*/
public function confirm(Request $request)
{
$params = $request->getServerParams();
$signature = $params["HTTP_STRIPE_SIGNATURE"];
$webhook = $this->stripe->getWebhook($signature);
$object = $webhook->data->object;
$id = $object->metadata->transaction;
$transaction = $this->service->findTransaction($id);
$id = $object->id;
$transaction->setTransactionId($id);
$this->service->updateTransactionId($transaction);
if ($webhook->type != 'checkout.session.completed') {
return null;
}
if (isset($webhook->data->object)) {
$object = $webhook->data->object;
$id = $object->metadata->transaction;
$transaction = $this->service->findTransaction($id);
$id = $object->id;
$transaction->setTransactionId($id);
$this->service->updateTransactionId($transaction);

if ($object->payment_status !== "paid") {
$transaction->setState($transaction::REFUSED);
$transaction->setReason("Stripe error");
$this->service->changeState($transaction);
$this->service->setReason($transaction);
if ($object->payment_status !== "paid") {
$transaction->setState($transaction::REFUSED);
$transaction->setReason("Stripe error");
$this->service->changeState($transaction);
$this->service->setReason($transaction);

return $transaction;
} else {
$transaction->setState($transaction::COMPLETED);
$this->service->complete($transaction);
$this->service->changeState($transaction);
return $transaction;
return $transaction;
} else {
$transaction->setState($transaction::COMPLETED);
$this->service->complete($transaction);
$this->service->changeState($transaction);
return $transaction;
}
}
}

Expand Down

0 comments on commit af92055

Please sign in to comment.