diff --git a/src/CheckoutGateway.php b/src/CheckoutGateway.php new file mode 100644 index 00000000..9dfd769d --- /dev/null +++ b/src/CheckoutGateway.php @@ -0,0 +1,66 @@ +createRequest('\Omnipay\Stripe\Message\Checkout\PurchaseRequest', $parameters); + } + + /** + * @inheritdoc + * @return \Omnipay\Stripe\Message\Checkout\PurchaseRequest + */ + public function fetchTransaction(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Stripe\Message\Checkout\FetchTransactionRequest', $parameters); + } + + /** + * @inheritdoc + * + * @return \Omnipay\Stripe\Message\AuthorizeRequest + */ + public function authorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Stripe\Message\AuthorizeRequest', $parameters); + } + + /** + * @inheritdoc + * + * @return \Omnipay\Stripe\Message\CaptureRequest + */ + public function capture(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Stripe\Message\CaptureRequest', $parameters); + } +} diff --git a/src/Message/Checkout/AbstractRequest.php b/src/Message/Checkout/AbstractRequest.php new file mode 100644 index 00000000..46abf036 --- /dev/null +++ b/src/Message/Checkout/AbstractRequest.php @@ -0,0 +1,21 @@ + + * // Fetch the transaction so that details can be found for refund, etc. + * $transaction = $gateway->fetchTransaction(); + * $transaction->setTransactionReference($sale_id); + * $response = $transaction->send(); + * $data = $response->getData(); + * echo "Gateway fetchTransaction response data == " . print_r($data, true) . "\n"; + * + * + * @see PurchaseRequest + * @see Omnipay\Stripe\CheckoutGateway + * @link https://stripe.com/docs/api/checkout/sessions/retrieve + */ +class FetchTransactionRequest extends AbstractRequest +{ + public function getData() + { + $this->validate('transactionReference'); + + $data = []; + + return $data; + } + + public function getEndpoint() + { + return $this->endpoint.'/checkout/sessions/'. $this->getTransactionReference(); + } + + public function getHttpMethod() + { + return 'GET'; + } +} diff --git a/src/Message/Checkout/PurchaseRequest.php b/src/Message/Checkout/PurchaseRequest.php new file mode 100644 index 00000000..d3d2386d --- /dev/null +++ b/src/Message/Checkout/PurchaseRequest.php @@ -0,0 +1,166 @@ +setParameter('success_url', $value); + } + + /** + * Get the success url + * + * @return string + */ + public function getSuccessUrl() + { + return $this->getParameter('success_url'); + } + /** + * Set the cancel url + * + * @param string $value + * + * @return \Omnipay\Common\Message\AbstractRequest|PurchaseRequest + */ + public function setCancelUrl($value) + { + return $this->setParameter('cancel_url', $value); + } + + /** + * Get the success url + * + * @return string + */ + public function getCancelUrl() + { + return $this->getParameter('cancel_url'); + } + + /** + * Set the payment method types accepted url + * + * @param array $value + * + * @return \Omnipay\Common\Message\AbstractRequest|PurchaseRequest + */ + public function setPaymentMethodTypes($value) + { + return $this->setParameter('payment_method_types', $value); + } + + /** + * Get the success url + * + * @return string + */ + public function getPaymentMethodTypes() + { + return $this->getParameter('payment_method_types'); + } + + /** + * Set the payment method types accepted url + * + * @param string $value + * + * @return \Omnipay\Common\Message\AbstractRequest|PurchaseRequest + */ + public function setMode($value) + { + return $this->setParameter('mode', $value); + } + + /** + * Get the success url + * + * @return string + */ + public function getMode() + { + return $this->getParameter('mode'); + } + + /** + * Set the payment method types accepted url + * + * @param array $value + * + * @return \Omnipay\Common\Message\AbstractRequest|PurchaseRequest + */ + public function setLineItems($value) + { + return $this->setParameter('line_items', $value); + } + + /** + * Get the success url + * + * @return array + */ + public function getLineItems() + { + return $this->getParameter('line_items'); + } + + /** + * Set the payment method types accepted url + * + * @param string $value + * + * @return \Omnipay\Common\Message\AbstractRequest|PurchaseRequest + */ + public function setClientReferenceId($value) + { + return $this->setParameter('client_reference_id', $value); + } + + /** + * Get the success url + * + * @return string + */ + public function getClientReferenceId() + { + return $this->getParameter('client_reference_id'); + } + + + public function getData() + { + $data = array( + 'success_url' => $this->getSuccessUrl(), + 'cancel_url' => $this->getCancelUrl(), + 'payment_method_types' => $this->getPaymentMethodTypes(), + 'mode' => $this->getMode(), + 'line_items' => $this->getLineItems() + ); + + return $data; + } + + public function getEndpoint() + { + return $this->endpoint.'/checkout/sessions'; + } +} diff --git a/tests/CheckoutGatewayTest.php b/tests/CheckoutGatewayTest.php new file mode 100644 index 00000000..6f69e45e --- /dev/null +++ b/tests/CheckoutGatewayTest.php @@ -0,0 +1,34 @@ +gateway = new CheckoutGateway($this->getHttpClient(), $this->getHttpRequest()); + } + + public function testPurchase() + { + $request = $this->gateway->purchase(['mode' => 'payment']); + + $this->assertInstanceOf('Omnipay\Stripe\Message\Checkout\PurchaseRequest', $request); + $this->assertSame('payment', $request->getMode()); + } + + public function testFetchTransaction() + { + $request = $this->gateway->fetchTransaction(['transactionReference' => 'transaction-reference']); + + $this->assertInstanceOf('Omnipay\Stripe\Message\Checkout\FetchTransactionRequest', $request); + $this->assertSame('transaction-reference', $request->getTransactionReference()); + } +}