Skip to content

Commit

Permalink
Use stripe to validate success on payment response
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Dec 11, 2023
1 parent ba7a2fa commit eb5953e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Omnipay/Stripe/Subscription/Message/SubscriptionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@

namespace Omnipay\Stripe\Subscription\Message;

use Goteo\Application\Config;
use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RedirectResponseInterface;
use Omnipay\Common\Message\RequestInterface;
use Stripe\Checkout\Session as StripeSession;
use Stripe\StripeClient;

class SubscriptionResponse extends AbstractResponse implements RedirectResponseInterface
{
private StripeClient $stripe;

private StripeSession $checkout;

public function __construct(RequestInterface $request, string $checkoutSessionId)
{
parent::__construct($request, $checkoutSessionId);

$this->stripe = new StripeClient(Config::get('payments.stripe.secretKey'));
$this->checkout = $this->stripe->checkout->sessions->retrieve($checkoutSessionId);
}

public function isSuccessful()
{
return $this->data['success'];
return $this->checkout->status === StripeSession::STATUS_COMPLETE;
}

public function isRedirect()
Expand All @@ -19,6 +35,6 @@ public function isRedirect()

public function getRedirectUrl()
{
return $this->data->url;
return $this->checkout->url;
}
}

0 comments on commit eb5953e

Please sign in to comment.