Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special Response for Checkout Session #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Message/Checkout/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
*/
class PurchaseRequest extends AbstractRequest
{
/**
* Create response
*
* @param string $data
* @param array $headers
*
* @return Response
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}

/**
* Set the success url
*
Expand Down
33 changes: 33 additions & 0 deletions src/Message/Checkout/Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Omnipay\Stripe\Message\Checkout;

use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RedirectResponseInterface;
use Omnipay\Common\Message\RequestInterface;

/**
* Stripe Checkout Response - https://stripe.com/docs/api/checkout/sessions/create
*
* @see \Omnipay\Stripe\Gateway
*/
class Response extends \Omnipay\Stripe\Message\Response
{
/**
* @return bool
*/
public function isRedirect()
{
return $this->getRedirectUrl() !== null;
}

/**
* @return mixed
*/
public function getRedirectUrl()
{
if (isset($this->data['object']) && 'checkout.session' !== $this->data['object']) {
return null;
}

return !empty($this->data['url']) ? $this->data['url'] : null;
}
}