allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
2026-03-30 14:54:57 +07:00
parent 66aed7c4e8
commit b5e3a778ce
21316 changed files with 2777892 additions and 13 deletions

View File

@@ -0,0 +1,62 @@
<?php
/**
* Stripe Abstract Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Payment Intent Abstract Request.
*
* This is the parent class for all Stripe payment intent requests.
* It adds just a getter and setter.
*
* @see \Omnipay\Stripe\PaymentIntentsGateway
* @see \Omnipay\Stripe\Message\AbstractRequest
* @link https://stripe.com/docs/api/payment_intents
*/
abstract class AbstractRequest extends \Omnipay\Stripe\Message\AbstractRequest
{
/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setPaymentIntentReference($value)
{
return $this->setParameter('paymentIntentReference', $value);
}
/**
* @return mixed
*/
public function getPaymentIntentReference()
{
return $this->getParameter('paymentIntentReference');
}
/**
* If there's a reference to a payment method, return that instead.
*
* @inheritdoc
*/
public function getCardReference()
{
if ($paymentMethod = $this->getPaymentMethod()) {
return $paymentMethod;
}
return parent::getCardReference();
}
/**
* Actually, set the payment method, which is the preferred API.
*
* @inheritdoc
*/
public function setCardReference($reference)
{
$this->setPaymentMethod($reference);
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* Stripe Attach Payment Method Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Attach Payment Method Request.
*
* This request is used to attach an existing payment method to an existing customer.
* The `attachCard` method *will not work* on the Charge gateway.
*
* ### Example
*
* This example assumes that you have already created both a customer and a
* payment method and that the data is stored in $customerId and $paymentMethodId, respectively.
*
* <code>
* // Do an attach card transaction on the gateway
* $response = $gateway->attachCard(array(
* 'paymentMethod' => $paymentMethodId,
* 'customerReference' => $customerId,
* ))->send();
* if ($response->isSuccessful()) {
* echo "Gateway attachCard was successful.\n";
* // Find the card ID
* $methodId = $response->getCardReference();
* echo "Method ID = " . $methodId . "\n";
* }
* </code>
*
* @see \Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\CreateCustomerRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\DetachPaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\UpdatePaymentMethodRequest
* @link https://stripe.com/docs/api/payment_methods/attach
*/
class AttachPaymentMethodRequest extends AbstractRequest
{
public function getData()
{
$data = [];
$this->validate('customerReference');
$this->validate('paymentMethod');
$data['customer'] = $this->getCustomerReference();
return $data;
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint.'/payment_methods/' . $this->getPaymentMethod() . '/attach';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,425 @@
<?php
/**
* Stripe Payment Intents Authorize Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
use Money\Formatter\DecimalMoneyFormatter;
/**
* Stripe Payment Intents Authorize Request.
*
* An authorize request is similar to a purchase request but the
* charge issues an authorization (or pre-authorization), and no money
* is transferred. The transaction will need to be captured later
* in order to effect payment. Uncaptured charges expire in 7 days.
*
* A payment method is required. It can be set using the `paymentMethod`, `source`,
* `cardReference` or `token` parameters.
*
* *Important*: Please note, that this gateway is a hybrid between credit card and
* off-site gateway. It acts as a normal credit card gateway, unless the payment method
* requires 3DS authentication, in which case it also performs a redirect to an
* off-site authentication form.
*
* Example:
*
* <code>
* // Create a gateway for the Stripe Gateway
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('Stripe\PaymentIntents');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'apiKey' => 'MyApiKey',
* ));
*
* // Create a payment method using a credit card object.
* // This card can be used for testing.
* $card = new CreditCard(array(
* 'firstName' => 'Example',
* 'lastName' => 'Customer',
* 'number' => '4242424242424242',
* 'expiryMonth' => '01',
* 'expiryYear' => '2020',
* 'cvv' => '123',
* 'email' => 'customer@example.com',
* 'billingAddress1' => '1 Scrubby Creek Road',
* 'billingCountry' => 'AU',
* 'billingCity' => 'Scrubby Creek',
* 'billingPostcode' => '4999',
* 'billingState' => 'QLD',
* ));
*
* $paymentMethod = $gateway->createCard(['card' => $card])->send()->getCardReference();
*
* // Code above can be skipped if you use Stripe.js and have a payment method reference
* // in the $paymentMethod variable already.
*
* // For backwards compatibility, it's also possible to use card and source references
* // as well as tokens. However, a data dictionary containing card data cannot
* // be used at this stage.
*
* // Also note the setting of a return url. This is needed for cards that require
* // the 3DS 2.0 authentication. If you do not set a return url, payment with such
* // cards will fail.
*
* // Do a purchase transaction on the gateway
* $paymentIntent = $gateway->authorize(array(
* 'amount' => '10.00',
* 'currency' => 'USD',
* 'description' => 'This is a test purchase transaction.',
* 'paymentMethod' => $paymentMethod,
* 'returnUrl' => $completePaymentUrl,
* 'confirm' => true,
* ));
*
* $paymentIntent = $paymentIntent->send();
*
* // Alternatively, if you don't want to confirm it at one go for whatever reason, you
* // can use this code block below to confirm it. Otherwise, skip it.
* $paymentIntent = $gateway->confirm(array(
* 'returnUrl' => $completePaymentUrl
* 'paymentIntentReference' => $paymentIntent->getPaymentIntentReference(),
* ));
*
* $response = $paymentIntent->send();
*
* // If you set the confirm to true when performing the authorize transaction,
* // resume here.
*
* // 3DS 2.0 time!
* if ($response->isRedirect()) {
* $response->redirect();
* } else if ($response->isSuccessful()) {
* echo "Authorize transaction was successful!\n";
* $sale_id = $response->getTransactionReference();
* echo "Transaction reference = " . $sale_id . "\n";
* }
* </code>
*
* @see \Omnipay\Stripe\PaymentIntentsGateway
* @see \Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\ConfirmPaymentIntentRequest
* @link https://stripe.com/docs/api/payment_intents
*/
class AuthorizeRequest extends AbstractRequest
{
/**
* Set the confirm parameter.
*
* @param $value
* @return AbstractRequest provides a fluent interface.
*/
public function setConfirm($value)
{
return $this->setParameter('confirm', $value);
}
/**
* Get the confirm parameter.
*
* @return mixed
*/
public function getConfirm()
{
return $this->getParameter('confirm');
}
/**
* @return mixed
*/
public function getDestination()
{
return $this->getParameter('destination');
}
/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setDestination($value)
{
return $this->setParameter('destination', $value);
}
/**
* @return mixed
*/
public function getSource()
{
return $this->getParameter('source');
}
/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setSource($value)
{
return $this->setParameter('source', $value);
}
/**
* Connect only
*
* @return mixed
*/
public function getTransferGroup()
{
return $this->getParameter('transferGroup');
}
/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setTransferGroup($value)
{
return $this->setParameter('transferGroup', $value);
}
/**
* Connect only
*
* @return mixed
*/
public function getOnBehalfOf()
{
return $this->getParameter('onBehalfOf');
}
/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setOnBehalfOf($value)
{
return $this->setParameter('onBehalfOf', $value);
}
/**
* @return string
* @throws \Omnipay\Common\Exception\InvalidRequestException
*/
public function getApplicationFee()
{
$money = $this->getMoney('applicationFee');
if ($money !== null) {
$moneyFormatter = new DecimalMoneyFormatter($this->getCurrencies());
return $moneyFormatter->format($money);
}
return '';
}
/**
* Get the payment amount as an integer.
*
* @return integer
* @throws \Omnipay\Common\Exception\InvalidRequestException
*/
public function getApplicationFeeInteger()
{
$money = $this->getMoney('applicationFee');
if ($money !== null) {
return (integer) $money->getAmount();
}
return 0;
}
/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setApplicationFee($value)
{
return $this->setParameter('applicationFee', $value);
}
/**
* @return mixed
*/
public function getStatementDescriptor()
{
return $this->getParameter('statementDescriptor');
}
/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setStatementDescriptor($value)
{
$value = str_replace(array('<', '>', '"', '\''), '', $value);
return $this->setParameter('statementDescriptor', $value);
}
/**
* @return mixed
*/
public function getReceiptEmail()
{
return $this->getParameter('receipt_email');
}
/**
* @param mixed $email
* @return $this
*/
public function setReceiptEmail($email)
{
$this->setParameter('receipt_email', $email);
return $this;
}
/**
* Set the setup_future_usage parameter.
*
* @param $value
* @return AbstractRequest provides a fluent interface.
*/
public function setSetupFutureUsage($value)
{
return $this->setParameter('setup_future_usage', $value);
}
/**
* Get the setup_future_usage parameter.
*
* @return mixed
*/
public function getSetupFutureUsage()
{
return $this->getParameter('setup_future_usage');
}
/**
* Set the setup_future_usage parameter.
*
* @param $value
* @return AbstractRequest provides a fluent interface.
*/
public function setOffSession($value)
{
return $this->setParameter('off_session', $value);
}
/**
* Get the setup_future_usage parameter.
*
* @return mixed
*/
public function getOffSession()
{
return $this->getParameter('off_session');
}
/**
* @inheritdoc
*/
public function getData()
{
$this->validate('amount', 'currency');
$data = array();
$data['amount'] = $this->getAmountInteger();
$data['currency'] = strtolower($this->getCurrency());
$data['description'] = $this->getDescription();
$data['metadata'] = $this->getMetadata();
if ($this->getStatementDescriptor()) {
$data['statement_descriptor'] = $this->getStatementDescriptor();
}
if ($this->getDestination()) {
$data['transfer_data']['destination'] = $this->getDestination();
}
if ($this->getOnBehalfOf()) {
$data['on_behalf_of'] = $this->getOnBehalfOf();
}
if ($this->getApplicationFee()) {
$data['application_fee'] = $this->getApplicationFeeInteger();
}
if ($this->getTransferGroup()) {
$data['transfer_group'] = $this->getTransferGroup();
}
if ($this->getReceiptEmail()) {
$data['receipt_email'] = $this->getReceiptEmail();
}
if ($this->getPaymentMethod()) {
$data['payment_method'] = $this->getPaymentMethod();
} elseif ($this->getSource()) {
$data['payment_method'] = $this->getSource();
} elseif ($this->getCardReference()) {
$data['payment_method'] = $this->getCardReference();
} elseif ($this->getToken()) {
$data['payment_method_data'] = [
'type' => 'card',
'card' => ['token' => $this->getToken()],
];
} else {
// one of cardReference, token, or card is required
$this->validate('paymentMethod');
}
if ($this->getCustomerReference()) {
$data['customer'] = $this->getCustomerReference();
}
if ($this->getSetupFutureUsage()) {
$data['setup_future_usage'] = $this->getSetupFutureUsage();
}
$data['off_session'] = $this->getOffSession() ? 'true' : 'false';
$data['confirmation_method'] = 'manual';
$data['capture_method'] = 'manual';
$data['confirm'] = $this->getConfirm() ? 'true' : 'false';
if ($this->getConfirm() && !$this->getOffSession()) {
$this->validate('returnUrl');
$data['return_url'] = $this->getReturnUrl();
}
$data['off_session'] = $this->getOffSession() ? 'true' : 'false';
return $data;
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint.'/payment_intents';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Payment Intents Cancel Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Cancel Payment Intent Request.
*
* <code>
* $paymentIntent = $gateway->cancelPaymentIntent(array(
* 'paymentIntentReference' => $paymentIntentReference,
* ));
*
* $response = $paymentIntent->send();
*
* if ($response->isCancelled()) {
* // All done
* }
* </code>
*
* @link https://stripe.com/docs/api/payment_intents/cancel
*/
class CancelPaymentIntentRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$this->validate('paymentIntentReference');
return [];
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint.'/payment_intents/' . $this->getPaymentIntentReference() . '/cancel';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* Stripe Capture Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Capture Request.
*
* Use this request to capture and process a previously created authorization.
*
* Example -- note this example assumes that the authorization has been successful
* and that the payment intent that performed the authorization is held in $paymentIntent.
* See AuthorizeRequest for the first part of this example transaction:
*
* <code>
* // Once the transaction has been authorized, we can capture it for final payment.
* $transaction = $gateway->capture(array(
* 'amount' => '10.00',
* 'currency' => 'AUD',
* ));
* $transaction->setPaymentMethod($paymentMethod);
* $response = $transaction->send();
* </code>
*
* @see AuthorizeRequest
* @link https://stripe.com/docs/api/payment_intents/capture
*/
class CaptureRequest extends AbstractRequest
{
public function getData()
{
$this->validate('paymentIntentReference');
$data = array();
if ($amount = $this->getAmountInteger()) {
$data['amount_to_capture'] = $amount;
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/payment_intents/'.$this->getPaymentIntentReference().'/capture';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* Stripe Payment Intents Authorize Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Confirm Payment Intent Request.
*
* This request is sent behind the scenes whenever an authorize or purchase request
* is performed by the Payment Intents gateway. The previous authorize or purchase request
* "primes" the purchase or authorization and this request confirms it.
*
* The response to this request indicates whether the payment requires 3DS authentication,
* in which case it will be a redirect response.
*
* For examples, refer to related purchase and authorization classes.
*
* @see \Omnipay\Stripe\Gateway
* @see \Omnipay\Stripe\Message\PaymentIntents\AuthorizeRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\PurchaseRequest
* @link https://stripe.com/docs/api/payment_intents/confirm
*/
class ConfirmPaymentIntentRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$this->validate('paymentIntentReference');
$data = array();
if ($this->getReturnUrl()) {
$data['return_url'] = $this->getReturnUrl();
}
return $data;
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint.'/payment_intents/' . $this->getPaymentIntentReference() . '/confirm';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* Stripe Create Payment Method Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Create Payment Method Request.
*
* Stripe payment methods differs a little bit from creating a card.
* When using the Payment Intent API, it is mandatory to use a payment method,
* so a lot of times you'll be creating a payment method without an assigned customer.
*
* Another difference is that it's impossible to create a payment method and assign
* it to a user in a single request. Instead, you create a payment method and then
* attach it.
*
* ### Example
*
* <code>
* // Create a credit card object
* // This card can be used for testing.
* $new_card = new CreditCard([
* 'firstName' => 'Example',
* 'lastName' => 'Customer',
* 'number' => '5555555555554444',
* 'expiryMonth' => '01',
* 'expiryYear' => '2020',
* 'cvv' => '456',
* 'email' => 'customer@example.com',
* 'billingAddress1' => '1 Lower Creek Road',
* 'billingCountry' => 'AU',
* 'billingCity' => 'Upper Swan',
* 'billingPostcode' => '6999',
* 'billingState' => 'WA',
* ]);
*
* // Do a create card transaction on the gateway
* $response = $gateway->createCard(['card' => $new_card])->send();
* if ($response->isSuccessful()) {
* echo "Gateway createCard was successful.\n";
* // Find the card ID
* $method_id = $response->getCardReference();
* echo "Method ID = " . $method_id . "\n";
* }
* </code>
*
* @see \Omnipay\Stripe\Message\PaymentIntents\AttachPaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\DetachPaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\UpdatePaymentMethodRequest
* @link https://stripe.com/docs/api/payment_methods/create
*/
class CreatePaymentMethodRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$data = [];
if ($this->getToken()) {
$data['card'] = ['token' => $this->getToken()];
} elseif ($this->getCard()) {
$data['card'] = $this->getCardData();
} else {
// one of token or card is required
$this->validate('card');
}
if ($this->getCard() && $billingDetails = $this->getBillingDetails()) {
$data['billing_details'] = $billingDetails;
}
$data['type'] = 'card';
return $data;
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint.'/payment_methods';
}
/**
* @inheritdoc
*/
public function getCardData()
{
$data = parent::getCardData();
return [
'exp_month' => $data['exp_month'],
'exp_year' => $data['exp_year'],
'number' => $data['number'],
'cvc' => $data['cvc'],
];
}
/**
* Return an array of the billing details.
*/
public function getBillingDetails()
{
$data = parent::getCardData();
// Take care of optional data by filtering it out.
return array_filter([
'email' => $data['email'],
'name' => $data['name'],
'address' => array_filter([
'city' => $data['address_city'],
'country' => $data['address_country'],
'line1' => $data['address_line1'],
'line2' => $data['address_line2'],
'postal_code' => $data['address_zip'],
'state' => $data['address_state'],
]),
]);
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Stripe Attach Payment Method Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Attach Payment Method Request.
*
* This request is used to detach an existing payment method from a customer.
*
* ### Example
*
* This example assumes that you have already created both a customer and a
* payment method and that the data is stored in $customerId and $paymentMethodId, respectively.
*
* <code>
* // Do an attach card transaction on the gateway
* $response = $gateway->deleteCard(array(
* 'paymentMethod' => $paymentMethodId,
* ))->send();
* if ($response->isSuccessful()) {
* echo "Gateway detachCard was successful.\n";
* // Find the card ID
* $methodId = $response->getCardReference();
* echo "Method ID = " . $methodId . "\n";
* }
* </code>
*
* @see \Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\AttachPaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\UpdatePaymentMethodRequest
* @link https://stripe.com/docs/api/payment_methods/detach
*/
class DetachPaymentMethodRequest extends AbstractRequest
{
public function getData()
{
$this->validate('paymentMethod');
return [];
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint.'/payment_methods/' . $this->getPaymentMethod() . '/detach';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* Stripe Fetch Payment Intent Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Fetch Payment Intent Request.
*
* // Check if we're good!
* $paymentIntent = $gateway->fetchPaymentIntent(array(
* 'paymentIntentReference' => $paymentIntentReference,
* ));
*
* $response = $paymentIntent->send();
*
* if ($response->isSuccessful()) {
* // All done. Rejoice.
* }
*
* @link https://stripe.com/docs/api/payment_intents/retrieve
*/
class FetchPaymentIntentRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$this->validate('paymentIntentReference');
}
/**
* @inheritdoc
*/
public function getHttpMethod()
{
return 'GET';
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint . '/payment_intents/' . $this->getPaymentIntentReference();
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Stripe Fetch Payment Method Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Fetch Payment Method Request.
*
* <code>
* $paymentMethod = $gateway->fetchPaymentMethod(array(
* 'paymentMethodId' => $paymentMethodId,
* ));
*
* $response = $paymentMethod->send();
*
* if ($response->isSuccessful()) {
* // All done
* }
* </code>
*
* @link https://stripe.com/docs/api/payment_methods/retrieve
*/
class FetchPaymentMethodRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$this->validate('paymentMethod');
return [];
}
/**
* @inheritdoc
*/
public function getHttpMethod()
{
return 'GET';
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint . '/payment_methods/' . $this->getPaymentMethod();
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Stripe Payment Intents Purchase Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Payment Intents Purchase Request.
*
* A payment method is required. It can be set using the `paymentMethod`, `source`,
* `cardReference` or `token` parameters.
*
* *Important*: Please note, that this gateway is a hybrid between credit card and
* off-site gateway. It acts as a normal credit card gateway, unless the payment method
* requires 3DS authentication, in which case it also performs a redirect to an
* off-site authentication form.
*
* Because a purchase request in Stripe looks similar to an Authorize request, this
* class simply extends the AuthorizeRequest class and overrides the
* getData method setting capture_method to be automatic.
*
* You should also look at that class for code examples.
*
* @see \Omnipay\Stripe\PaymentIntentsGateway
* @see \Omnipay\Stripe\Message\PaymentIntents\AuthorizeRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\ConfirmPaymentIntentRequest
* @link https://stripe.com/docs/api/payment_intents
*/
class PurchaseRequest extends AuthorizeRequest
{
public function getData()
{
$data = parent::getData();
$data['capture_method'] = 'automatic';
return $data;
}
}

View File

@@ -0,0 +1,171 @@
<?php
/**
* Stripe Payment Intents Response.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Stripe\Message\Response as BaseResponse;
use Omnipay\Common\Message\RedirectResponseInterface;
/**
* Stripe Payment Intents Response.
*
* This is the response class for all payment intents related responses.
*
* @see \Omnipay\Stripe\PaymentIntentsGateway
*/
class Response extends BaseResponse implements RedirectResponseInterface
{
/**
* Get the status of a payment intents response.
*
* @return string|null
*/
public function getStatus()
{
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
return $this->data['status'];
}
return null;
}
/**
* Return true if the payment intent requires confirmation.
*
* @return bool
*/
public function requiresConfirmation()
{
return $this->getStatus() === 'requires_confirmation';
}
/**
* @inheritdoc
*/
public function getCardReference()
{
if (isset($this->data['object']) && 'payment_method' === $this->data['object']) {
if (!empty($this->data['id'])) {
return $this->data['id'];
}
}
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
if (!empty($this->data['payment_method'])) {
return $this->data['payment_method'];
}
}
return parent::getCardReference();
}
/**
* @inheritdoc
*/
public function getCustomerReference()
{
if (isset($this->data['object']) && 'payment_method' === $this->data['object']) {
if (!empty($this->data['customer'])) {
return $this->data['customer'];
}
}
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
if (!empty($this->data['customer'])) {
return $this->data['customer'];
}
}
return parent::getCustomerReference();
}
/**
* Get the capture method of a payment intents response.
*
* @return string|null
*/
public function getCaptureMethod()
{
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
return $this->data['capture_method'];
}
return null;
}
/**
* @inheritdoc
*/
public function getTransactionReference()
{
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
if (!empty($this->data['charges']['data'][0]['id'])) {
return $this->data['charges']['data'][0]['id'];
}
}
return parent::getTransactionReference();
}
/**
* @inheritdoc
*/
public function isSuccessful()
{
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
return in_array($this->getStatus(), ['succeeded', 'requires_capture']);
}
return parent::isSuccessful();
}
/**
* @inheritdoc
*/
public function isCancelled()
{
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
return $this->getStatus() === 'canceled';
}
return parent::isCancelled();
}
/**
* @inheritdoc
*/
public function isRedirect()
{
if ($this->getStatus() === 'requires_action' || $this->getStatus() === 'requires_source_action') {
// Currently this gateway supports only manual confirmation, so any other
// next action types pretty much mean a failed transaction for us.
return (!empty($this->data['next_action']) && $this->data['next_action']['type'] === 'redirect_to_url');
}
return parent::isRedirect();
}
/**
* @inheritdoc
*/
public function getRedirectUrl()
{
return $this->isRedirect() ? $this->data['next_action']['redirect_to_url']['url'] : parent::getRedirectUrl();
}
/**
* Get the payment intent reference.
*
* @return string|null
*/
public function getPaymentIntentReference()
{
if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) {
return $this->data['id'];
}
return null;
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* Stripe Update Payment Method Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;
/**
* Stripe Update Payment Method Request.
*
* If you need to update only some payment method details, like the billing
* address or expiration date, you can do so, however it is impossible to change the
* card number or the cvc code for a payment method. Stripe also works directly
* with card networks so that your customers can continue using your service without
* interruption.
*
* Stripe will automatically validate the payment method on update.
* The payment method must be attached to a customer to be updated.
*
* This requires a paymentMethod.
*
* @see \Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\CreateCustomerRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\DetachPaymentMethodRequest
* @see \Omnipay\Stripe\Message\PaymentIntents\AttachPaymentMethodRequest
* @link https://stripe.com/docs/api/payment_methods/update
*/
class UpdatePaymentMethodRequest extends AbstractRequest
{
public function getData()
{
$this->validate('paymentMethod');
$data = [];
if ($this->getCard()) {
$data['card'] = $this->getCardData();
$data['billing_details'] = $this->getBillingDetails();
} else {
return array();
}
if ($metadata = $this->getMetadata()) {
$data['metadata'] = $metadata;
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/payment_methods/'.$this->getPaymentMethod();
}
/**
* Get the card data.
*
* This request uses a slightly different format for card data to
* the other requests and does not require the card data to be
* complete in full (or valid).
*
* @return array
*/
protected function getCardData()
{
$data = array();
$card = $this->getCard();
if (!empty($card)) {
if ($card->getExpiryMonth()) {
$data['exp_month'] = $card->getExpiryMonth();
}
if ($card->getExpiryYear()) {
$data['exp_year'] = $card->getExpiryYear();
}
}
return $data;
}
/**
* Return an array of the billing details.
*/
public function getBillingDetails()
{
$data = parent::getCardData();
// Take care of optional data by filtering it out.
return array_filter([
'email' => $data['email'],
'name' => $data['name'],
'address' => array_filter([
'city' => $data['address_city'],
'country' => $data['address_country'],
'line1' => $data['address_line1'],
'line2' => $data['address_line2'],
'postal_code' => $data['address_zip'],
'state' => $data['address_state'],
]),
]);
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}