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

8
vendor/omnipay/stripe/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
/vendor
composer.lock
composer.phar
phpunit.xml
.directory
/dirlist.*
/documents/
/.idea/

31
vendor/omnipay/stripe/.travis.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false
## Cache composer
cache:
directories:
- $HOME/.composer/cache
env:
global:
- setup=basic
matrix:
include:
- php: 5.6
env: setup=lowest
install:
- if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi
script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text

10
vendor/omnipay/stripe/CONTRIBUTING.md vendored Normal file
View File

@@ -0,0 +1,10 @@
# Contributing Guidelines
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
* Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files.
* Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
style and that all tests pass.
* Send the pull request.
* Check that the Travis CI build passed. If not, rinse and repeat.

20
vendor/omnipay/stripe/LICENSE vendored Normal file
View File

@@ -0,0 +1,20 @@
Copyright (c) 2012-2013 Adrian Macneil
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

154
vendor/omnipay/stripe/README.md vendored Normal file
View File

@@ -0,0 +1,154 @@
# Omnipay: Stripe
**Stripe driver for the Omnipay PHP payment processing library**
[![Build Status](https://travis-ci.org/thephpleague/omnipay-stripe.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-stripe)
[![Latest Stable Version](https://poser.pugx.org/omnipay/stripe/version.png)](https://packagist.org/packages/omnipay/stripe)
[![Total Downloads](https://poser.pugx.org/omnipay/stripe/d/total.png)](https://packagist.org/packages/omnipay/stripe)
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
processing library for PHP. This package implements Stripe support for Omnipay.
## Installation
Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `omnipay/stripe` with Composer:
```
composer require league/omnipay omnipay/stripe
```
## Basic Usage
The following gateways are provided by this package:
* [Stripe Charge](https://stripe.com/docs/charges)
* [Stripe Payment Intents](https://stripe.com/docs/payments/payment-intents)
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.
### Stripe.js
The Stripe integration is fairly straight forward. Essentially you just pass
a `token` field through to Stripe instead of the regular credit card data.
Start by following the standard Stripe JS guide here:
[https://stripe.com/docs/tutorials/forms](https://stripe.com/docs/tutorials/forms)
After that you will have a `stripeToken` field which will be submitted to your server.
Simply pass this through to the gateway as `token`, instead of the usual `card` array:
```php
$token = $_POST['stripeToken'];
$response = $gateway->purchase([
'amount' => '10.00',
'currency' => 'USD',
'token' => $token,
])->send();
```
### Stripe Payment Intents
Stripe Payment Intents is the Stripe's new foundational payment API. As opposed to Charges API, Payment Intents supports [Strong Customer Authentication](https://stripe.com/docs/strong-customer-authentication). It means that during the payment process, the user _might_ be redirected to an off-site page hosted by the customer's bank for authentication purposes.
This plugin's implementation uses the manual Payment Intent confirmation flow, which is pretty similar to the one the Charges API uses. It shouldn't be too hard to modify your current payment flow.
1) Start by [collecting the payment method details](https://stripe.com/docs/payments/payment-intents/quickstart#collect-payment-method) from the customer. Alternatively, if the customer has provided this earlier and has saved a payment method in your system, you can re-use that.
2) Proceed to authorize or purchase as when using the Charges API.
```php
$paymentMethod = $_POST['paymentMethodId'];
$response = $gateway->authorize([
'amount' => '10.00',
'currency' => 'USD',
'description' => 'This is a test purchase transaction.',
'paymentMethod' => $paymentMethod,
'returnUrl' => $completePaymentUrl,
'confirm' => true,
])->send();
```
* If you have a token, instead of a payment method, you can use that by setting the `token` parameter, instead of setting the `paymentMethod` parameter.
* The `returnUrl` must point to where you would redirect every off-site gateway. This parameter is mandatory, if `confirm` is set to true.
* If you don't set the `confirm` parameter to `true`, you will have to manually confirm the payment intent as shown below.
```php
$paymentIntentReference = $response->getPaymentIntentReference();
$response = $gateway->confirm([
'paymentIntentReference' => $paymentIntentReference,
'returnUrl' => $completePaymentUrl,
])->send();
```
At this point, you'll need to save a reference to the payment intent. `$_SESSION` can be used for this purpose, but a more common pattern is to have a reference to the current order encoded in the `$completePaymentUrl` URL. In this case, now would be an excellent time to save the relationship between the order and the payment intent somewhere so that you can retrieve the payment intent reference at a later point.
3) Check if the payment is successful. If it is, that means the 3DS authentication was not required. This decision is up to Stripe (taking into account any custom Radar rules you have set) and the issuing bank.
```php
if ($response->isSuccessful()) {
// Pop open that champagne bottle, because the payment is complete.
} else if($response->isRedirect()) {
$response->redirect();
} else {
// The payment has failed. Use $response->getMessage() to figure out why and return to step (1).
}
```
4) The customer is redirected to the 3DS authentication page. Once they authenticate (or fail to do so), the customer is redirected to the URL specified earlier with `completePaymentUrl`.
5) Retrieve the `$paymentIntentReference` mentioned at the end of step (2).
6) Now we have to confirm the payment intent, to signal Stripe that everything is under control.
```php
$response = $gateway->confirm([
'paymentIntentReference' => $paymentIntentReference,
'returnUrl' => $completePaymentUrl,
])->send();
if ($response->isSuccessful()) {
// All done!! Big bucks!
} else {
// The response will not be successful if the 3DS authentication process failed or the card has been declined. Either way, it's back to step (1)!
}
```
### Stripe Connect
Stripe connect applications can charge an additional fee on top of Stripe's fees for charges they make on behalf of
their users. To do this you need to specify an additional `transactionFee` parameter as part of an authorize or purchase
request.
When a charge is refunded the transaction fee is refunded with an amount proportional to the amount of the charge
refunded and by default this will come from your connected user's Stripe account effectively leaving them out of pocket.
To refund from your (the applications) Stripe account instead you can pass a ``refundApplicationFee`` parameter with a
boolean value of true as part of a refund request.
Note: making requests with Stripe Connect specific parameters can only be made using the OAuth access token you received
as part of the authorization process. Read more on Stripe Connect [here](https://stripe.com/docs/connect).
## Test Mode
Stripe accounts have test-mode API keys as well as live-mode API keys. These keys can be active
at the same time. Data created with test-mode credentials will never hit the credit card networks
and will never cost anyone money.
Unlike some gateways, there is no test mode endpoint separate to the live mode endpoint, the
Stripe API endpoint is the same for test and for live.
## Support
If you are having general issues with Omnipay, we suggest posting on
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.
If you want to keep up to date with release announcements, discuss ideas for the project,
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
you can subscribe to.
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-stripe/issues),
or better yet, fork the library and submit a pull request.

42
vendor/omnipay/stripe/composer.json vendored Normal file
View File

@@ -0,0 +1,42 @@
{
"name": "omnipay/stripe",
"type": "library",
"description": "Stripe driver for the Omnipay payment processing library",
"keywords": [
"gateway",
"merchant",
"omnipay",
"pay",
"payment",
"stripe"
],
"homepage": "https://github.com/thephpleague/omnipay-stripe",
"license": "MIT",
"authors": [
{
"name": "Adrian Macneil",
"email": "adrian@adrianmacneil.com"
},
{
"name": "Omnipay Contributors",
"homepage": "https://github.com/thephpleague/omnipay-stripe/contributors"
}
],
"autoload": {
"psr-4": { "Omnipay\\Stripe\\" : "src/" }
},
"require": {
"omnipay/common": "^3"
},
"require-dev": {
"omnipay/tests": "^3",
"squizlabs/php_codesniffer": "^3",
"phpro/grumphp": "^0.14"
},
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
}
},
"prefer-stable": true
}

15
vendor/omnipay/stripe/grumphp.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
parameters:
git_dir: .
bin_dir: vendor/bin
tasks:
phpunit:
config_file: ~
testsuite: ~
group: []
always_execute: false
phpcs:
standard: PSR2
warning_severity: ~
ignore_patterns:
- tests/
triggered_by: [php]

146
vendor/omnipay/stripe/makedoc.sh vendored Normal file
View File

@@ -0,0 +1,146 @@
#!/bin/sh
#
# Smart little documentation generator.
# GPL/LGPL
# (c) Del 2015 http://www.babel.com.au/
#
APPNAME='Omnipay Stripe Gateway Module'
CMDFILE=apigen.cmd.$$
DESTDIR=./documents
#
# Find apigen, either in the path or as a local phar file
#
if [ -f apigen.phar ]; then
APIGEN="php apigen.phar"
else
APIGEN=`which apigen`
if [ ! -f "$APIGEN" ]; then
# Search for phpdoc if apigen is not found.
if [ -f phpDocumentor.phar ]; then
PHPDOC="php phpDocumentor.phar"
else
PHPDOC=`which phpdoc`
if [ ! -f "$PHPDOC" ]; then
echo "Neither apigen nor phpdoc is installed in the path or locally, please install one of them"
echo "see http://www.apigen.org/ or http://www.phpdoc.org/"
exit 1
fi
fi
fi
fi
#
# As of version 4 of apigen need to use the generate subcommand
#
if [ ! -z "$APIGEN" ]; then
APIGEN="$APIGEN generate"
fi
#
# Without any arguments this builds the entire system documentation,
# making the cache file first if required.
#
if [ -z "$1" ]; then
#
# Check to see that the cache has been made.
#
if [ ! -f dirlist.cache ]; then
echo "Making dirlist.cache file"
$0 makecache
fi
#
# Build the apigen/phpdoc command in a file.
#
if [ ! -z "$APIGEN" ]; then
echo "$APIGEN --php --tree --title '$APPNAME API Documentation' --destination $DESTDIR/main \\" > $CMDFILE
cat dirlist.cache | while read dir; do
echo "--source $dir \\" >> $CMDFILE
done
echo "" >> $CMDFILE
elif [ ! -z "$PHPDOC" ]; then
echo "$PHPDOC --sourcecode --title '$APPNAME API Documentation' --target $DESTDIR/main --directory \\" > $CMDFILE
cat dirlist.cache | while read dir; do
echo "${dir},\\" >> $CMDFILE
done
echo "" >> $CMDFILE
else
"Neither apigen nor phpdoc are found, how did I get here?"
exit 1
fi
#
# Run the apigen command
#
rm -rf $DESTDIR/main
mkdir -p $DESTDIR/main
. ./$CMDFILE
/bin/rm -f ./$CMDFILE
#
# The "makecache" argument causes the script to just make the cache file
#
elif [ "$1" = "makecache" ]; then
echo "Find application source directories"
find src -name \*.php -print | \
(
while read file; do
grep -q 'class' $file && dirname $file
done
) | sort -u | \
grep -v -E 'config|docs|migrations|phpunit|test|Test|views|web' > dirlist.app
echo "Find vendor source directories"
find vendor -name \*.php -print | \
(
while read file; do
grep -q 'class' $file && dirname $file
done
) | sort -u | \
grep -v -E 'config|docs|migrations|phpunit|codesniffer|test|Test|views' > dirlist.vendor
#
# Filter out any vendor directories for which apigen fails
#
echo "Filter source directories"
mkdir -p $DESTDIR/tmp
cat dirlist.app dirlist.vendor | while read dir; do
if [ ! -z "$APIGEN" ]; then
$APIGEN --quiet --title "Test please ignore" \
--source $dir \
--destination $DESTDIR/tmp && (
echo "Including $dir"
echo $dir >> dirlist.cache
) || (
echo "Excluding $dir"
)
elif [ ! -z "$PHPDOC" ]; then
$PHPDOC --quiet --title "Test please ignore" \
--directory $dir \
--target $DESTDIR/tmp && (
echo "Including $dir"
echo $dir >> dirlist.cache
) || (
echo "Excluding $dir"
)
fi
done
echo "Documentation cache dirlist.cache built OK"
#
# Clean up
#
/bin/rm -rf $DESTDIR/tmp
fi

22
vendor/omnipay/stripe/phpunit.xml.dist vendored Normal file
View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Omnipay Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>

25
vendor/omnipay/stripe/runtests.sh vendored Normal file
View File

@@ -0,0 +1,25 @@
#!/bin/sh
#
# Command line runner for unit tests for composer projects
# (c) Del 2015 http://www.babel.com.au/
# No Rights Reserved
#
#
# Clean up after any previous test runs
#
mkdir -p documents
rm -rf documents/coverage-html-new
rm -f documents/coverage.xml
#
# Run phpunit
#
vendor/bin/phpunit --coverage-html documents/coverage-html-new --coverage-clover documents/coverage.xml
if [ -d documents/coverage-html-new ]; then
rm -rf documents/coverage-html
mv documents/coverage-html-new documents/coverage-html
fi

View File

@@ -0,0 +1,720 @@
<?php
/**
* Stripe base gateway.
*/
namespace Omnipay\Stripe;
use Omnipay\Common\AbstractGateway as AbstractOmnipayGateway;
/**
* Stripe Gateway.
*
* Example:
*
* <code>
* // Create a gateway for the Stripe Gateway
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('Stripe');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'apiKey' => 'MyApiKey',
* ));
*
* // Create 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',
* ));
*
* // Do a purchase transaction on the gateway
* $transaction = $gateway->purchase(array(
* 'amount' => '10.00',
* 'currency' => 'USD',
* 'card' => $card,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Purchase transaction was successful!\n";
* $sale_id = $response->getTransactionReference();
* echo "Transaction reference = " . $sale_id . "\n";
*
* $balance_transaction_id = $response->getBalanceTransactionReference();
* echo "Balance Transaction reference = " . $balance_transaction_id . "\n";
* }
* </code>
*
* Test modes:
*
* Stripe accounts have test-mode API keys as well as live-mode
* API keys. These keys can be active at the same time. Data
* created with test-mode credentials will never hit the credit
* card networks and will never cost anyone money.
*
* Unlike some gateways, there is no test mode endpoint separate
* to the live mode endpoint, the Stripe API endpoint is the same
* for test and for live.
*
* Setting the testMode flag on this gateway has no effect. To
* use test mode just use your test mode API key.
*
* You can use any of the cards listed at https://stripe.com/docs/testing
* for testing.
*
* Authentication:
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
*
* @see \Omnipay\Common\AbstractGateway
* @see \Omnipay\Stripe\Message\AbstractRequest
*
* @link https://stripe.com/docs/api
*
* @method \Omnipay\Common\Message\RequestInterface completeAuthorize(array $options = array())
* @method \Omnipay\Common\Message\RequestInterface completePurchase(array $options = array())
*/
abstract class AbstractGateway extends AbstractOmnipayGateway
{
const BILLING_PLAN_FREQUENCY_DAY = 'day';
const BILLING_PLAN_FREQUENCY_WEEK = 'week';
const BILLING_PLAN_FREQUENCY_MONTH = 'month';
const BILLING_PLAN_FREQUENCY_YEAR = 'year';
/**
* @inheritdoc
*/
abstract public function getName();
/**
* Get the gateway parameters.
*
* @return array
*/
public function getDefaultParameters()
{
return array(
'apiKey' => '',
'stripeVersion' => null
);
}
/**
* Get the gateway API Key.
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
*
* @return string
*/
public function getApiKey()
{
return $this->getParameter('apiKey');
}
/**
* Set the gateway API Key.
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
*
* Stripe accounts have test-mode API keys as well as live-mode
* API keys. These keys can be active at the same time. Data
* created with test-mode credentials will never hit the credit
* card networks and will never cost anyone money.
*
* Unlike some gateways, there is no test mode endpoint separate
* to the live mode endpoint, the Stripe API endpoint is the same
* for test and for live.
*
* Setting the testMode flag on this gateway has no effect. To
* use test mode just use your test mode API key.
*
* @param string $value
*
* @return Gateway provides a fluent interface.
*/
public function setApiKey($value)
{
return $this->setParameter('apiKey', $value);
}
/**
* @return string
*/
public function getStripeVersion()
{
return $this->getParameter('stripeVersion');
}
/**
* @param string $value
*
* @return Gateway
*/
public function setStripeVersion($value)
{
return $this->setParameter('stripeVersion', $value);
}
/**
* 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.
*
* Either a customerReference or a card is required. If a customerReference
* is passed in then the cardReference must be the reference of a card
* assigned to the customer. Otherwise, if you do not pass a customer ID,
* the card you provide must either be a token, like the ones returned by
* Stripe.js, or a dictionary containing a user's credit card details.
*
* IN OTHER WORDS: You cannot just pass a card reference into this request,
* you must also provide a customer reference if you want to use a stored
* card.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\AbstractRequest
*/
abstract public function authorize(array $parameters = array());
/**
* Capture Request.
*
* Use this request to capture and process a previously created authorization.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\AbstractRequest
*/
abstract public function capture(array $parameters = array());
/**
* Purchase request.
*
* To charge a credit card, you create a new charge object. If your API key
* is in test mode, the supplied card won't actually be charged, though
* everything else will occur as if in live mode. (Stripe assumes that the
* charge would have completed successfully).
*
* Either a customerReference or a card is required. If a customerReference
* is passed in then the cardReference must be the reference of a card
* assigned to the customer. Otherwise, if you do not pass a customer ID,
* the card you provide must either be a token, like the ones returned by
* Stripe.js, or a dictionary containing a user's credit card details.
*
* IN OTHER WORDS: You cannot just pass a card reference into this request,
* you must also provide a customer reference if you want to use a stored
* card.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\AbstractRequest
*/
abstract public function purchase(array $parameters = array());
/**
* Refund Request.
*
* When you create a new refund, you must specify a
* charge to create it on.
*
* Creating a new refund will refund a charge that has
* previously been created but not yet refunded. Funds will
* be refunded to the credit or debit card that was originally
* charged. The fees you were originally charged are also
* refunded.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\RefundRequest
*/
public function refund(array $parameters = [])
{
return $this->createRequest('\Omnipay\Stripe\Message\RefundRequest', $parameters);
}
/**
* Void a transaction.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\VoidRequest
*/
public function void(array $parameters = [])
{
return $this->createRequest('\Omnipay\Stripe\Message\VoidRequest', $parameters);
}
/**
* Fetch a transaction.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\FetchTransactionRequest
*/
public function fetchTransaction(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchTransactionRequest', $parameters);
}
/**
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchBalanceTransactionRequest
*/
public function fetchBalanceTransaction(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchBalanceTransactionRequest', $parameters);
}
//
// Application Fees
// @link https://stripe.com/docs/api#application_fees
//
/**
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\FetchApplicationFeeRequest
*/
public function fetchApplicationFee(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchApplicationFeeRequest', $parameters);
}
//
// Transfers
// @link https://stripe.com/docs/api#transfers
//
/**
* Transfer Request.
*
* To send funds from your Stripe account to a connected account, you create
* a new transfer object. Your Stripe balance must be able to cover the
* transfer amount, or you'll receive an "Insufficient Funds" error.
*
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function transfer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\CreateTransferRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function fetchTransfer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\FetchTransferRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function updateTransfer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\UpdateTransferRequest', $parameters);
}
/**
* List Transfers
*
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest|\Omnipay\Stripe\Message\Transfers\ListTransfersRequest
*/
public function listTransfers(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\ListTransfersRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function reverseTransfer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\CreateTransferReversalRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function fetchTransferReversal(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\FetchTransferReversalRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function updateTransferReversal(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\UpdateTransferReversalRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function listTransferReversals(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\Transfers\ListTransferReversalsRequest', $parameters);
}
//
// Cards
// @link https://stripe.com/docs/api#cards
//
/**
* Create Card.
*
* This call can be used to create a new customer or add a card
* to an existing customer. If a customerReference is passed in then
* a card is added to an existing customer. If there is no
* customerReference passed in then a new customer is created. The
* response in that case will then contain both a customer token
* and a card token, and is essentially the same as CreateCustomerRequest
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\AbstractRequest
*/
public function createCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateCardRequest', $parameters);
}
/**
* Update Card.
*
* If you need to update only some card details, like the billing
* address or expiration date, you can do so without having to re-enter
* the full card details. Stripe also works directly with card networks
* so that your customers can continue using your service without
* interruption.
*
* When you update a card, Stripe will automatically validate the card.
*
* This requires both a customerReference and a cardReference.
*
* @link https://stripe.com/docs/api#update_card
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\AbstractRequest
*/
public function updateCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\UpdateCardRequest', $parameters);
}
/**
* Delete a card.
*
* This is normally used to delete a credit card from an existing
* customer.
*
* You can delete cards from a customer or recipient. If you delete a
* card that is currently the default card on a customer or recipient,
* the most recently added card will be used as the new default. If you
* delete the last remaining card on a customer or recipient, the
* default_card attribute on the card's owner will become null.
*
* Note that for cards belonging to customers, you may want to prevent
* customers on paid subscriptions from deleting all cards on file so
* that there is at least one default card for the next invoice payment
* attempt.
*
* In deference to the previous incarnation of this gateway, where
* all CreateCard requests added a new customer and the customer ID
* was used as the card ID, if a cardReference is passed in but no
* customerReference then we assume that the cardReference is in fact
* a customerReference and delete the customer. This might be
* dangerous but it's the best way to ensure backwards compatibility.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\AbstractRequest
*/
public function deleteCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeleteCardRequest', $parameters);
}
//
// Customers
// link: https://stripe.com/docs/api#customers
//
/**
* Create Customer.
*
* Customer objects allow you to perform recurring charges and
* track multiple charges that are associated with the same customer.
* The API allows you to create, delete, and update your customers.
* You can retrieve individual customers as well as a list of all of
* your customers.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\CreateCustomerRequest
*/
public function createCustomer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateCustomerRequest', $parameters);
}
/**
* Fetch Customer.
*
* Fetches customer by customer reference.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\FetchCustomerRequest
*/
public function fetchCustomer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchCustomerRequest', $parameters);
}
/**
* Update Customer.
*
* This request updates the specified customer by setting the values
* of the parameters passed. Any parameters not provided will be left
* unchanged. For example, if you pass the card parameter, that becomes
* the customer's active card to be used for all charges in the future,
* and the customer email address is updated to the email address
* on the card. When you update a customer to a new valid card: for
* each of the customer's current subscriptions, if the subscription
* is in the `past_due` state, then the latest unpaid, unclosed
* invoice for the subscription will be retried (note that this retry
* will not count as an automatic retry, and will not affect the next
* regularly scheduled payment for the invoice). (Note also that no
* invoices pertaining to subscriptions in the `unpaid` state, or
* invoices pertaining to canceled subscriptions, will be retried as
* a result of updating the customer's card.)
*
* This request accepts mostly the same arguments as the customer
* creation call.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\CreateCustomerRequest
*/
public function updateCustomer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\UpdateCustomerRequest', $parameters);
}
/**
* Delete a customer.
*
* Permanently deletes a customer. It cannot be undone. Also immediately
* cancels any active subscriptions on the customer.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\DeleteCustomerRequest
*/
public function deleteCustomer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeleteCustomerRequest', $parameters);
}
/**
* Create Plan
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreatePlanRequest
*/
public function createPlan(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreatePlanRequest', $parameters);
}
/**
* Fetch Plan
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchPlanRequest
*/
public function fetchPlan(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchPlanRequest', $parameters);
}
/**
* Delete Plan
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\DeletePlanRequest
*/
public function deletePlan(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeletePlanRequest', $parameters);
}
/**
* List Plans
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\ListPlansRequest
*/
public function listPlans(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\ListPlansRequest', $parameters);
}
/**
* Create Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateSubscriptionRequest
*/
public function createSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateSubscriptionRequest', $parameters);
}
/**
* Fetch Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchSubscriptionRequest
*/
public function fetchSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchSubscriptionRequest', $parameters);
}
/**
* Update Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\UpdateSubscriptionRequest
*/
public function updateSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\UpdateSubscriptionRequest', $parameters);
}
/**
* Cancel Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CancelSubscriptionRequest
*/
public function cancelSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CancelSubscriptionRequest', $parameters);
}
/**
* Fetch Event
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchEventRequest
*/
public function fetchEvent(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchEventRequest', $parameters);
}
/**
* Fetch Invoice Lines
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchInvoiceLinesRequest
*/
public function fetchInvoiceLines(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchInvoiceLinesRequest', $parameters);
}
/**
* Fetch Invoice
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchInvoiceRequest
*/
public function fetchInvoice(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchInvoiceRequest', $parameters);
}
/**
* List Invoices
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\ListInvoicesRequest
*/
public function listInvoices(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\ListInvoicesRequest', $parameters);
}
/**
* Create Invoice Item
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateInvoiceItemRequest
*/
public function createInvoiceItem(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateInvoiceItemRequest', $parameters);
}
/**
* Fetch Invoice Item
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchInvoiceItemRequest
*/
public function fetchInvoiceItem(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchInvoiceItemRequest', $parameters);
}
/**
* Delete Invoice Item
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\DeleteInvoiceItemRequest
*/
public function deleteInvoiceItem(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeleteInvoiceItemRequest', $parameters);
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Stripe Payment Intents Gateway.
*/
namespace Omnipay\Stripe;
/**
* Stripe Payment Intents Gateway.
*
* @see \Omnipay\Stripe\AbstractGateway
* @see \Omnipay\Stripe\Message\AbstractRequest
* @link https://stripe.com/docs/api
* @method \Omnipay\Common\Message\NotificationInterface acceptNotification(array $options = array())
* @method \Omnipay\Common\Message\RequestInterface refund(array $options = array())
* @method \Omnipay\Common\Message\RequestInterface void(array $options = array())
*/
class CheckoutGateway extends AbstractGateway
{
/**
* @inheritdoc
*/
public function getName()
{
return 'Stripe Checkout';
}
/**
* @inheritdoc
* @return \Omnipay\Stripe\Message\Checkout\PurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->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);
}
}

420
vendor/omnipay/stripe/src/Gateway.php vendored Normal file
View File

@@ -0,0 +1,420 @@
<?php
/**
* Stripe Charge Gateway.
*/
namespace Omnipay\Stripe;
/**
* Stripe Charge Gateway.
*
* @see \Omnipay\Stripe\AbstractGateway
* @see \Omnipay\Stripe\Message\AbstractRequest
*
* @link https://stripe.com/docs/api
*
*/
class Gateway extends AbstractGateway
{
/**
* @inheritdoc
*/
public function getName()
{
return 'Stripe Charge';
}
/**
* @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);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PurchaseRequest', $parameters);
}
/**
* @deprecated 2.3.3:3.0.0 duplicate of \Omnipay\Stripe\Gateway::fetchTransaction()
* @see \Omnipay\Stripe\Gateway::fetchTransaction()
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchChargeRequest
*/
public function fetchCharge(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchChargeRequest', $parameters);
}
//
// Cards
// @link https://stripe.com/docs/api#cards
//
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\CreateCardRequest
*/
public function createCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateCardRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\UpdateCardRequest
*/
public function updateCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\UpdateCardRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\DeleteCardRequest
*/
public function deleteCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeleteCardRequest', $parameters);
}
//
// Tokens
// @link https://stripe.com/docs/api#tokens
//
/**
* Creates a single use token that wraps the details of a credit card.
* This token can be used in place of a credit card associative array with any API method.
* These tokens can only be used once: by creating a new charge object, or attaching them to a customer.
*
* This kind of token is also useful when sharing clients between one platform and a connect account.
* Use this request to create a new token to make a direct charge on a customer of the platform.
*
* @param array $parameters parameters to be passed in to the TokenRequest.
* @return \Omnipay\Stripe\Message\CreateTokenRequest The create token request.
*/
public function createToken(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateTokenRequest', $parameters);
}
/**
* Stripe Fetch Token Request.
*
* Often you want to be able to charge credit cards or send payments
* to bank accounts without having to hold sensitive card information
* on your own servers. Stripe.js makes this easy in the browser, but
* you can use the same technique in other environments with our token API.
*
* Tokens can be created with your publishable API key, which can safely
* be embedded in downloadable applications like iPhone and Android apps.
* You can then use a token anywhere in our API that a card or bank account
* is accepted. Note that tokens are not meant to be stored or used more
* than once—to store these details for use later, you should create
* Customer or Recipient objects.
*
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\FetchTokenRequest
*/
public function fetchToken(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchTokenRequest', $parameters);
}
/**
* Create Plan
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreatePlanRequest
*/
public function createPlan(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreatePlanRequest', $parameters);
}
/**
* Fetch Plan
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchPlanRequest
*/
public function fetchPlan(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchPlanRequest', $parameters);
}
/**
* Delete Plan
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\DeletePlanRequest
*/
public function deletePlan(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeletePlanRequest', $parameters);
}
/**
* List Plans
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\ListPlansRequest
*/
public function listPlans(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\ListPlansRequest', $parameters);
}
/**
* Create Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateSubscriptionRequest
*/
public function createSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateSubscriptionRequest', $parameters);
}
/**
* Fetch Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchSubscriptionRequest
*/
public function fetchSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchSubscriptionRequest', $parameters);
}
/**
* Update Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\UpdateSubscriptionRequest
*/
public function updateSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\UpdateSubscriptionRequest', $parameters);
}
/**
* Cancel Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CancelSubscriptionRequest
*/
public function cancelSubscription(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CancelSubscriptionRequest', $parameters);
}
/**
* Fetch Schedule Subscription
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchSubscriptionSchedulesRequest
*/
public function fetchSubscriptionSchedules(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchSubscriptionSchedulesRequest', $parameters);
}
/**
* Fetch Event
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchEventRequest
*/
public function fetchEvent(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchEventRequest', $parameters);
}
/**
* Fetch Invoice Lines
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchInvoiceLinesRequest
*/
public function fetchInvoiceLines(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchInvoiceLinesRequest', $parameters);
}
/**
* Fetch Invoice
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchInvoiceRequest
*/
public function fetchInvoice(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchInvoiceRequest', $parameters);
}
/**
* List Invoices
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\ListInvoicesRequest
*/
public function listInvoices(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\ListInvoicesRequest', $parameters);
}
/**
* Create Invoice Item
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateInvoiceItemRequest
*/
public function createInvoiceItem(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateInvoiceItemRequest', $parameters);
}
/**
* Fetch Invoice Item
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchInvoiceItemRequest
*/
public function fetchInvoiceItem(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchInvoiceItemRequest', $parameters);
}
/**
* Delete Invoice Item
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\DeleteInvoiceItemRequest
*/
public function deleteInvoiceItem(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeleteInvoiceItemRequest', $parameters);
}
/**
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateSourceRequest
*/
public function createSource(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateSourceRequest', $parameters);
}
/**
* @param array $parameters
* @return \Omnipay\Stripe\Message\AttachSourceRequest
*/
public function attachSource(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\AttachSourceRequest', $parameters);
}
/**
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchSourceRequest
*/
public function detachSource(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DetachSourceRequest', $parameters);
}
/**
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchSourceRequest
*/
public function fetchSource(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchSourceRequest', $parameters);
}
/**
* Create a completePurchase request.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CompletePurchaseRequest
*/
public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CompletePurchaseRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function createCoupon(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateCouponRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function fetchCoupon(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchCouponRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function deleteCoupon(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeleteCouponRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function updateCoupon(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\UpdateCouponRequest', $parameters);
}
/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function listCoupons(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\ListCouponsRequest', $parameters);
}
}

View File

@@ -0,0 +1,390 @@
<?php
/**
* Stripe Abstract Request.
*/
namespace Omnipay\Stripe\Message;
use Money\Currency;
use Money\Money;
use Money\Number;
use Money\Parser\DecimalMoneyParser;
use Omnipay\Common\Exception\InvalidRequestException;
/**
* Stripe Abstract Request.
*
* This is the parent class for all Stripe requests.
*
* Test modes:
*
* Stripe accounts have test-mode API keys as well as live-mode
* API keys. These keys can be active at the same time. Data
* created with test-mode credentials will never hit the credit
* card networks and will never cost anyone money.
*
* Unlike some gateways, there is no test mode endpoint separate
* to the live mode endpoint, the Stripe API endpoint is the same
* for test and for live.
*
* Setting the testMode flag on this gateway has no effect. To
* use test mode just use your test mode API key.
*
* You can use any of the cards listed at https://stripe.com/docs/testing
* for testing.
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api
*/
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
/**
* Live or Test Endpoint URL.
*
* @var string URL
*/
protected $endpoint = 'https://api.stripe.com/v1';
/**
* Get the gateway API Key.
*
* @return string
*/
public function getApiKey()
{
return $this->getParameter('apiKey');
}
/**
* Set the gateway API Key.
*
* @return AbstractRequest provides a fluent interface.
*/
public function setApiKey($value)
{
return $this->setParameter('apiKey', $value);
}
/**
* @deprecated
*/
public function getCardToken()
{
return $this->getCardReference();
}
/**
* @deprecated
*/
public function setCardToken($value)
{
return $this->setCardReference($value);
}
/**
* Get the customer reference.
*
* @return string
*/
public function getCustomerReference()
{
return $this->getParameter('customerReference');
}
/**
* Set the customer reference.
*
* Used when calling CreateCard on an existing customer. If this
* parameter is not set then a new customer is created.
*
* @return AbstractRequest provides a fluent interface.
*/
public function setCustomerReference($value)
{
return $this->setParameter('customerReference', $value);
}
public function getMetadata()
{
return $this->getParameter('metadata');
}
public function setMetadata($value)
{
return $this->setParameter('metadata', $value);
}
/**
* Connect only
*
* @return mixed
*/
public function getConnectedStripeAccountHeader()
{
return $this->getParameter('connectedStripeAccount');
}
/**
* @param string $value
*
* @return AbstractRequest
*/
public function setConnectedStripeAccountHeader($value)
{
return $this->setParameter('connectedStripeAccount', $value);
}
/**
* Connect only
*
* @return mixed
*/
public function getIdempotencyKeyHeader()
{
return $this->getParameter('idempotencyKey');
}
/**
*
* @return string
*/
public function getStripeVersion()
{
return $this->getParameter('stripeVersion');
}
/**
* @param string $value
*
* @return AbstractRequest
*/
public function setStripeVersion($value)
{
return $this->setParameter('stripeVersion', $value);
}
/**
* @param string $value
*
* @return AbstractRequest
*/
public function setIdempotencyKeyHeader($value)
{
return $this->setParameter('idempotencyKey', $value);
}
/**
* @return array
*/
public function getExpand()
{
return $this->getParameter('expand');
}
/**
* Specifies which object relations (IDs) in the response should be expanded to include the entire object.
*
* @see https://stripe.com/docs/api/expanding_objects
*
* @param array $value
* @return AbstractRequest
*/
public function setExpand($value)
{
return $this->setParameter('expand', $value);
}
abstract public function getEndpoint();
/**
* Get HTTP Method.
*
* This is nearly always POST but can be over-ridden in sub classes.
*
* @return string
*/
public function getHttpMethod()
{
return 'POST';
}
/**
* @return array
*/
public function getHeaders()
{
$headers = array();
if ($this->getConnectedStripeAccountHeader()) {
$headers['Stripe-Account'] = $this->getConnectedStripeAccountHeader();
}
if ($this->getIdempotencyKeyHeader()) {
$headers['Idempotency-Key'] = $this->getIdempotencyKeyHeader();
}
if ($this->getStripeVersion()) {
$headers['Stripe-Version'] = $this->getStripeVersion();
}
return $headers;
}
/**
* {@inheritdoc}
*/
public function sendData($data)
{
$headers = array_merge(
$this->getHeaders(),
array('Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':'))
);
$body = $data ? http_build_query($data, '', '&') : null;
$httpResponse = $this->httpClient->request(
$this->getHttpMethod(),
$this->getExpandedEndpoint(),
$headers,
$body
);
return $this->createResponse($httpResponse->getBody()->getContents(), $httpResponse->getHeaders());
}
/**
* Appends the `expand` properties to the endpoint as a querystring.
*
* @return string
*/
public function getExpandedEndpoint()
{
$endpoint = $this->getEndpoint();
$expand = $this->getExpand();
if (is_array($expand) && count($expand) > 0) {
$queryParams = [];
foreach ($expand as $key) {
$queryParams[] = 'expand[]=' . $key;
}
$queryString = join('&', $queryParams);
$endpoint .= '?' . $queryString;
}
return $endpoint;
}
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
/**
* @return mixed
*/
public function getSource()
{
return $this->getParameter('source');
}
/**
* @param $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setSource($value)
{
return $this->setParameter('source', $value);
}
/**
* @param string $parameterName
*
* @return null|Money
* @throws InvalidRequestException
*/
public function getMoney($parameterName = 'amount')
{
$amount = $this->getParameter($parameterName);
if ($amount instanceof Money) {
return $amount;
}
if ($amount !== null) {
$moneyParser = new DecimalMoneyParser($this->getCurrencies());
$currencyCode = $this->getCurrency() ?: 'USD';
$currency = new Currency($currencyCode);
$number = Number::fromString($amount);
// Check for rounding that may occur if too many significant decimal digits are supplied.
$decimal_count = strlen($number->getFractionalPart());
$subunit = $this->getCurrencies()->subunitFor($currency);
if ($decimal_count > $subunit) {
throw new InvalidRequestException('Amount precision is too high for currency.');
}
$money = $moneyParser->parse((string) $number, $currency->getCode());
// Check for a negative amount.
if (!$this->negativeAmountAllowed && $money->isNegative()) {
throw new InvalidRequestException('A negative amount is not allowed.');
}
// Check for a zero amount.
if (!$this->zeroAmountAllowed && $money->isZero()) {
throw new InvalidRequestException('A zero amount is not allowed.');
}
return $money;
}
}
/**
* Get the card data.
*
* Because the stripe gateway uses a common format for passing
* card data to the API, this function can be called to get the
* data from the associated card object in the format that the
* API requires.
*
* @return array
*/
protected function getCardData()
{
$card = $this->getCard();
$card->validate();
$data = array();
$data['object'] = 'card';
// If track data is present, only return data relevant to a card present charge
$tracks = $card->getTracks();
$cvv = $card->getCvv();
$postcode = $card->getPostcode();
if (!empty($postcode)) {
$data['address_zip'] = $postcode;
}
if (!empty($cvv)) {
$data['cvc'] = $cvv;
}
if (!empty($tracks)) {
$data['swipe_data'] = $tracks;
return $data;
}
// If we got here, it's a card not present transaction, so include everything we have
$data['number'] = $card->getNumber();
$data['exp_month'] = $card->getExpiryMonth();
$data['exp_year'] = $card->getExpiryYear();
$data['name'] = $card->getName();
$data['address_line1'] = $card->getAddress1();
$data['address_line2'] = $card->getAddress2();
$data['address_city'] = $card->getCity();
$data['address_state'] = $card->getState();
$data['address_country'] = $card->getCountry();
$data['email'] = $card->getEmail();
return $data;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* CreateSourceRequest
*/
namespace Omnipay\Stripe\Message;
/**
* Class CreateSourceRequest
*
* @link https://stripe.com/docs/api/sources/attach
*/
class AttachSourceRequest extends AbstractRequest
{
/**
* @return mixed
*/
public function getData()
{
$this->validate('customerReference', 'source');
$data['source'] = $this->getSource();
return $data;
}
/**
* @inheritdoc
*
* @return string The endpoint for the create token request.
*/
public function getEndpoint()
{
return $this->endpoint . '/customers/' . $this->getCustomerReference() . '/sources';
}
}

View File

@@ -0,0 +1,379 @@
<?php
/**
* Stripe Authorize Request.
*/
namespace Omnipay\Stripe\Message;
use Money\Formatter\DecimalMoneyFormatter;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\ItemBag;
use Omnipay\Stripe\StripeItem;
use Omnipay\Stripe\StripeItemBag;
/**
* Stripe 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.
*
* Either a customerReference or a card is required. If a customerReference
* is passed in then the cardReference must be the reference of a card
* assigned to the customer. Otherwise, if you do not pass a customer ID,
* the card you provide must either be a token, like the ones returned by
* Stripe.js, or a dictionary containing a user's credit card details.
*
* IN OTHER WORDS: You cannot just pass a card reference into this request,
* you must also provide a customer reference if you want to use a stored
* card.
*
* Example:
*
* <code>
* // Create a gateway for the Stripe Gateway
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('Stripe');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'apiKey' => 'MyApiKey',
* ));
*
* // Create 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',
* ));
*
* // Do an authorize transaction on the gateway
* $transaction = $gateway->authorize(array(
* 'amount' => '10.00',
* 'currency' => 'USD',
* 'description' => 'This is a test authorize transaction.',
* 'card' => $card,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Authorize transaction was successful!\n";
* $sale_id = $response->getTransactionReference();
* echo "Transaction reference = " . $sale_id . "\n";
* }
* </code>
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#charges
*/
class AuthorizeRequest extends AbstractRequest
{
/**
* @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 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 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);
}
public function getStatementDescriptor()
{
return $this->getParameter('statementDescriptor');
}
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;
}
/**
* A list of items in this order
*
* @return StripeItemBag|StripeItem[]|null A bag containing items in this order
*/
public function getItems()
{
return $this->getParameter('items');
}
/**
* Set the items in this order
*
* @param array $items An array of items in this order
* @return AuthorizeRequest
*/
public function setItems($items)
{
if ($items && !$items instanceof ItemBag) {
$items = new StripeItemBag($items);
}
return $this->setParameter('items', $items);
}
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();
$data['capture'] = 'false';
if ($items = $this->getItems()) {
if (empty($this->getDescription())) {
$itemDescriptions = [];
foreach ($items as $n => $item) {
$itemDescriptions[] = $item->getDescription();
}
$data['description'] = implode(" + ", $itemDescriptions);
}
if ($this->validateLineItemsForLevel3($items)) {
$lineItems = [];
foreach ($items as $item) {
$lineItem = [
'product_code' => substr($item->getName(), 0, 12),
'product_description' => substr($item->getDescription(), 0, 26)
];
if ($item->getPrice()) {
$lineItem['unit_cost'] = $this->getAmountWithCurrencyPrecision($item->getPrice());
}
if ($item->getQuantity()) {
$lineItem['quantity'] = $item->getQuantity();
}
if ($item->getTaxes()) {
$lineItem['tax_amount'] = $this->getAmountWithCurrencyPrecision($item->getTaxes());
}
if ($item->getDiscount()) {
$lineItem['discount_amount'] = $this->getAmountWithCurrencyPrecision($item->getDiscount());
}
$lineItems[] = $lineItem;
}
$data['level3'] = [
'merchant_reference' => $this->getTransactionId(),
'line_items' => $lineItems
];
}
}
if ($this->getStatementDescriptor()) {
$data['statement_descriptor'] = $this->getStatementDescriptor();
}
if ($this->getDestination()) {
$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->getSource()) {
$data['source'] = $this->getSource();
} elseif ($this->getCardReference()) {
$data['source'] = $this->getCardReference();
if ($this->getCustomerReference()) {
$data['customer'] = $this->getCustomerReference();
}
} elseif ($this->getToken()) {
$data['source'] = $this->getToken();
if ($this->getCustomerReference()) {
$data['customer'] = $this->getCustomerReference();
}
} elseif ($this->getCard()) {
$data['source'] = $this->getCardData();
} elseif ($this->getCustomerReference()) {
$data['customer'] = $this->getCustomerReference();
} else {
// one of cardReference, token, or card is required
$this->validate('source');
}
return $data;
}
private function getAmountWithCurrencyPrecision($amount)
{
return (int)round($amount * pow(10, $this->getCurrencyDecimalPlaces()));
}
/**
* For Stripe to accept Level 3 data, the sum of all the line items should equal the request's `amount`. This
* method validates that the summation adds up as expected.
*
* @param StripeItemBag $items
* @return bool
*/
private function validateLineItemsForLevel3(StripeItemBag $items)
{
$actualAmount = 0;
foreach ($items as $item) {
$actualAmount += $item->getQuantity() * $item->getPrice() + $item->getTaxes() - $item->getDiscount();
}
return (string)$actualAmount == (string)$this->getAmount();
}
public function getEndpoint()
{
return $this->endpoint . '/charges';
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* Stripe Cancel Subscription Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Cancel Subscription Request.
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/#cancel_subscription
*/
class CancelSubscriptionRequest extends AbstractRequest
{
/**
* Get the subscription reference.
*
* @return string
*/
public function getSubscriptionReference()
{
return $this->getParameter('subscriptionReference');
}
/**
* Set the set subscription reference.
*
* @param string $value
*
* @return CancelSubscriptionRequest provides a fluent interface.
*/
public function setSubscriptionReference($value)
{
return $this->setParameter('subscriptionReference', $value);
}
/**
* Set whether or not to cancel the subscription at period end.
*
* @param bool $value
*
* @return CancelSubscriptionRequest provides a fluent interface.
*/
public function setAtPeriodEnd($value)
{
return $this->setParameter('atPeriodEnd', $value);
}
/**
* Get whether or not to cancel the subscription at period end.
*
* @return bool
*/
public function getAtPeriodEnd()
{
return $this->getParameter('atPeriodEnd');
}
public function getData()
{
$this->validate('customerReference', 'subscriptionReference');
$data = array();
// NOTE: Boolean must be passed as string
// Otherwise it will be converted to numeric 0 or 1
// Causing an error with the API
if ($this->getAtPeriodEnd()) {
$data['at_period_end'] = 'true';
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint
.'/customers/'.$this->getCustomerReference()
.'/subscriptions/'.$this->getSubscriptionReference();
}
public function getHttpMethod()
{
return 'DELETE';
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Stripe Capture Request.
*/
namespace Omnipay\Stripe\Message;
/**
* 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 authorization ID returned from the authorization is held in $auth_id.
* 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->setTransactionReference($auth_id);
* $response = $transaction->send();
* </code>
*
* @see AuthorizeRequest
*/
class CaptureRequest extends AbstractRequest
{
public function getData()
{
$this->validate('transactionReference');
$data = array();
if ($amount = $this->getAmountInteger()) {
$data['amount'] = $amount;
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/charges/'.$this->getTransactionReference().'/capture';
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Stripe Abstract Request.
*/
namespace Omnipay\Stripe\Message\Checkout;
/**
* 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
{
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* Stripe Fetch Transaction Request.
*/
namespace Omnipay\Stripe\Message\Checkout;
/**
* Stripe Fetch Transaction Request.
* Example -- note this example assumes that the purchase has been successful
* and that the transaction ID returned from the purchase is held in $sale_id.
* See PurchaseRequest for the first part of this example transaction:
* <code>
* // 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";
* </code>
*
* @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';
}
}

View File

@@ -0,0 +1,166 @@
<?php
/**
* Stripe Checkout Session Request.
*/
namespace Omnipay\Stripe\Message\Checkout;
/**
* Stripe Checkout Session Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/checkout/sessions
*/
class PurchaseRequest extends AbstractRequest
{
/**
* Set the success url
*
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest|PurchaseRequest
*/
public function setSuccessUrl($value)
{
return $this->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';
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* CreateSourceRequest
*/
namespace Omnipay\Stripe\Message;
/**
* Class CreateSourceRequest
*
* TODO : Add docblock
*/
class CompletePurchaseRequest extends PurchaseRequest
{
public function getData()
{
$data = parent::getData();
return $data;
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* Stripe Create Credit Card Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Create Credit Card Request.
*
* In the stripe system, creating a credit card requires passing
* a customer ID. The card is then added to the customer's account.
* If the customer has no default card then the newly added
* card becomes the customer's default card.
*
* This call can be used to create a new customer or add a card
* to an existing customer. If a customerReference is passed in then
* a card is added to an existing customer. If there is no
* customerReference passed in then a new customer is created. The
* response in that case will then contain both a customer token
* and a card token, and is essentially the same as CreateCustomerRequest
*
* ### Example
*
* This example assumes that you have already created a
* customer, and that the customer reference is stored in $customer_id.
* See CreateCustomerRequest for the first part of this transaction.
*
* <code>
* // Create a credit card object
* // This card can be used for testing.
* // The CreditCard object is also used for creating customers.
* $new_card = new CreditCard(array(
* '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(array(
* 'card' => $new_card,
* 'customerReference' => $customer_id,
* ))->send();
* if ($response->isSuccessful()) {
* echo "Gateway createCard was successful.\n";
* // Find the card ID
* $card_id = $response->getCardReference();
* echo "Card ID = " . $card_id . "\n";
* }
* </code>
*
* @see CreateCustomerRequest
* @link https://stripe.com/docs/api#create_card
*/
class CreateCardRequest extends AbstractRequest
{
public function getData()
{
$data = array();
// Only set the description if we are creating a new customer.
if (!$this->getCustomerReference()) {
$data['description'] = $this->getDescription();
}
if ($this->getSource()) {
$data['source'] = $this->getSource();
} elseif ($this->getCardReference()) {
$data['source'] = $this->getCardReference();
} elseif ($this->getToken()) {
$data['source'] = $this->getToken();
} elseif ($this->getCard()) {
$this->getCard()->validate();
$data['source'] = $this->getCardData();
// Only set the email address if we are creating a new customer.
if (!$this->getCustomerReference()) {
$data['email'] = $this->getCard()->getEmail();
}
} else {
// one of token or card is required
$this->validate('source');
}
return $data;
}
public function getEndpoint()
{
if ($this->getCustomerReference()) {
// Create a new card on an existing customer
return $this->endpoint.'/customers/'.
$this->getCustomerReference().'/cards';
}
// Create a new customer and card
return $this->endpoint.'/customers';
}
public function getCardData()
{
$data = parent::getCardData();
unset($data['email']);
return $data;
}
}

View File

@@ -0,0 +1,201 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Common\Exception\InvalidRequestException;
/**
* Stripe Create Coupon Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/coupons/create
*/
class CreateCouponRequest extends AbstractRequest
{
/**
* @return int
*/
public function getAmountOff()
{
return $this->getParameter('amount_off');
}
/**
* @param int $value
*
* @return CreateCouponRequest
*/
public function setAmountOff($value)
{
return $this->setParameter('amount_off', $value);
}
/**
* @return int
*/
public function getPercentOff()
{
return $this->getParameter('percent_off');
}
/**
* @param int $value
*
* @return CreateCouponRequest
*/
public function setPercentOff($value)
{
return $this->setParameter('percent_off', $value);
}
/**
* @return int
*/
public function getDurationInMonths()
{
return $this->getParameter('duration_in_months');
}
/**
* @param int $value
*
* @return CreateCouponRequest
*/
public function setDurationInMonths($value)
{
return $this->setParameter('duration_in_months', $value);
}
/**
* @return string
*/
public function getName()
{
return $this->getParameter('name');
}
/**
* @param string $value
*
* @return CreateCouponRequest
*/
public function setName($value)
{
return $this->setParameter('name', $value);
}
/**
* @return int
*/
public function getMaxRedemptions()
{
return $this->getParameter('max_redemptions');
}
/**
* @param int $value
*
* @return CreateCouponRequest
*/
public function setMaxRedemptions($value)
{
return $this->setParameter('duration_in_months', $value);
}
/**
* @return int
*/
public function getRedeemBy()
{
return $this->getParameter('redeem_by');
}
/**
* @param int $value
*
* @return CreateCouponRequest
*/
public function setRedeemBy($value)
{
return $this->setParameter('redeem_by', $value);
}
/**
* @return string
*/
public function getId()
{
return $this->getParameter('id');
}
/**
* @param string $value
*
* @return CreateCouponRequest
*/
public function setId($value)
{
return $this->setParameter('id', $value);
}
/**
* @return string
*/
public function getDuration()
{
return $this->getParameter('duration');
}
/**
* @param string $value
*
* @return CreateCouponRequest
*/
public function setDuration($value)
{
return $this->setParameter('duration', $value);
}
/**
* {@inheritdoc}
*/
public function getData()
{
$this->validate('duration');
$amountOff = $this->getAmountOff();
$percentOff = $this->getPercentOff();
if (!isset($amountOff) && !isset($percentOff)) {
throw new InvalidRequestException("Either amount_off or percent_off is required");
}
$data = [
'id' => $this->getId(),
'duration' => $this->getDuration(),
'amount_off' => $this->getAmountOff(),
'currency' => $this->getCurrency(),
'duration_in_months' => $this->getDurationInMonths(),
'name' => $this->getName(),
'max_redemptions' => $this->getMaxRedemptions(),
'percent_off' => $this->getPercentOff(),
'redeem_by' => $this->getRedeemBy(),
];
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/coupons';
}
public function getHttpMethod()
{
return 'POST';
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* Stripe Create Customer Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Create Customer Request.
*
* Customer objects allow you to perform recurring charges and
* track multiple charges that are associated with the same customer.
* The API allows you to create, delete, and update your customers.
* You can retrieve individual customers as well as a list of all of
* your customers.
*
* ### Examples
*
* #### Create Customer from Email Address
*
* This is the recommended way to create a customer object.
*
* <code>
* $response = $gateway->createCustomer(array(
* 'description' => 'Test Customer',
* 'email' => 'test123@example.com',
* ))->send();
* if ($response->isSuccessful()) {
* echo "Gateway createCustomer was successful.\n";
* // Find the card ID
* $customer_id = $response->getCustomerReference();
* echo "Customer ID = " . $customer_id . "\n";
* } else {
* echo "Gateway createCustomer failed.\n";
* echo "Error message == " . $response->getMessage() . "\n";
* }
* </code>
*
* The $customer_id can now be used in a createCard() call.
*
* #### Create Customer using Card Object
*
* Historically, this library used a card object to create customers.
* Although this is no longer the recommended path, it is still supported.
* Using this approach, a customer object and a card object can be created
* at the same time.
*
* <code>
* // Create a credit card object
* // This card can be used for testing.
* // The CreditCard object is also used for creating customers.
* $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',
* ));
*
* // Do a create customer transaction on the gateway
* $response = $gateway->createCustomer(array(
* 'card' => $card,
* ))->send();
* if ($response->isSuccessful()) {
* echo "Gateway createCustomer was successful.\n";
* // Find the customer ID
* $customer_id = $response->getCustomerReference();
* echo "Customer ID = " . $customer_id . "\n";
* // Find the card ID
* $card_id = $response->getCardReference();
* echo "Card ID = " . $card_id . "\n";
* }
* </code>
*
* @link https://stripe.com/docs/api#customers
*/
class CreateCustomerRequest extends AbstractRequest
{
/**
* Get the customer's email address.
*
* @return string
*/
public function getEmail()
{
return $this->getParameter('email');
}
/**
* Sets the customer's email address.
*
* @param string $value
* @return CreateCustomerRequest provides a fluent interface.
*/
public function setEmail($value)
{
return $this->setParameter('email', $value);
}
public function getName()
{
return $this->getParameter('name');
}
/**
* Sets the customer's name.
*
* @param string $value
* @return CreateCustomerRequest provides a fluent interface.
*/
public function setName($value)
{
return $this->setParameter('name', $value);
}
public function getSource()
{
return $this->getParameter('source');
}
public function setSource($value)
{
$this->setParameter('source', $value);
}
public function getData()
{
$data = array();
$data['description'] = $this->getDescription();
if ($this->getToken()) {
$data['card'] = $this->getToken();
if ($this->getEmail()) {
$data['email'] = $this->getEmail();
}
} elseif ($this->getCard()) {
$data['card'] = $this->getCardData();
$data['email'] = $this->getCard()->getEmail();
} elseif ($this->getEmail()) {
$data['email'] = $this->getEmail();
}
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
if ($this->getSource()) {
$data['source'] = $this->getSource();
}
if ($this->getName()) {
$data['name'] = $this->getName();
}
if ($this->getPaymentMethod()) {
$data['payment_method'] = $this->getPaymentMethod();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/customers';
}
}

View File

@@ -0,0 +1,203 @@
<?php
/**
* Stripe Create Invoice Item Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Create Invoice Item Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#create_invoiceitem
*
* Providing the invoice-item reference will update the invoice-item
* @link https://stripe.com/docs/api#update_invoiceitem
*/
class CreateInvoiceItemRequest extends AbstractRequest
{
/**
* Get the invoice-item reference
*
* @return string
*/
public function getInvoiceItemReference()
{
return $this->getParameter('invoiceItemReference');
}
/**
* Set the invoice-item reference
*
* @return CreateInvoiceItemRequest provides a fluent interface.
*/
public function setInvoiceItemReference($invoiceItemReference)
{
return $this->setParameter('invoiceItemReference', $invoiceItemReference);
}
/**
* Get the invoice-item amount
*
* @return int
*/
public function getAmount()
{
return $this->getParameter('amount');
}
/**
* Set the invoice-item amount
*
* @return CreateInvoiceItemRequest provides a fluent interface.
*/
public function setAmount($value)
{
return $this->setParameter('amount', $value);
}
/**
* Set the invoice-item currency
*
* @return CreateInvoiceItemRequest provides a fluent interface.
*/
public function setCurrency($currency)
{
return $this->setParameter('currency', $currency);
}
/**
* Get the invoice-item currency
*
* @return string
*/
public function getCurrency()
{
return $this->getParameter('currency');
}
/**
* Set the invoice-item description
*
* @return CreateInvoiceItemRequest provides a fluent interface.
*/
public function setDescription($description)
{
return $this->setParameter('description', $description);
}
/**
* Get the invoice-item description
*
* @return string
*/
public function getDescription()
{
return $this->getParameter('description');
}
/**
* Set the invoice-item discountable
*
* @return CreateInvoiceItemRequest provides a fluent interface.
*/
public function setDiscountable($discountable)
{
return $this->setParameter('discountable', $discountable);
}
/**
* Get the invoice-item discountable
*
* @return string
*/
public function getDiscountable()
{
return $this->getParameter('discountable');
}
/**
* Set the invoice-item invoice reference
*
* @return CreateInvoiceItemRequest provides a fluent interface.
*/
public function setInvoiceReference($invoiceReference)
{
return $this->setParameter('invoiceReference', $invoiceReference);
}
/**
* Get the invoice-item invoice reference
*
* @return string
*/
public function getInvoiceReference()
{
return $this->getParameter('invoiceReference');
}
/**
* Set the invoice-item subscription reference
*
* @return CreateInvoiceItemRequest provides a fluent interface.
*/
public function setSubscriptionReference($subscriptionReference)
{
return $this->setParameter('subscriptionReference', $subscriptionReference);
}
/**
* Get the invoice-item subscription reference
*
* @return string
*/
public function getSubscriptionReference()
{
return $this->getParameter('subscriptionReference');
}
public function getData()
{
$data = array();
if ($this->getInvoiceItemReference() == null) {
$this->validate('customerReference', 'amount', 'currency');
}
if ($this->getCustomerReference()) {
$data['customer'] = $this->getCustomerReference();
}
if ($this->getAmount()) {
$data['amount'] = $this->getAmount();
}
if ($this->getCurrency()) {
$data['currency'] = $this->getCurrency();
}
if ($this->getDescription()) {
$data['description'] = $this->getDescription();
}
if ($this->getDiscountable() !== null) {
$data['discountable'] = $this->getDiscountable();
}
if ($this->getInvoiceReference()) {
$data['invoice'] = $this->getInvoiceReference();
}
if ($this->getSubscriptionReference()) {
$data['subscription'] = $this->getSubscriptionReference();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/invoiceitems'
.($this->getInvoiceItemReference() != null ? '/'.$this->getInvoiceItemReference() : '');
}
}

View File

@@ -0,0 +1,450 @@
<?php
/**
* Stripe Create Plan Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Create Plan Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/plans/create
*/
class CreatePlanRequest extends AbstractRequest
{
/**
* Set the plan ID
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setId($value)
{
return $this->setParameter('id', $value);
}
/**
* Get the plan ID
*
* @return string
*/
public function getId()
{
return $this->getParameter('id');
}
/**
* Set the plan interval
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setInterval($value)
{
return $this->setParameter('interval', $value);
}
/**
* Get the plan interval
*
* @return int
*/
public function getInterval()
{
return $this->getParameter('interval');
}
/**
* Set the plan interval count
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setIntervalCount($value)
{
return $this->setParameter('interval_count', $value);
}
/**
* Get the plan interval count
*
* @return int
*/
public function getIntervalCount()
{
return $this->getParameter('interval_count');
}
/**
* Set the plan name
* @deprecated use setNickname() instead
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setName($value)
{
return $this->setNickname($value);
}
/**
* Get the plan name
* @deprecated use getNickname() instead
*
* @return string
*/
public function getName()
{
return $this->getNickname();
}
/**
* Set the plan statement descriptor
* @deprecated Not used anymore
*
* @param $planStatementDescriptor
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setStatementDescriptor($planStatementDescriptor)
{
return $this->setParameter('statement_descriptor', $planStatementDescriptor);
}
/**
* Get the plan statement descriptor
* @deprecated Not used anymore
*
* @return string
*/
public function getStatementDescriptor()
{
return $this->getParameter('statement_descriptor');
}
/**
* Set the plan product
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setProduct($value)
{
return $this->setParameter('product', $value);
}
/**
* Get the plan product
*
* @return string|array
*/
public function getProduct()
{
return $this->getParameter('product');
}
/**
* Set the plan amount
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setAmount($value)
{
return $this->setParameter('amount', (integer)$value);
}
/**
* Get the plan amount
*
* @return int
*/
public function getAmount()
{
return $this->getParameter('amount');
}
/**
* Set the plan tiers
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setTiers($value)
{
return $this->setParameter('tiers', $value);
}
/**
* Get the plan tiers
*
* @return int
*/
public function getTiers()
{
return $this->getParameter('tiers');
}
/**
* Set the plan tiers mode
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setTiersMode($value)
{
return $this->setParameter('tiers_mode', $value);
}
/**
* Get the plan tiers mode
*
* @return int
*/
public function getTiersMode()
{
return $this->getParameter('tiers_mode');
}
/**
* Set the plan nickname
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setNickname($value)
{
return $this->setParameter('nickname', $value);
}
/**
* Get the plan nickname
*
* @return string|array
*/
public function getNickname()
{
return $this->getParameter('nickname');
}
/**
* Set the plan metadata
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setMetadata($value)
{
return $this->setParameter('metadata', $value);
}
/**
* Get the plan metadata
*
* @return string|array
*/
public function getMetadata()
{
return $this->getParameter('metadata');
}
/**
* Set the plan active
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setActive($value)
{
return $this->setParameter('active', $value);
}
/**
* Get the plan active
*
* @return string|array
*/
public function getActive()
{
return $this->getParameter('active');
}
/**
* Set the plan billingScheme
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setBillingScheme($value)
{
return $this->setParameter('billing_scheme', $value);
}
/**
* Get the plan billingScheme
*
* @return string|array
*/
public function getBillingScheme()
{
return $this->getParameter('billing_scheme');
}
/**
* Set the plan aggregate usage
*
* @param $planAggregateUsage
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setAggregateUsage($planAggregateUsage)
{
return $this->setParameter('aggregate_usage', $planAggregateUsage);
}
/**
* Get the plan aggregate usage
*
* @return string
*/
public function getAggregateUsage()
{
return $this->getParameter('aggregate_usage');
}
/**
* Set the plan trial period days
*
* @param $planTrialPeriodDays
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setTrialPeriodDays($planTrialPeriodDays)
{
return $this->setParameter('trial_period_days', $planTrialPeriodDays);
}
/**
* Get the plan trial period days
*
* @return int
*/
public function getTrialPeriodDays()
{
return $this->getParameter('trial_period_days');
}
/**
* Set the plan transform usage
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setTransformUsage($value)
{
return $this->setParameter('transform_usage', $value);
}
/**
* Get the plan transform usage
*
* @return int
*/
public function getTransformUsage()
{
return $this->getParameter('transform_usage');
}
/**
* Set the plan usage type
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
*/
public function setUsageType($value)
{
return $this->setParameter('usage_type', $value);
}
/**
* Get the plan usage type
*
* @return int
*/
public function getUsageType()
{
return $this->getParameter('usage_type');
}
public function getData()
{
$this->validate('currency', 'interval', 'product');
if (null == $this->getBillingScheme() || 'per_unit' == $this->getBillingScheme()) {
$this->validate('amount');
} elseif ('tiered' == $this->getBillingScheme()) {
$this->validate('tiers', 'tiers_mode');
}
$data = array(
'currency' => $this->getCurrency(),
'interval' => $this->getInterval(),
'product' => $this->getProduct()
);
if (null != $this->getBillingScheme()) {
$data['billing_scheme'] = $this->getBillingScheme();
}
if (null != $this->getId()) {
$data['id'] = $this->getId();
}
if (null != $this->getAmount()) {
$data['amount'] = $this->getAmount();
}
if (null != $this->getNickName()) {
$data['nickname'] = $this->getNickName();
}
if (null != $this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
if (null != $this->getActive()) {
$data['active'] = $this->getActive();
}
if (null != $this->getIntervalCount()) {
$data['interval_count'] = $this->getIntervalCount();
}
if (null != $this->getAggregateUsage()) {
$data['aggregate_usage'] = $this->getAggregateUsage();
}
if (null != $this->getTrialPeriodDays()) {
$data['trial_period_days'] = $this->getTrialPeriodDays();
}
if (null != $this->getTransformUsage()) {
$data['transform_usage'] = $this->getTransformUsage();
}
if (null != $this->getUsageType()) {
$data['usage_type'] = $this->getUsageType();
}
if (null != $this->getTiers()) {
$data['tiers'] = $this->getTiers();
}
if (null != $this->getTiersMode()) {
$data['tiers_mode'] = $this->getTiersMode();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/plans';
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* CreateSourceRequest
*/
namespace Omnipay\Stripe\Message;
use Omnipay\Common\Exception\InvalidRequestException;
/**
* Class CreateSourceRequest
*
* @link https://stripe.com/docs/api/sources/create
*/
class CreateSourceRequest extends AbstractRequest
{
/**
* Get the request secure flag. This is a boolean flag to indicate
* whether 3-D secure is required for this source or not
*
* @return mixed
*/
public function getSecure()
{
return $this->getParameter('secure');
}
/**
* Set the request secure flag. This is a boolean flag to indicate
* whether 3-D secure is required for this source or not
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setSecure($value)
{
return $this->setParameter('secure', $value);
}
/**
* Get the secure redirect url where the user will be redirected back after OTP verification
*
* @return string
*/
public function getSecureRedirectUrl()
{
return $this->getParameter('secureRedirectUrl');
}
/**
* Set the secure redirect url where the user will be redirected back after OTP verification
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest]
*/
public function setSecureRedirectUrl($value)
{
return $this->setParameter('secureRedirectUrl', $value);
}
/**
* Get the raw data array for this message. The format of this varies from gateway to
* gateway, but will usually be either an associative array, or a SimpleXMLElement.
*
* @return mixed
* @throws InvalidRequestException
*/
public function getData()
{
$data['amount'] = $this->getAmountInteger();
$data['currency'] = strtolower($this->getCurrency());
if ($this->getSecure()) {
$data['type'] = 'three_d_secure';
$data['three_d_secure']['card'] = $this->getSource();
$data['redirect']['return_url'] = $this->getSecureRedirectUrl();
} elseif ($card = $this->getCard()) {
$data['type'] = 'card';
$data['card']['number'] = $card->getNumber();
$data['card']['exp_month'] = $card->getExpiryMonth();
$data['card']['exp_year'] = $card->getExpiryYear();
if ($card->getCvv()) {
$data['card']['cvc'] = $card->getCvv();
}
$data['owner']['email'] = $card->getEmail();
$data['owner']['name'] = $card->getName();
}
return $data;
}
/**
* @inheritdoc
*
* @return string The endpoint for the create token request.
*/
public function getEndpoint()
{
return $this->endpoint . '/sources';
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* Stripe Create Subscription Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Create Subscription Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/php#create_subscription
*/
class CreateSubscriptionRequest extends AbstractRequest
{
/**
* Get the plan
*
* @return string
*/
public function getPlan()
{
return $this->getParameter('plan');
}
/**
* Set the plan
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreateSubscriptionRequest
*/
public function setPlan($value)
{
return $this->setParameter('plan', $value);
}
/**
* Get the tax percent
*
* @return string
*/
public function getTaxPercent()
{
return $this->getParameter('tax_percent');
}
/**
* Get the the trial end timestamp
*
* @return int
*/
public function getTrialEnd()
{
return $this->getParameter('trial_end');
}
/**
* Set the trial end timestamp.
*
* @param int $value
* @return \Omnipay\Common\Message\AbstractRequest|CreateSubscriptionRequest
*/
public function setTrialEnd($value)
{
return $this->setParameter('trial_end', $value);
}
/**
* Set the tax percentage
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|CreateSubscriptionRequest
*/
public function setTaxPercent($value)
{
return $this->setParameter('tax_percent', $value);
}
public function getData()
{
$this->validate('customerReference', 'plan');
$data = array(
'plan' => $this->getPlan()
);
if ($this->parameters->has('tax_percent')) {
$data['tax_percent'] = (float)$this->getParameter('tax_percent');
}
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
if ($this->getTrialEnd()) {
$data['trial_end'] = $this->getTrialEnd();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/customers/'.$this->getCustomerReference().'/subscriptions';
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Common\Exception\InvalidRequestException;
/**
* Message which creates a new card token, or in a Connect API
* workflow can be used to share clients between the platform and
* the connected accounts.
*
* Creates a single use token that wraps the details of a credit card.
* This token can be used in place of a credit card dictionary with any API method.
* These tokens can only be used once: by creating a new charge object, or attaching them to a customer.
*
* In most cases, you should create tokens client-side using Checkout, Elements, or our mobile libraries,
* instead of using the API.
*
* @link https://stripe.com/docs/api#create_card_token
*/
class CreateTokenRequest extends AbstractRequest
{
/**
* @inheritdoc
*
* @param \Omnipay\Common\CreditCard $value Credit card object
* @return \Omnipay\Common\Message\AbstractRequest $this
*/
public function setCard($value)
{
return parent::setCard($value);
}
/**
* The id of the customer with format cus_<identifier>.
* <strong>Only use this if you are using Connect API</strong>
*
* @param string $customer The id of the customer
* @return \Omnipay\Common\Message\AbstractRequest|\Omnipay\Stripe\Message\CreateTokenRequest
*/
public function setCustomer($customer)
{
return $this->setParameter('customer', $customer);
}
/**
* Get the raw data array for this message. The format of this varies from gateway to
* gateway, but will usually be either an associative array, or a SimpleXMLElement.
* @return mixed
* @throws InvalidRequestException
*/
public function getData()
{
$data = array();
if ($this->getParameter('customer')) {
$data['customer'] = $this->getParameter('customer');
} elseif ($this->getParameter('card')) {
/* @var $card \OmniPay\Common\CreditCard */
$card = $this->getParameter('card');
$card->validate();
$card_data = array(
'exp_month' => $card->getExpiryMonth(),
'exp_year' => $card->getExpiryYear(),
'number' => $card->getNumber(),
);
if ($card->getBillingCity()) {
$card_data['address_city'] = $card->getBillingCity();
}
if ($card->getBillingCountry()) {
$card_data['address_country'] = $card->getBillingCountry();
}
if ($card->getBillingAddress1()) {
$card_data['address_line1'] = $card->getBillingAddress1();
}
if ($card->getBillingAddress2()) {
$card_data['address_line2'] = $card->getBillingAddress2();
}
if ($card->getBillingState()) {
$card_data['address_state'] = $card->getBillingState();
}
if ($card->getBillingPostcode()) {
$card_data['address_zip'] = $card->getBillingPostcode();
}
if ($card->getCvv()) {
$card_data['cvc'] = $card->getCvv();
}
if ($card->getBillingName()) {
$card_data['name'] = $card->getBillingName();
}
$data['card'] = $card_data;
} else {
throw new InvalidRequestException("You must pass either the card or the customer");
}
return $data;
}
/**
* @inheritdoc
*
* @return string The endpoint for the create token request.
*/
public function getEndpoint()
{
return $this->endpoint . '/tokens';
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Stripe Delete Credit Card Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Delete Credit Card Request.
*
* This is normally used to delete a credit card from an existing
* customer.
*
* You can delete cards from a customer or recipient. If you delete a
* card that is currently the default card on a customer or recipient,
* the most recently added card will be used as the new default. If you
* delete the last remaining card on a customer or recipient, the
* default_card attribute on the card's owner will become null.
*
* Note that for cards belonging to customers, you may want to prevent
* customers on paid subscriptions from deleting all cards on file so
* that there is at least one default card for the next invoice payment
* attempt.
*
* In deference to the previous incarnation of this gateway, where
* all CreateCard requests added a new customer and the customer ID
* was used as the card ID, if a cardReference is passed in but no
* customerReference then we assume that the cardReference is in fact
* a customerReference and delete the customer. This might be
* dangerous but it's the best way to ensure backwards compatibility.
*
* @link https://stripe.com/docs/api#delete_card
*/
class DeleteCardRequest extends AbstractRequest
{
public function getData()
{
$this->validate('cardReference');
return;
}
public function getHttpMethod()
{
return 'DELETE';
}
public function getEndpoint()
{
if ($this->getCustomerReference()) {
// Delete a card from a customer
return $this->endpoint.'/customers/'.
$this->getCustomerReference().'/cards/'.
$this->getCardReference();
}
// Delete the customer. Oops?
return $this->endpoint.'/customers/'.$this->getCardReference();
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Omnipay\Stripe\Message;
/**
* Stripe Delete Coupon Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/coupons/delete
*/
class DeleteCouponRequest extends AbstractRequest
{
/**
* Get the source id.
*
* @return string
*/
public function getCouponId()
{
return $this->getParameter('couponId');
}
/**
* Set the coupon id.
*
* @param string $value
*
* @return DeleteCouponRequest provides a fluent interface
*/
public function setCouponId($value)
{
return $this->setParameter('couponId', $value);
}
public function getData()
{
$this->validate('couponId');
}
public function getEndpoint()
{
return $this->endpoint.'/coupons/'.$this->getCouponId();
}
public function getHttpMethod()
{
return 'DELETE';
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Stripe Delete Customer Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Delete Customer Request.
*
* Permanently deletes a customer. It cannot be undone. Also immediately
* cancels any active subscriptions on the customer.
*
* @link https://stripe.com/docs/api#delete_customer
*/
class DeleteCustomerRequest extends AbstractRequest
{
public function getData()
{
$this->validate('customerReference');
return;
}
public function getHttpMethod()
{
return 'DELETE';
}
public function getEndpoint()
{
return $this->endpoint.'/customers/'.$this->getCustomerReference();
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Delete Invoice Item Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Delete Invoice Item Request.
*
* @link https://stripe.com/docs/api#delete_invoiceitem
*/
class DeleteInvoiceItemRequest extends AbstractRequest
{
/**
* Get the invoice-item reference.
*
* @return string
*/
public function getInvoiceItemReference()
{
return $this->getParameter('invoiceItemReference');
}
/**
* Set the set invoice-item reference.
*
* @return DeleteInvoiceItemRequest provides a fluent interface.
*/
public function setInvoiceItemReference($value)
{
return $this->setParameter('invoiceItemReference', $value);
}
public function getData()
{
$this->validate('invoiceItemReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/invoiceitems/'.$this->getInvoiceItemReference();
}
public function getHttpMethod()
{
return 'DELETE';
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Stripe Delete Plan Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Delete Plan Request.
*
* @link https://stripe.com/docs/api#delete_plan
*/
class DeletePlanRequest extends AbstractRequest
{
/**
* Get the plan id.
*
* @return string
*/
public function getId()
{
return $this->getParameter('id');
}
/**
* Set the plan id.
*
* @return DeletePlanRequest provides a fluent interface.
*/
public function setId($planId)
{
return $this->setParameter('id', $planId);
}
public function getData()
{
$this->validate('id');
return;
}
public function getEndpoint()
{
return $this->endpoint.'/plans/'.$this->getId();
}
public function getHttpMethod()
{
return 'DELETE';
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Stripe Detach Source Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Detach Source Request.
*
* Detaches a Source object from a Customer.
* The status of a source is changed to consumed when it is detached and it can no longer be used to create a charge.
*
* @link https://stripe.com/docs/api/sources/detach
*/
class DetachSourceRequest extends AbstractRequest
{
public function getData()
{
$this->validate('customerReference', 'source');
return;
}
public function getEndpoint()
{
return $this->endpoint.'/customers/'.$this->getCustomerReference().'/sources/'.$this->getSource();
}
public function getHttpMethod()
{
return 'DELETE';
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* Stripe Fetch Application Fee Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Application Fee Request.
*
* Example -- note this example assumes that an application fee has been successful.
*
* <code>
* // Fetch the transaction so that details can be found for refund, etc.
* $transaction = $gateway->fetchApplicationFee();
* $transaction->setApplicationFeeReference($application_fee_id);
* $response = $transaction->send();
* $data = $response->getData();
* echo "Gateway fetchApplicationFee response data == " . print_r($data, true) . "\n";
* </code>
*
* @see \Omnipay\Stripe\Gateway
*
* @link https://stripe.com/docs/api#retrieve_application_fee
*/
class FetchApplicationFeeRequest extends AbstractRequest
{
/**
* Get the application fee reference
*
* @return string
*/
public function getApplicationFeeReference()
{
return $this->getParameter('applicationFeeReference');
}
/**
* Set the application fee reference
*
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setApplicationFeeReference($value)
{
return $this->setParameter('applicationFeeReference', $value);
}
public function getData()
{
$this->validate('applicationFeeReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint . '/application_fees/' . $this->getApplicationFeeReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* Stripe Fetch Transaction Request
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Balance Request
*
* Example -- note this example assumes that the purchase has been successful
* and that the transaction balance ID returned from the purchase is held in $balanceTransactionId.
* See PurchaseRequest for the first part of this example transaction:
*
* <code>
* // Fetch the balance to get information about the payment.
* $balance = $gateway->fetchBalanceTransaction();
* $balance->setBalanceTransactionReference($balance_transaction_id);
* $response = $balance->send();
* $data = $response->getData();
* echo "Gateway fetchBalance response data == " . print_r($data, true) . "\n";
* </code>
*
* @see PurchaseRequest
* @see Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#retrieve_balance_transaction
*/
class FetchBalanceTransactionRequest extends AbstractRequest
{
/**
* Get the transaction balance reference
*
* @return string
*/
public function getBalanceTransactionReference()
{
return $this->getParameter('balanceTransactionReference');
}
/**
* Set the transaction balance reference
*
* @return AbstractRequest provides a fluent interface.
*/
public function setBalanceTransactionReference($value)
{
return $this->setParameter('balanceTransactionReference', $value);
}
public function getData()
{
$this->validate('balanceTransactionReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/balance/history/'.$this->getBalanceTransactionReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Fetch Charge Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Charge Request.
*
* @deprecated 2.3.3:3.0.0 functionality provided by \Omnipay\Stripe\Message\FetchTransactionRequest
* @see \Omnipay\Stripe\Message\FetchTransactionRequest
* @link https://stripe.com/docs/api#retrieve_charge
*/
class FetchChargeRequest extends AbstractRequest
{
/**
* Get the charge reference.
*
* @return string
*/
public function getChargeReference()
{
return $this->getParameter('chargeReference');
}
/**
* Set the charge reference.
*
* @param string
* @return FetchChargeRequest provides a fluent interface.
*/
public function setChargeReference($value)
{
return $this->setParameter('chargeReference', $value);
}
public function getData()
{
$this->validate('chargeReference');
}
public function getEndpoint()
{
return $this->endpoint.'/charges/'.$this->getChargeReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Coupon Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/coupons/retrieve
*/
class FetchCouponRequest extends AbstractRequest
{
/**
* Get the coupon id.
*
* @return string
*/
public function getCouponId()
{
return $this->getParameter('couponId');
}
/**
* Set the coupon id.
*
* @param string
* @return FetchCouponRequest provides a fluent interface.
*/
public function setCouponId($value)
{
return $this->setParameter('couponId', $value);
}
public function getData()
{
$this->validate('couponId');
}
public function getEndpoint()
{
return $this->endpoint.'/coupons/'.$this->getCouponId();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Stripe Delete Customer Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Customer Request.
*
*
* @link https://stripe.com/docs/api#retrieve_customer
*/
class FetchCustomerRequest extends AbstractRequest
{
public function getData()
{
$this->validate('customerReference');
return;
}
public function getHttpMethod()
{
return 'GET';
}
public function getEndpoint()
{
return $this->endpoint . '/customers/' . $this->getCustomerReference();
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Fetch Event Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Event Request.
*
* @link https://stripe.com/docs/api/curl#retrieve_event
*/
class FetchEventRequest extends AbstractRequest
{
/**
* Get the event reference.
*
* @return string
*/
public function getEventReference()
{
return $this->getParameter('eventReference');
}
/**
* Set the event reference.
*
* @return FetchEventRequest provides a fluent interface.
*/
public function setEventReference($value)
{
return $this->setParameter('eventReference', $value);
}
public function getData()
{
$this->validate('eventReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/events/'.$this->getEventReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Fetch Invoice Item Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Invoice Item Request.
*
* @link https://stripe.com/docs/api#retrieve_invoiceitem
*/
class FetchInvoiceItemRequest extends AbstractRequest
{
/**
* Get the invoice-item reference.
*
* @return string
*/
public function getInvoiceItemReference()
{
return $this->getParameter('invoiceItemReference');
}
/**
* Set the set invoice-item reference.
*
* @return FetchInvoiceItemRequest provides a fluent interface.
*/
public function setInvoiceItemReference($value)
{
return $this->setParameter('invoiceItemReference', $value);
}
public function getData()
{
$this->validate('invoiceItemReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/invoiceitems/'.$this->getInvoiceItemReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Fetch Invoice Lines Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Invoice Lines Request.
*
* @link https://stripe.com/docs/api#invoice_lines
*/
class FetchInvoiceLinesRequest extends AbstractRequest
{
/**
* Get the invoice reference.
*
* @return string
*/
public function getInvoiceReference()
{
return $this->getParameter('invoiceReference');
}
/**
* Set the set invoice reference.
*
* @return FetchInvoiceLinesRequest provides a fluent interface.
*/
public function setInvoiceReference($value)
{
return $this->setParameter('invoiceReference', $value);
}
public function getData()
{
$this->validate('invoiceReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/invoices/'.$this->getInvoiceReference().'/lines';
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Fetch Invoice Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Invoice Request.
*
* @link https://stripe.com/docs/api#retrieve_invoice
*/
class FetchInvoiceRequest extends AbstractRequest
{
/**
* Get the invoice reference.
*
* @return string
*/
public function getInvoiceReference()
{
return $this->getParameter('invoiceReference');
}
/**
* Set the set invoice reference.
*
* @return FetchInvoiceRequest provides a fluent interface.
*/
public function setInvoiceReference($value)
{
return $this->setParameter('invoiceReference', $value);
}
public function getData()
{
$this->validate('invoiceReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/invoices/'.$this->getInvoiceReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Stripe Fetch Plan Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Plan Request.
*
* @link https://stripe.com/docs/api#retrieve_plan
*/
class FetchPlanRequest extends AbstractRequest
{
/**
* Get the plan id.
*
* @return string
*/
public function getId()
{
return $this->getParameter('id');
}
/**
* Set the plan id.
*
* @return FetchPlanRequest provides a fluent interface.
*/
public function setId($planId)
{
return $this->setParameter('id', $planId);
}
public function getData()
{
$this->validate('id');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/plans/'.$this->getId();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* Stripe Fetch Source Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Source Request.
*
* @link https://stripe.com/docs/api/sources/retrieve
*/
class FetchSourceRequest extends AbstractRequest
{
/**
* @return string|null
*/
public function getClientSecret()
{
return $this->getParameter('clientSecret');
}
/**
* @param string $value
*
* @return FetchSourceRequest
*/
public function setClientSecret($value)
{
return $this->setParameter('clientSecret', $value);
}
public function getData()
{
$this->validate('source');
$data = array();
if ($clientSecret = $this->getClientSecret()) {
$data['client_secret'] = $clientSecret;
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/sources/'.$this->getSource();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* Stripe Fetch Subscription Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Subscription Request.
*
* @link https://stripe.com/docs/api#retrieve_subscription
*/
class FetchSubscriptionRequest extends AbstractRequest
{
/**
* Get the subscription reference.
*
* @return string
*/
public function getSubscriptionReference()
{
return $this->getParameter('subscriptionReference');
}
/**
* Set the subscription reference.
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|FetchSubscriptionRequest
*/
public function setSubscriptionReference($value)
{
return $this->setParameter('subscriptionReference', $value);
}
public function getData()
{
$this->validate('customerReference', 'subscriptionReference');
return array();
}
public function getEndpoint()
{
return $this->endpoint.'/customers/'.$this->getCustomerReference()
.'/subscriptions/'.$this->getSubscriptionReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Stripe Fetch Subscription Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Subscription Request.
*
* @link https://stripe.com/docs/api/subscription_schedules/retrieve
*/
class FetchSubscriptionSchedulesRequest extends AbstractRequest
{
/**
* Get the subscription reference.
*
* @return string
*/
public function getSubscriptionSchedulesReference()
{
return $this->getParameter('subscriptionSchedulesReference');
}
/**
* Set the subscription reference.
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|FetchSubscriptionRequest
*/
public function setSubscriptionSchedulesReference($value)
{
return $this->setParameter('subscriptionSchedulesReference', $value);
}
public function getData()
{
$this->validate('subscriptionSchedulesReference');
return array();
}
public function getEndpoint()
{
return $this->endpoint.'/subscription_schedules/'.$this->getSubscriptionSchedulesReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Stripe Fetch Token Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Token Request.
*
* Often you want to be able to charge credit cards or send payments
* to bank accounts without having to hold sensitive card information
* on your own servers. Stripe.js makes this easy in the browser, but
* you can use the same technique in other environments with our token API.
*
* Tokens can be created with your publishable API key, which can safely
* be embedded in downloadable applications like iPhone and Android apps.
* You can then use a token anywhere in our API that a card or bank account
* is accepted. Note that tokens are not meant to be stored or used more
* than once—to store these details for use later, you should create
* Customer or Recipient objects.
*
* @link https://stripe.com/docs/api#tokens
*/
class FetchTokenRequest extends AbstractRequest
{
public function getData()
{
$this->validate('token');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/tokens/'.$this->getToken();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Stripe Fetch Transaction Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Fetch Transaction Request.
*
* Example -- note this example assumes that the purchase has been successful
* and that the transaction ID returned from the purchase is held in $sale_id.
* See PurchaseRequest for the first part of this example transaction:
*
* <code>
* // 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";
* </code>
*
* @see PurchaseRequest
* @see Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#retrieve_charge
*/
class FetchTransactionRequest extends AbstractRequest
{
public function getData()
{
$this->validate('transactionReference');
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/charges/'.$this->getTransactionReference();
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace Omnipay\Stripe\Message;
/**
* Stripe List Coupons Request.
*
* @see Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/coupons/list
*/
class ListCouponsRequest extends AbstractRequest
{
/**
* @return mixed
*/
public function getCreated()
{
return $this->getParameter('created');
}
/**
* @param string $value
*
* @return ListCouponsRequest
*/
public function setCreated($value)
{
return $this->setParameter('created', $value);
}
/**
* @return mixed
*/
public function getLimit()
{
return $this->getParameter('limit');
}
/**
* @param string $value
*
* @return ListCouponsRequest
*/
public function setLimit($value)
{
return $this->setParameter('limit', $value);
}
/**
* A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list.
* For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your
* subsequent call can include `ending_before=obj_ba`r in order to fetch the previous page of the list.
*
* @return mixed
*/
public function getEndingBefore()
{
return $this->getParameter('endingBefore');
}
/**
* A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list.
* For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your
* subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
*
* @return mixed
*/
public function getStartingAfter()
{
return $this->getParameter('startingAfter');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setStartingAfter($value)
{
return $this->setParameter('startingAfter', $value);
}
/**
* @param string $value
*
* @return ListCouponsRequest
*/
public function setEndingBefore($value)
{
return $this->setParameter('endingBefore', $value);
}
public function getData()
{
$data = array();
if ($this->getLimit()) {
$data['created'] = $this->getCreated();
}
if ($this->getLimit()) {
$data['limit'] = $this->getLimit();
}
if ($this->getEndingBefore()) {
$data['ending_before'] = $this->getEndingBefore();
}
if ($this->getStartingAfter()) {
$data['starting_after'] = $this->getStartingAfter();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/coupons';
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Stripe List Invoices Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe List Invoices Request.
*
* @see Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#list_invoices
*/
class ListInvoicesRequest extends AbstractRequest
{
public function getData()
{
$data = array();
return $data;
}
public function getEndpoint()
{
$endpoint = $this->endpoint.'/invoices';
if ($customerReference = $this->getCustomerReference()) {
return $endpoint . '?customer=' . $customerReference;
}
return $endpoint;
}
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Stripe List Plans Request.
*/
namespace Omnipay\Stripe\Message;
// use Omnipay\Common\Message\AbstractRequest;
/**
* Stripe List Plans Request.
*
* @see Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/curl#list_plans
*/
class ListPlansRequest extends AbstractRequest
{
public function getData()
{
$data = array();
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/plans';
}
public function getHttpMethod()
{
return 'GET';
}
}

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);
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* Stripe Purchase Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Purchase Request.
*
* To charge a credit card, you create a new charge object. If your API key
* is in test mode, the supplied card won't actually be charged, though
* everything else will occur as if in live mode. (Stripe assumes that the
* charge would have completed successfully).
*
* Example:
*
* <code>
* // Create a gateway for the Stripe Gateway
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('Stripe');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'apiKey' => 'MyApiKey',
* ));
*
* // Create 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',
* ));
*
* // Do a purchase transaction on the gateway
* $transaction = $gateway->purchase(array(
* 'amount' => '10.00',
* 'currency' => 'USD',
* 'description' => 'This is a test purchase transaction.',
* 'card' => $card,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Purchase transaction was successful!\n";
* $sale_id = $response->getTransactionReference();
* echo "Transaction reference = " . $sale_id . "\n";
* }
* </code>
*
* Because a purchase request in Stripe looks similar to an
* Authorize request, this class simply extends the AuthorizeRequest
* class and over-rides the getData method setting capture = true.
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#charges
*/
class PurchaseRequest extends AuthorizeRequest
{
public function getData()
{
$data = parent::getData();
$data['capture'] = 'true';
return $data;
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* Stripe Refund Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Refund Request.
*
* When you create a new refund, you must specify a
* charge to create it on.
*
* Creating a new refund will refund a charge that has
* previously been created but not yet refunded. Funds will
* be refunded to the credit or debit card that was originally
* charged. The fees you were originally charged are also
* refunded.
*
* You can optionally refund only part of a charge. You can
* do so as many times as you wish until the entire charge
* has been refunded.
*
* Once entirely refunded, a charge can't be refunded again.
* This method will return an error when called on an
* already-refunded charge, or when trying to refund more
* money than is left on a charge.
*
* Example -- note this example assumes that the purchase has been successful
* and that the transaction ID returned from the purchase is held in $sale_id.
* See PurchaseRequest for the first part of this example transaction:
*
* <code>
* // Do a refund transaction on the gateway
* $transaction = $gateway->refund(array(
* 'amount' => '10.00',
* 'transactionReference' => $sale_id,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Refund transaction was successful!\n";
* $refund_id = $response->getTransactionReference();
* echo "Transaction reference = " . $refund_id . "\n";
* }
* </code>
*
* @see PurchaseRequest
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#create_refund
*/
class RefundRequest extends AbstractRequest
{
/**
* @return bool Whether the application fee should be refunded
*/
public function getRefundApplicationFee()
{
return $this->getParameter('refundApplicationFee');
}
/**
* Whether to refund the application fee associated with a charge.
*
* From the {@link https://stripe.com/docs/api#create_refund Stripe docs}:
* Boolean indicating whether the application fee should be refunded
* when refunding this charge. If a full charge refund is given, the
* full application fee will be refunded. Else, the application fee
* will be refunded with an amount proportional to the amount of the
* charge refunded. An application fee can only be refunded by the
* application that created the charge.
*
* @param bool $value Whether the application fee should be refunded
*
* @return AbstractRequest
*/
public function setRefundApplicationFee($value)
{
return $this->setParameter('refundApplicationFee', $value);
}
/**
* @return bool Whether the transfer should be reversed
*/
public function getReverseTransfer()
{
return $this->getParameter('reverseTransfer');
}
/**
* Whether to refund the application fee associated with a charge.
*
* From the {@link https://stripe.com/docs/connect/destination-charges#issuing-refunds Stripe docs}:
* Charges created on the platform account can be refunded using the
* platform account's secret key. When refunding a charge that has a
* `destination[account]`, by default the destination account keeps the
* funds that were transferred to it, leaving the platform account to
* cover the negative balance from the refund. To pull back the funds
* from the connected account to cover the refund, set the
* `reverse_transfer` parameter to true when creating the refund
*
* @param bool $value Whether the transfer should be refunded
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setReverseTransfer($value)
{
return $this->setParameter('reverseTransfer', $value);
}
public function getData()
{
$this->validate('transactionReference', 'amount');
$data = array();
$data['amount'] = $this->getAmountInteger();
if ($this->getRefundApplicationFee()) {
$data['refund_application_fee'] = 'true';
}
if ($this->getReverseTransfer()) {
$data['reverse_transfer'] = 'true';
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/charges/'.$this->getTransactionReference().'/refund';
}
}

View File

@@ -0,0 +1,596 @@
<?php
/**
* Stripe Response.
*/
namespace Omnipay\Stripe\Message;
use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RedirectResponseInterface;
use Omnipay\Common\Message\RequestInterface;
/**
* Stripe Response.
*
* This is the response class for all Stripe requests.
*
* @see \Omnipay\Stripe\Gateway
*/
class Response extends AbstractResponse implements RedirectResponseInterface
{
/**
* Request id
*
* @var string URL
*/
protected $requestId = null;
/**
* @var array
*/
protected $headers = [];
public function __construct(RequestInterface $request, $data, $headers = [])
{
$this->request = $request;
$this->data = json_decode($data, true);
$this->headers = $headers;
}
/**
* Is the transaction successful?
*
* @return bool
*/
public function isSuccessful()
{
if ($this->isRedirect()) {
return false;
}
return !isset($this->data['error']);
}
/**
* Get the charge reference from the response of FetchChargeRequest.
*
* @deprecated 2.3.3:3.0.0 duplicate of \Omnipay\Stripe\Message\Response::getTransactionReference()
* @see \Omnipay\Stripe\Message\Response::getTransactionReference()
* @return array|null
*/
public function getChargeReference()
{
if (isset($this->data['object']) && 'charge' === $this->data['object']) {
return $this->data['id'];
}
return null;
}
/**
* Get the outcome of a charge from the response
*
* @return array|null
*/
public function getOutcome()
{
if (isset($this->data['object']) && 'charge' === $this->data['object']) {
if (isset($this->data['outcome']) && !empty($this->data['outcome'])) {
return $this->data['outcome'];
}
}
return null;
}
/**
* Get the transaction reference.
*
* @return string|null
*/
public function getTransactionReference()
{
if (isset($this->data['object']) && 'charge' === $this->data['object']) {
return $this->data['id'];
}
if (isset($this->data['error']) && isset($this->data['error']['charge'])) {
return $this->data['error']['charge'];
}
return null;
}
/**
* Get the balance transaction reference.
*
* @return string|null
*/
public function getApplicationFeeReference()
{
if (isset($this->data['object']) && 'application_fee' === $this->data['object']) {
return $this->data['id'];
}
if (isset($this->data['error']) && isset($this->data['error']['application_fee'])) {
return $this->data['error']['application_fee'];
}
return null;
}
/**
* Get the balance transaction reference.
*
* @return string|null
*/
public function getBalanceTransactionReference()
{
if (isset($this->data['object']) && 'charge' === $this->data['object']) {
return $this->data['balance_transaction'];
}
if (isset($this->data['object']) && 'balance_transaction' === $this->data['object']) {
return $this->data['id'];
}
if (isset($this->data['error']) && isset($this->data['error']['charge'])) {
return $this->data['error']['charge'];
}
return null;
}
/**
* Get a customer reference, for createCustomer requests.
*
* @return string|null
*/
public function getCustomerReference()
{
if (isset($this->data['object']) && 'customer' === $this->data['object']) {
return $this->data['id'];
}
if (isset($this->data['object']) && 'card' === $this->data['object']) {
if (!empty($this->data['customer'])) {
return $this->data['customer'];
}
}
if (isset($this->data['object']) && 'charge' === $this->data['object']) {
if (!empty($this->data['customer'])) {
return $this->data['customer'];
}
}
return null;
}
/**
* Get a card reference, for createCard or createCustomer requests.
*
* @return string|null
*/
public function getCardReference()
{
if (isset($this->data['object']) && 'customer' === $this->data['object']) {
if (isset($this->data['default_source']) && !empty($this->data['default_source'])) {
return $this->data['default_source'];
}
if (isset($this->data['default_card']) && !empty($this->data['default_card'])) {
return $this->data['default_card'];
}
if (!empty($this->data['id'])) {
return $this->data['id'];
}
}
if (isset($this->data['object']) && 'card' === $this->data['object']) {
if (!empty($this->data['id'])) {
return $this->data['id'];
}
}
if (isset($this->data['object']) && 'charge' === $this->data['object']) {
if (! empty($this->data['source'])) {
if (!empty($this->data['source']['three_d_secure']['card'])) {
return $this->data['source']['three_d_secure']['card'];
}
if (! empty($this->data['source']['id'])) {
return $this->data['source']['id'];
}
}
}
return null;
}
/**
* Get a token, for createCard requests.
*
* @return string|null
*/
public function getToken()
{
if (isset($this->data['object']) && 'token' === $this->data['object']) {
return $this->data['id'];
}
return null;
}
/**
* Get the card data from the response.
*
* @return array|null
*/
public function getCard()
{
if (isset($this->data['card'])) {
return $this->data['card'];
}
return null;
}
/**
* Get the card data from the response of purchaseRequest.
*
* @return array|null
*/
public function getSource()
{
if (isset($this->data['source']) && $this->data['source']['object'] == 'card') {
return $this->data['source'];
}
if (isset($this->data['object']) && 'source' === $this->data['object']) {
return $this->data;
}
return null;
}
/**
* Get the subscription reference from the response of CreateSubscriptionRequest.
*
* @return array|null
*/
public function getSubscriptionReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'subscription') {
return $this->data['id'];
}
return null;
}
/**
* Get the subscription schedule reference from the response of FetchSubscriptionSchedulesRequest.
*
* @return array|null
*/
public function getSubscriptionSchedulesReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'subscription_schedule') {
return $this->data['id'];
}
return null;
}
/**
* Get the event reference from the response of FetchEventRequest.
*
* @return array|null
*/
public function getEventReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'event') {
return $this->data['id'];
}
return null;
}
/**
* Get the invoice reference from the response of FetchInvoiceRequest.
*
* @return array|null
*/
public function getInvoiceReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'invoice') {
return $this->data['id'];
}
return null;
}
/**
* Get the transfer reference from the response of CreateTransferRequest,
* UpdateTransferRequest, and FetchTransferRequest.
*
* @return array|null
*/
public function getTransferReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'transfer') {
return $this->data['id'];
}
return null;
}
/**
* Get the transfer reference from the response of CreateTransferReversalRequest,
* UpdateTransferReversalRequest, and FetchTransferReversalRequest.
*
* @return array|null
*/
public function getTransferReversalReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'transfer_reversal') {
return $this->data['id'];
}
return null;
}
/**
* Get the list object from a result
*
* @return array|null
*/
public function getList()
{
if (isset($this->data['object']) && $this->data['object'] == 'list') {
return $this->data['data'];
}
return null;
}
/**
* Get the subscription plan from the response of CreateSubscriptionRequest.
*
* @return array|null
*/
public function getPlan()
{
if (isset($this->data['plan'])) {
return $this->data['plan'];
} elseif (array_key_exists('object', $this->data) && $this->data['object'] == 'plan') {
return $this->data;
}
return null;
}
/**
* Get plan id
*
* @return string|null
*/
public function getPlanId()
{
$plan = $this->getPlan();
if ($plan && array_key_exists('id', $plan)) {
return $plan['id'];
}
return null;
}
/**
* Get plan id
*
* @return string|null
*/
public function getSourceId()
{
if (isset($this->data['object']) && 'source' === $this->data['object']) {
return $this->data['id'];
}
return null;
}
/**
* Get invoice-item reference
*
* @return string|null
*/
public function getInvoiceItemReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'invoiceitem') {
return $this->data['id'];
}
return null;
}
/**
* Get the error message from the response.
*
* Returns null if the request was successful.
*
* @return string|null
*/
public function getMessage()
{
if (!$this->isSuccessful() && isset($this->data['error']) && isset($this->data['error']['message'])) {
return $this->data['error']['message'];
}
return null;
}
/**
* Get the error message from the response.
*
* Returns null if the request was successful.
*
* @return string|null
*/
public function getCode()
{
if (!$this->isSuccessful() && isset($this->data['error']) && isset($this->data['error']['code'])) {
return $this->data['error']['code'];
}
return null;
}
/**
* @return string|null
*/
public function getRequestId()
{
if (isset($this->headers['Request-Id'])) {
return $this->headers['Request-Id'][0];
}
return null;
}
/**
* Get the source reference
*
* @return null
*/
public function getSourceReference()
{
if (isset($this->data['object']) && 'source' === $this->data['object']) {
return $this->data['id'];
}
return null;
}
/**
* @return bool
*/
public function isRedirect()
{
if (isset($this->data['object']) && 'source' === $this->data['object']) {
if ($this->cardCan3DS() || ($this->isThreeDSecureSourcePending() && $this->getRedirectUrl() !== null)) {
return true;
}
}
return false;
}
/**
* Check if card requires 3DS
*
* @return bool
*/
protected function cardCan3DS()
{
if (isset($this->data['type']) && 'card' === $this->data['type']) {
if (isset($this->data['card']['three_d_secure']) &&
in_array($this->data['card']['three_d_secure'], ['required', 'optional', 'recommended'], true)
) {
return true;
}
}
return false;
}
/**
* Check if the ThreeDSecure source has status pending
*
* @return bool
*/
protected function isThreeDSecureSourcePending()
{
if (isset($this->data['type']) && 'three_d_secure' === $this->data['type']) {
if (isset($this->data['status']) && 'pending' === $this->data['status']) {
return true;
}
}
return false;
}
/**
* @return mixed
*/
public function getRedirectUrl()
{
if (isset($this->data['object']) && 'source' === $this->data['object'] &&
isset($this->data['type']) && 'three_d_secure' === $this->data['type'] &&
!empty($this->data['redirect']['url'])
) {
return $this->data['redirect']['url'];
}
return null;
}
/**
* @return mixed
*/
public function getRedirectMethod()
{
return 'GET';
}
/**
* @return mixed
*/
public function getRedirectData()
{
return null;
}
/**
* Get the source reference of ThreeDSecure charge
*
* @return null
*/
public function getSessionId()
{
if (isset($this->data['type']) && 'three_d_secure' === $this->data['type']) {
return $this->getSourceReference();
}
return null;
}
/**
* Get the coupon plan from the response of CreateCouponRequest.
*
* @return array|null
*/
public function getCoupon()
{
if (isset($this->data['coupon'])) {
return $this->data['coupon'];
} elseif (array_key_exists('object', $this->data) && $this->data['object'] == 'coupon') {
return $this->data;
}
return null;
}
/**
* Get coupon id
*
* @return string|null
*/
public function getCouponId()
{
$coupon = $this->getCoupon();
if ($coupon && array_key_exists('id', $coupon)) {
return $coupon['id'];
}
return null;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Stripe Abstract Request.
*/
namespace Omnipay\Stripe\Message\SetupIntents;
/**
* 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 setSetupIntentReference($value)
{
return $this->setParameter('setupIntentReference', $value);
}
/**
* @return mixed
*/
public function getSetupIntentReference()
{
return $this->getParameter('setupIntentReference');
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Stripe Create Payment Method Request.
*/
namespace Omnipay\Stripe\Message\SetupIntents;
/**
* Stripe create setup intent
*
* ### Example
*
* <code>
*
* </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/setup_intents/create
*/
class CreateSetupIntentRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$data = [];
if ($this->getCustomerReference()) {
$data['customer'] = $this->getCustomerReference();
}
if ($this->getDescription()) {
$data['description'] = $this->getDescription();
}
if ($this->getMetadata()) {
$this['metadata'] = $this->getMetadata();
}
if ($this->getPaymentMethod()) {
$this['payment_method'] = $this->getPaymentMethod();
}
$data['usage'] = 'off_session';
$data['payment_method_types'][] = 'card';
return $data;
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint . '/setup_intents';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Stripe Payment Intents Response.
*/
namespace Omnipay\Stripe\Message\SetupIntents;
use Omnipay\Common\Message\ResponseInterface;
use Omnipay\Stripe\Message\Response as BaseResponse;
/**
* Stripe Payment Intents Response.
*
* This is the response class for all payment intents related responses.
*
* @see \Omnipay\Stripe\PaymentIntentsGateway
*/
class Response extends BaseResponse implements ResponseInterface
{
/**
* Get the status of a payment intents response.
*
* @return string|null
*/
public function getStatus()
{
if (isset($this->data['object']) && 'setup_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 getClientSecret()
{
if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) {
if (!empty($this->data['client_secret'])) {
return $this->data['client_secret'];
}
}
}
/**
* @inheritdoc
*/
public function getCustomerReference()
{
if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) {
if (!empty($this->data['customer'])) {
return $this->data['customer'];
}
}
return parent::getCustomerReference();
}
/**
* @inheritdoc
*/
public function isSuccessful()
{
if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) {
return in_array($this->getStatus(), ['succeeded', 'requires_payment_method']);
}
return parent::isSuccessful();
}
/**
* @inheritdoc
*/
public function isCancelled()
{
if (isset($this->data['object']) && 'setup_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 getSetupIntentReference()
{
if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) {
return $this->data['id'];
}
return null;
}
/**
* Get the payment intent reference.
*
* @return string|null
*/
public function getPaymentMethod()
{
if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) {
return $this->data['payment_method'];
}
return null;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Stripe Create Payment Method Request.
*/
namespace Omnipay\Stripe\Message\SetupIntents;
/**
* Stripe create setup intent
*
* ### Example
*
* <code>
*
* </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/setup_intents/create
*/
class RetrieveSetupIntentRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$this->validate('setupIntentReference');
return [];
}
/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint . '/setup_intents/' . $this->getSetupIntentReference();
}
public function getHttpMethod()
{
return 'GET';
}
/**
* @inheritdoc
*/
protected function createResponse($data, $headers = [])
{
return $this->response = new Response($this, $data, $headers);
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Stripe Transfer Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Stripe\Message\AuthorizeRequest;
/**
* Stripe Transfer Request.
*
* To send funds from your Stripe account to a connected account, you create
* a new transfer object. Your Stripe balance must be able to cover the
* transfer amount, or you'll receive an "Insufficient Funds" error.
*
* Example -- note this example assumes that the original charge was successful
*
* <code>
* // Create the transfer object when moving funds between Stripe accounts
* $transaction = $gateway->transfer(array(
* 'amount' => '10.00',
* 'currency' => 'AUD',
* 'transferGroup' => '{ORDER10}',
* 'destination' => '{CONNECTED_STRIPE_ACCOUNT_ID}',
* ));
* $response = $transaction->send();
* </code>
*
* @see AuthorizeRequest
* @link https://stripe.com/docs/connect/charges-transfers
*/
class CreateTransferRequest extends AuthorizeRequest
{
/**
* @return mixed
*/
public function getSourceTransaction()
{
return $this->getParameter('sourceTransaction');
}
/**
* When creating separate charges and transfers, your platform can
* inadvertently attempt a transfer without having a sufficient
* available balance. Doing so raises an error and the transfer
* attempt fails. If youre commonly experiencing this problem, you
* can use the `source_transaction` parameter to tie a transfer to an
* existing charge. By using `source_transaction`, the transfer
* request succeeds regardless of your available balance and the
* transfer itself only occurs once the charges funds become available.
*
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setSourceTransaction($value)
{
return $this->setParameter('sourceTransaction', $value);
}
public function getData()
{
$this->validate('amount', 'currency', 'destination');
$data = array(
'amount' => $this->getAmountInteger(),
'currency' => strtolower($this->getCurrency()),
'destination' => $this->getDestination(),
);
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
if ($this->getTransferGroup()) {
$data['transfer_group'] = $this->getTransferGroup();
} elseif ($this->getSourceTransaction()) {
$data['source_transaction'] = $this->getSourceTransaction();
} else {
throw new InvalidRequestException("The sourceTransaction or transferGroup parameter is required");
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/transfers';
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Stripe Reverse Transfer Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Stripe\Message\RefundRequest;
/**
* Stripe Transfer Reversal Request.
*
* When you create a new reversal, you must specify a transfer to create it on.
*
* When reversing transfers, you can optionally reverse part of the transfer.
* You can do so as many times as you wish until the entire transfer has been
* reversed.
*
* Once entirely reversed, a transfer can't be reversed again. This method will
* return an error when called on an already-reversed transfer, or when trying
* to reverse more money than is left on a transfer.
*
* <code>
* // Once the transaction has been authorized, we can capture it for final payment.
* $transaction = $gateway->reverseTransfer(array(
* 'transferReference' => '{TRANSFER_ID}',
* 'description' => 'Had to reverse this transfer because of things'
* ));
* $response = $transaction->send();
* </code>
*
* @link https://stripe.com/docs/api#create_transfer_reversal
*/
class CreateTransferReversalRequest extends RefundRequest
{
/**
* @return mixed
*/
public function getTransferReference()
{
return $this->getParameter('transferReference');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setTransferReference($value)
{
return $this->setParameter('transferReference', $value);
}
/**
* {@inheritdoc}
*/
public function getData()
{
$this->validate('transferReference');
$data = array();
// If no amount is passed, then the entire transfer is reversed
if ($this->getAmountInteger()) {
$data['amount'] = $this->getAmountInteger();
}
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
if ($this->getDescription()) {
$data['description'] = $this->getDescription();
}
if ($this->getRefundApplicationFee()) {
$data['refund_application_fee'] = 'true';
}
return $data;
}
/**
* {@inheritdoc}
*/
public function getEndpoint()
{
return $this->endpoint.'/transfers/'.$this->getTransferReference().'/reversals';
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Stripe Fetch Transfer Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Stripe\Message\AbstractRequest;
/**
* Stripe Fetch Transfer Request.
*
* <code>
* // Once the transaction has been authorized, we can capture it for final payment.
* $transaction = $gateway->fetchTransfer([
* 'transferReference' => '{TRANSFER_ID}',
* ]);
* $response = $transaction->send();
* </code>
*
* @link https://stripe.com/docs/api#retrieve_transfer
*/
class FetchTransferRequest extends AbstractRequest
{
/**
* @return mixed
*/
public function getTransferReference()
{
return $this->getParameter('transferReference');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setTransferReference($value)
{
return $this->setParameter('transferReference', $value);
}
/**
* {@inheritdoc}
*/
public function getData()
{
$this->validate('transferReference');
}
/**
* {@inheritdoc}
*/
public function getEndpoint()
{
return $this->endpoint.'/transfers/'.$this->getTransferReference();
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Stripe Fetch Transfer Reversal Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Stripe\Message\AbstractRequest;
/**
* Stripe Fetch Transfer Reversal Request.
*
* <code>
* // Once the transaction has been authorized, we can capture it for final payment.
* $transaction = $gateway->fetchTransferReversal([
* 'transferReference' => '{TRANSFER_ID}',
* 'reversalReference' => '{REVERSAL_ID}',
* ]);
* $response = $transaction->send();
* </code>
*
*
* @link https://stripe.com/docs/api#retrieve_transfer_reversal
*/
class FetchTransferReversalRequest extends AbstractRequest
{
/**
* @return mixed
*/
public function getReversalReference()
{
return $this->getParameter('reversalReference');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setReversalReference($value)
{
return $this->setParameter('reversalReference', $value);
}
/**
* @return mixed
*/
public function getTransferReference()
{
return $this->getParameter('transferReference');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setTransferReference($value)
{
return $this->setParameter('transferReference', $value);
}
public function getData()
{
$this->validate('reversalReference', 'transferReference');
}
public function getEndpoint()
{
return $this->endpoint.'/transfers/'.$this->getTransferReference().'/reversals/'.$this->getReversalReference();
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* Stripe List Transfer Reversals Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Stripe\Message\AbstractRequest;
/**
* Stripe List Transfer Reversals Request.
*
* You can see a list of the reversals belonging to a specific transfer.
*
* Note that the 10 most recent reversals are always available by default
* on the transfer object. If you need more than those 10, you can use
* this API method and the `limit` and `starting_after` parameters to
* page through additional reversals.
*
* @link https://stripe.com/docs/api#list_transfer_reversals
*/
class ListTransferReversalsRequest extends AbstractRequest
{
/**
* @return mixed
*/
public function getTransferReference()
{
return $this->getParameter('transferReference');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setTransferReference($value)
{
return $this->setParameter('transferReference', $value);
}
/**
* @return mixed
*/
public function getLimit()
{
return $this->getParameter('limit');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setLimit($value)
{
return $this->setParameter('limit', $value);
}
/**
* A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list.
* For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your
* subsequent call can include `ending_before=obj_ba`r in order to fetch the previous page of the list.
*
* @return mixed
*/
public function getEndingBefore()
{
return $this->getParameter('endingBefore');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setEndingBefore($value)
{
return $this->setParameter('endingBefore', $value);
}
/**
* A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list.
* For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your
* subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
*
* @return mixed
*/
public function getStartingAfter()
{
return $this->getParameter('startingAfter');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setStartingAfter($value)
{
return $this->setParameter('startingAfter', $value);
}
/**
* {@inheritdoc}
*/
public function getData()
{
$this->validate('transferReference');
$data = array();
if ($this->getLimit()) {
$data['limit'] = $this->getLimit();
}
if ($this->getEndingBefore()) {
$data['ending_before'] = $this->getEndingBefore();
}
if ($this->getStartingAfter()) {
$data['starting_after'] = $this->getStartingAfter();
}
return $data;
}
/**
* {@inheritdoc}
*/
public function getEndpoint()
{
return $this->endpoint.'/transfers/'.$this->getTransferReference().'/reversals';
}
/**
* {@inheritdoc}
*/
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,167 @@
<?php
/**
* Stripe List Transfers Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Stripe\Message\AbstractRequest;
/**
* Stripe List Transfers Request.
*
* Returns a list of existing transfers sent to connected accounts. The
* transfers are returned in sorted order, with the most recently created
* transfers appearing first.
*
* @link https://stripe.com/docs/api#list_transfers
*/
class ListTransfersRequest extends AbstractRequest
{
/**
* @return mixed
*/
public function getLimit()
{
return $this->getParameter('limit');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setLimit($value)
{
return $this->setParameter('limit', $value);
}
/**
* @return mixed
*/
public function getDestination()
{
return $this->getParameter('destination');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setDestination($value)
{
return $this->setParameter('destination', $value);
}
/**
* Connect only
*
* @return mixed
*/
public function getTransferGroup()
{
return $this->getParameter('transferGroup');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setTransferGroup($value)
{
return $this->setParameter('transferGroup', $value);
}
/**
* A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list.
* For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your
* subsequent call can include `ending_before=obj_ba`r in order to fetch the previous page of the list.
*
* @return mixed
*/
public function getEndingBefore()
{
return $this->getParameter('endingBefore');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setEndingBefore($value)
{
return $this->setParameter('endingBefore', $value);
}
/**
* A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list.
* For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your
* subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
*
* @return mixed
*/
public function getStartingAfter()
{
return $this->getParameter('startingAfter');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setStartingAfter($value)
{
return $this->setParameter('startingAfter', $value);
}
/**
* {@inheritdoc}
*/
public function getData()
{
$data = array();
if ($this->getLimit()) {
$data['limit'] = $this->getLimit();
}
if ($this->getDestination()) {
$data['destination'] = $this->getDestination();
}
if ($this->getTransferGroup()) {
$data['transfer_group'] = $this->getTransferGroup();
}
if ($this->getEndingBefore()) {
$data['ending_before'] = $this->getEndingBefore();
}
if ($this->getStartingAfter()) {
$data['starting_after'] = $this->getStartingAfter();
}
return $data;
}
/**
* {@inheritdoc}
*/
public function getEndpoint()
{
return $this->endpoint.'/transfers';
}
/**
* {@inheritdoc}
*/
public function getHttpMethod()
{
return 'GET';
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Stripe Update Transfer Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Stripe\Message\AbstractRequest;
/**
* Stripe Update Transfer Request.
*
* Updates the specified transfer by setting the values of the parameters passed.
* Any parameters not provided will be left unchanged.
*
* <code>
* // Once the transaction has been authorized, we can capture it for final payment.
* $transaction = $gateway->updateTransfer(array(
* 'transferReference' => '{TRANSFER_ID}',
* 'metadata' => [],
* ));
* $response = $transaction->send();
* </code>
*
* @link https://stripe.com/docs/api#update_transfer
*/
class UpdateTransferRequest extends AbstractRequest
{
/**
* Get the plan ID
*
* @return string
*/
public function getTransferReference()
{
return $this->getParameter('transferReference');
}
/**
* Set the plan ID
*
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setTransferReference($value)
{
return $this->setParameter('transferReference', $value);
}
/**
* @return array
*/
public function getData()
{
$this->validate('transferReference');
$data = array();
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
return $data;
}
/**
* @return string
*/
public function getEndpoint()
{
return $this->endpoint.'/transfers/'.$this->getTransferReference();
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* Stripe Update Transfer Reversal Request (Connect only).
*/
namespace Omnipay\Stripe\Message\Transfers;
use Omnipay\Stripe\Message\AbstractRequest;
/**
* Stripe Update Transfer Reversal Request.
*
* Updates the specified reversal by setting the values of the parameters passed.
* Any parameters not provided will be left unchanged.
*
* This request only accepts metadata and description as arguments.
*
* <code>
* // Once the transaction has been authorized, we can capture it for final payment.
* $transaction = $gateway->updateTransfer(array(
* 'transferReference' => '{TRANSFER_ID}',
* 'reversalReference' => '{REVERSAL_ID}',
* 'metadata' => [],
* ));
* $response = $transaction->send();
* </code>
*
* @link https://stripe.com/docs/api#update_transfer_reversal
*/
class UpdateTransferReversalRequest extends AbstractRequest
{
/**
* @return mixed
*/
public function getReversalReference()
{
return $this->getParameter('reversalReference');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setReversalReference($value)
{
return $this->setParameter('reversalReference', $value);
}
/**
* @return mixed
*/
public function getTransferReference()
{
return $this->getParameter('transferReference');
}
/**
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setTransferReference($value)
{
return $this->setParameter('transferReference', $value);
}
/**
* @return array
*/
public function getData()
{
$this->validate('reversalReference', 'transferReference');
$data = array();
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
if ($this->getDescription()) {
$data['description'] = $this->getDescription();
}
return $data;
}
/**
* @return string
*/
public function getEndpoint()
{
return $this->endpoint.'/transfers/'.$this->getTransferReference().'/reversals/'.$this->getReversalReference();
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Stripe Update Credit Card Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Update Credit Card Request.
*
* If you need to update only some card details, like the billing
* address or expiration date, you can do so without having to re-enter
* the full card details. Stripe also works directly with card networks
* so that your customers can continue using your service without
* interruption.
*
* When you update a card, Stripe will automatically validate the card.
*
* This requires both a customerReference and a cardReference.
*
* @link https://stripe.com/docs/api#update_card
*/
class UpdateCardRequest extends AbstractRequest
{
public function getData()
{
$this->validate('cardReference');
$this->validate('customerReference');
if ($this->getCard()) {
return $this->getCardData();
} else {
return array();
}
}
public function getEndpoint()
{
return $this->endpoint.'/customers/'.$this->getCustomerReference().
'/cards/'.$this->getCardReference();
}
/**
* 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();
}
if ($card->getName()) {
$data['name'] = $card->getName();
}
if ($card->getNumber()) {
$data['number'] = $card->getNumber();
}
if ($card->getAddress1()) {
$data['address_line1'] = $card->getAddress1();
}
if ($card->getAddress2()) {
$data['address_line2'] = $card->getAddress2();
}
if ($card->getCity()) {
$data['address_city'] = $card->getCity();
}
if ($card->getPostcode()) {
$data['address_zip'] = $card->getPostcode();
}
if ($card->getState()) {
$data['address_state'] = $card->getState();
}
if ($card->getCountry()) {
$data['address_country'] = $card->getCountry();
}
}
return $data;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Omnipay\Stripe\Message;
/**
* Stripe Update Coupon Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api/coupons/update
*/
class UpdateCouponRequest extends AbstractRequest
{
/**
* Get the coupon
*
* @return string
*/
public function getCouponId()
{
return $this->getParameter('couponId');
}
/**
* Set the coupon
*
* @param $value
* @return UpdateCouponRequest
*/
public function setCouponId($value)
{
return $this->setParameter('couponId', $value);
}
/**
* @return string
*/
public function getName()
{
return $this->getParameter('name');
}
/**
* @param string $value
*
* @return UpdateCouponRequest
*/
public function setName($value)
{
return $this->setParameter('name', $value);
}
public function getData()
{
$data = array();
if (null !== $this->getName()) {
$data['name'] = $this->getName();
}
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/coupons/'.$this->getCouponId();
}
public function getHttpMethod()
{
return 'POST';
}
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* Stripe Update Customer Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Update Customer Request.
*
* Customer objects allow you to perform recurring charges and
* track multiple charges that are associated with the same customer.
* The API allows you to create, delete, and update your customers.
* You can retrieve individual customers as well as a list of all of
* your customers.
*
* This request updates the specified customer by setting the values
* of the parameters passed. Any parameters not provided will be left
* unchanged. For example, if you pass the card parameter, that becomes
* the customer's active card to be used for all charges in the future,
* and the customer email address is updated to the email address
* on the card. When you update a customer to a new valid card: for
* each of the customer's current subscriptions, if the subscription
* is in the `past_due` state, then the latest unpaid, unclosed
* invoice for the subscription will be retried (note that this retry
* will not count as an automatic retry, and will not affect the next
* regularly scheduled payment for the invoice). (Note also that no
* invoices pertaining to subscriptions in the `unpaid` state, or
* invoices pertaining to canceled subscriptions, will be retried as
* a result of updating the customer's card.)
*
* This request accepts mostly the same arguments as the customer
* creation call.
*
* @link https://stripe.com/docs/api#update_customer
*/
class UpdateCustomerRequest extends AbstractRequest
{
/**
* Get the customer's email address.
*
* @return string
*/
public function getEmail()
{
return $this->getParameter('email');
}
/**
* Sets the customer's email address.
*
* @param string $value
* @return CreateCustomerRequest provides a fluent interface.
*/
public function setEmail($value)
{
return $this->setParameter('email', $value);
}
/**
* Get the customer's source.
*
* @return string
*/
public function getSource()
{
return $this->getParameter('source');
}
/**
* Sets the customer's source.
*
* @param string $value
* @return CreateCustomerRequest provides a fluent interface.
*/
public function setSource($value)
{
$this->setParameter('source', $value);
}
public function getData()
{
$this->validate('customerReference');
$data = array();
$data['description'] = $this->getDescription();
if ($this->getToken()) {
$data['card'] = $this->getToken();
} elseif ($this->getCard()) {
$this->getCard()->validate();
$data['card'] = $this->getCardData();
$data['email'] = $this->getCard()->getEmail();
} elseif ($this->getEmail()) {
$data['email'] = $this->getEmail();
}
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
if ($this->getSource()) {
$data['source'] = $this->getSource();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/customers/'.$this->getCustomerReference();
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* Stripe Update Subscription Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Update Subscription Request
*
* @see \Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#update_subscription
*/
class UpdateSubscriptionRequest extends AbstractRequest
{
/**
* Get the plan
*
* @return string
*/
public function getPlan()
{
return $this->getParameter('plan');
}
/**
* Set the plan
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|UpdateSubscriptionRequest
*/
public function setPlan($value)
{
return $this->setParameter('plan', $value);
}
/**
* @deprecated
*/
public function getPlanId()
{
return $this->getPlan();
}
/**
* @deprecated
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|UpdateSubscriptionRequest
*/
public function setPlanId($value)
{
return $this->setPlan($value);
}
/**
* Get the subscription reference
*
* @return string
*/
public function getSubscriptionReference()
{
return $this->getParameter('subscriptionReference');
}
/**
* Set the subscription reference
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|UpdateSubscriptionRequest
*/
public function setSubscriptionReference($value)
{
return $this->setParameter('subscriptionReference', $value);
}
public function getData()
{
$this->validate('customerReference', 'subscriptionReference', 'plan');
$data = array(
'plan' => $this->getPlan()
);
if ($this->parameters->has('tax_percent')) {
$data['tax_percent'] = (float)$this->getParameter('tax_percent');
}
if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}
return $data;
}
public function getEndpoint()
{
return $this->endpoint.'/customers/'.$this->getCustomerReference()
.'/subscriptions/'.$this->getSubscriptionReference();
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Stripe Void Request.
*/
namespace Omnipay\Stripe\Message;
/**
* Stripe Void Request.
*
* Stripe does not support voiding, per se, but
* we treat it as a full refund.
*
* See RefundRequest for additional information
*
* Example -- note this example assumes that the purchase has been successful
* and that the transaction ID returned from the purchase is held in $sale_id.
* See PurchaseRequest for the first part of this example transaction:
*
* <code>
* // Do a void transaction on the gateway
* $transaction = $gateway->void(array(
* 'transactionReference' => $sale_id,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Void transaction was successful!\n";
* $void_id = $response->getTransactionReference();
* echo "Transaction reference = " . $void_id . "\n";
* }
* </code>
*
* @see RefundRequest
* @see Omnipay\Stripe\Gateway
* @link https://stripe.com/docs/api#create_refund
*/
class VoidRequest extends RefundRequest
{
public function getData()
{
$this->validate('transactionReference');
$data = array();
if ($this->getRefundApplicationFee()) {
$data['refund_application_fee'] = 'true';
}
return $data;
}
}

View File

@@ -0,0 +1,190 @@
<?php
/**
* Stripe Payment Intents Gateway.
*/
namespace Omnipay\Stripe;
/**
* Stripe Payment Intents Gateway.
*
* @see \Omnipay\Stripe\AbstractGateway
* @see \Omnipay\Stripe\Message\AbstractRequest
*
* @link https://stripe.com/docs/api
*
*/
class PaymentIntentsGateway extends AbstractGateway
{
/**
* @inheritdoc
*/
public function getName()
{
return 'Stripe Payment Intents';
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PaymentIntents\AuthorizeRequest
*/
public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\AuthorizeRequest', $parameters);
}
/**
* @inheritdoc
*
* In reality, we're confirming the payment intent.
* This method exists as an alias to in line with how Omnipay interfaces define things.
*
* @return \Omnipay\Stripe\Message\PaymentIntents\ConfirmPaymentIntentRequest
*/
public function completeAuthorize(array $options = [])
{
return $this->confirm($options);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PaymentIntents\CaptureRequest
*/
public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\CaptureRequest', $parameters);
}
/**
* Confirm a Payment Intent. Use this to confirm a payment intent created by a Purchase or Authorize request.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\PaymentIntents\ConfirmPaymentIntentRequest
*/
public function confirm(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\ConfirmPaymentIntentRequest', $parameters);
}
/**
* Cancel a Payment Intent.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\PaymentIntents\CancelPaymentIntentRequest
*/
public function cancel(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\CancelPaymentIntentRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PaymentIntents\PurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\PurchaseRequest', $parameters);
}
/**
* @inheritdoc
*
* In reality, we're confirming the payment intent.
* This method exists as an alias to in line with how Omnipay interfaces define things.
*
* @return \Omnipay\Stripe\Message\PaymentIntents\ConfirmPaymentIntentRequest
*/
public function completePurchase(array $options = [])
{
return $this->confirm($options);
}
/**
* Fetch a payment intent. Use this to check the status of it.
*
* @return \Omnipay\Stripe\Message\PaymentIntents\FetchPaymentIntentRequest
*/
public function fetchPaymentIntent(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\FetchPaymentIntentRequest', $parameters);
}
//
// Cards
// @link https://stripe.com/docs/api/payment_methods
//
/**
* @return \Omnipay\Stripe\Message\PaymentIntents\FetchPaymentMethodRequest
*/
public function fetchCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\FetchPaymentMethodRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest
*/
public function createCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PaymentIntents\CreatePaymentMethodRequest
*/
public function attachCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\AttachPaymentMethodRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PaymentIntents\UpdatePaymentMethodRequest
*/
public function updateCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\UpdatePaymentMethodRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\PaymentIntents\DetachPaymentMethodRequest
*/
public function deleteCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\DetachPaymentMethodRequest', $parameters);
}
// Setup Intent
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\SetupIntents\CreateSetupIntentRequest
*/
public function createSetupIntent(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\SetupIntents\CreateSetupIntentRequest', $parameters);
}
/**
* @inheritdoc
*
* @return \Omnipay\Stripe\Message\SetupIntents\CreateSetupIntentRequest
*/
public function retrieveSetupIntent(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\SetupIntents\RetrieveSetupIntentRequest', $parameters);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Stripe Item
*/
namespace Omnipay\Stripe;
use Omnipay\Common\Item;
/**
* Class StripeItem
*
* @package Omnipay\Stripe
*/
class StripeItem extends Item
{
public function getTaxes()
{
return $this->getParameter('taxes');
}
public function setTaxes($value)
{
$this->setParameter('taxes', $value);
}
public function getDiscount()
{
return $this->getParameter('discount');
}
public function setDiscount($value)
{
$this->setParameter('discount', $value);
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Stripe Item bag
*/
namespace Omnipay\Stripe;
use Omnipay\Common\ItemBag;
use Omnipay\Common\ItemInterface;
/**
* Class StripeItemBag
*
* @package Omnipay\Stripe
*/
class StripeItemBag extends ItemBag
{
/**
* Add an item to the bag
*
* @see Item
*
* @param ItemInterface|array $item An existing item, or associative array of item parameters
*/
public function add($item)
{
if ($item instanceof ItemInterface) {
$this->items[] = $item;
} else {
$this->items[] = new StripeItem($item);
}
}
}

View File

@@ -0,0 +1,268 @@
<?php
namespace Omnipay\Stripe;
use Omnipay\Tests\GatewayTestCase;
/**
* @property Gateway gateway
*/
class ChargeGatewayTest extends GatewayTestCase
{
public function setUp()
{
parent::setUp();
$this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest());
}
public function testAuthorize()
{
$request = $this->gateway->authorize(array('amount' => '10.00'));
$this->assertInstanceOf('Omnipay\Stripe\Message\AuthorizeRequest', $request);
$this->assertSame('10.00', $request->getAmount());
}
public function testCapture()
{
$request = $this->gateway->capture(array('amount' => '10.00'));
$this->assertInstanceOf('Omnipay\Stripe\Message\CaptureRequest', $request);
$this->assertSame('10.00', $request->getAmount());
}
public function testPurchase()
{
$request = $this->gateway->purchase(array('amount' => '10.00'));
$this->assertInstanceOf('Omnipay\Stripe\Message\PurchaseRequest', $request);
$this->assertSame('10.00', $request->getAmount());
}
public function testRefund()
{
$request = $this->gateway->refund(array('amount' => '10.00'));
$this->assertInstanceOf('Omnipay\Stripe\Message\RefundRequest', $request);
$this->assertSame('10.00', $request->getAmount());
}
public function testVoid()
{
$request = $this->gateway->void();
$this->assertInstanceOf('Omnipay\Stripe\Message\VoidRequest', $request);
}
public function testFetchTransaction()
{
$request = $this->gateway->fetchTransaction(array());
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchTransactionRequest', $request);
}
public function testFetchBalanceTransaction()
{
$request = $this->gateway->fetchBalanceTransaction(array());
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchBalanceTransactionRequest', $request);
}
public function testFetchToken()
{
$request = $this->gateway->fetchToken(array());
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchTokenRequest', $request);
}
public function testCreateToken()
{
$request = $this->gateway->createToken(array('customer' => 'cus_foo'));
$this->assertInstanceOf('Omnipay\Stripe\Message\CreateTokenRequest', $request);
$params = $request->getParameters();
$this->assertSame('cus_foo', $params['customer']);
}
public function testCreateCard()
{
$request = $this->gateway->createCard(array('description' => 'foo'));
$this->assertInstanceOf('Omnipay\Stripe\Message\CreateCardRequest', $request);
$this->assertSame('foo', $request->getDescription());
}
public function testUpdateCard()
{
$request = $this->gateway->updateCard(array('cardReference' => 'cus_1MZSEtqSghKx99'));
$this->assertInstanceOf('Omnipay\Stripe\Message\UpdateCardRequest', $request);
$this->assertSame('cus_1MZSEtqSghKx99', $request->getCardReference());
}
public function testDeleteCard()
{
$request = $this->gateway->deleteCard(array('cardReference' => 'cus_1MZSEtqSghKx99'));
$this->assertInstanceOf('Omnipay\Stripe\Message\DeleteCardRequest', $request);
$this->assertSame('cus_1MZSEtqSghKx99', $request->getCardReference());
}
public function testCreateCustomer()
{
$request = $this->gateway->createCustomer(array('description' => 'foo@foo.com'));
$this->assertInstanceOf('Omnipay\Stripe\Message\CreateCustomerRequest', $request);
$this->assertSame('foo@foo.com', $request->getDescription());
}
public function testFetchCustomer()
{
$request = $this->gateway->fetchCustomer(array('customerReference' => 'cus_1MZSEtqSghKx99'));
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchCustomerRequest', $request);
$this->assertSame('cus_1MZSEtqSghKx99', $request->getCustomerReference());
}
public function testUpdateCustomer()
{
$request = $this->gateway->updateCustomer(array('customerReference' => 'cus_1MZSEtqSghKx99'));
$this->assertInstanceOf('Omnipay\Stripe\Message\UpdateCustomerRequest', $request);
$this->assertSame('cus_1MZSEtqSghKx99', $request->getCustomerReference());
}
public function testDeleteCustomer()
{
$request = $this->gateway->deleteCustomer(array('customerReference' => 'cus_1MZSEtqSghKx99'));
$this->assertInstanceOf('Omnipay\Stripe\Message\DeleteCustomerRequest', $request);
$this->assertSame('cus_1MZSEtqSghKx99', $request->getCustomerReference());
}
public function testCreatePlan()
{
$request = $this->gateway->createPlan(array('id' => 'basic'));
$this->assertInstanceOf('Omnipay\Stripe\Message\CreatePlanRequest', $request);
$this->assertSame('basic', $request->getId());
}
public function testFetchPlan()
{
$request = $this->gateway->fetchPlan(array('id' => 'basic'));
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchPlanRequest', $request);
$this->assertSame('basic', $request->getId());
}
public function testDeletePlan()
{
$request = $this->gateway->deletePlan(array('id' => 'basic'));
$this->assertInstanceOf('Omnipay\Stripe\Message\DeletePlanRequest', $request);
$this->assertSame('basic', $request->getId());
}
public function testListPlans()
{
$request = $this->gateway->listPlans(array());
$this->assertInstanceOf('Omnipay\Stripe\Message\ListPlansRequest', $request);
}
public function testCreateSubscription()
{
$request = $this->gateway->createSubscription(array('plan' => 'basic'));
$this->assertInstanceOf('Omnipay\Stripe\Message\CreateSubscriptionRequest', $request);
$this->assertSame('basic', $request->getPlan());
}
public function testFetchSubscription()
{
$request = $this->gateway->fetchSubscription(array(
'customerReference' => 'cus_1MZSEtqZghix99',
'subscriptionReference' => 'sub_1mokfidgjdidf'
));
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchSubscriptionRequest', $request);
$this->assertSame('cus_1MZSEtqZghix99', $request->getCustomerReference());
$this->assertSame('sub_1mokfidgjdidf', $request->getSubscriptionReference());
}
public function testUpdateSubscription()
{
$request = $this->gateway->updateSubscription(array('subscriptionReference' => 'sub_1mokfidgjdidf'));
$this->assertInstanceOf('Omnipay\Stripe\Message\UpdateSubscriptionRequest', $request);
$this->assertSame('sub_1mokfidgjdidf', $request->getSubscriptionReference());
}
public function testCancelSubscription()
{
$request = $this->gateway->cancelSubscription(array(
'customerReference' => 'cus_1MZSEtqZghix99',
'subscriptionReference' => 'sub_1mokfidgjdidf'
));
$this->assertInstanceOf('Omnipay\Stripe\Message\CancelSubscriptionRequest', $request);
$this->assertSame('cus_1MZSEtqZghix99', $request->getCustomerReference());
$this->assertSame('sub_1mokfidgjdidf', $request->getSubscriptionReference());
}
public function testFetchEvent()
{
$request = $this->gateway->fetchEvent(array('eventReference' => 'evt_17X23UCryC4r2g4vdolh6muI'));
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchEventRequest', $request);
$this->assertSame('evt_17X23UCryC4r2g4vdolh6muI', $request->getEventReference());
}
public function testFetchInvoiceLines()
{
$request = $this->gateway->fetchInvoiceLines(array('invoiceReference' => 'in_17ZPbRCryC4r2g4vIdAFxptK'));
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchInvoiceLinesRequest', $request);
$this->assertSame('in_17ZPbRCryC4r2g4vIdAFxptK', $request->getInvoiceReference());
}
public function testFetchInvoice()
{
$request = $this->gateway->fetchInvoice(array('invoiceReference' => 'in_17ZPbRCryC4r2g4vIdAFxptK'));
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchInvoiceRequest', $request);
$this->assertSame('in_17ZPbRCryC4r2g4vIdAFxptK', $request->getInvoiceReference());
}
public function testListInvoices()
{
$request = $this->gateway->listInvoices(array());
$this->assertInstanceOf('Omnipay\Stripe\Message\ListInvoicesRequest', $request);
}
public function testCreateInvoiceItem()
{
$request = $this->gateway->createInvoiceItem(array('invoiceItemReference' => 'ii_17ZPbRCryC4r2g4vIdAFxptK'));
$this->assertInstanceOf('Omnipay\Stripe\Message\CreateInvoiceItemRequest', $request);
$this->assertSame('ii_17ZPbRCryC4r2g4vIdAFxptK', $request->getInvoiceItemReference());
}
public function testFetchInvoiceItem()
{
$request = $this->gateway->fetchInvoiceItem(array('invoiceItemReference' => 'ii_17ZPbRCryC4r2g4vIdAFxptK'));
$this->assertInstanceOf('Omnipay\Stripe\Message\FetchInvoiceItemRequest', $request);
$this->assertSame('ii_17ZPbRCryC4r2g4vIdAFxptK', $request->getInvoiceItemReference());
}
public function testDeleteInvoiceItem()
{
$request = $this->gateway->deleteInvoiceItem(array('invoiceItemReference' => 'ii_17ZPbRCryC4r2g4vIdAFxptK'));
$this->assertInstanceOf('Omnipay\Stripe\Message\DeleteInvoiceItemRequest', $request);
$this->assertSame('ii_17ZPbRCryC4r2g4vIdAFxptK', $request->getInvoiceItemReference());
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Omnipay\Stripe;
use Omnipay\Tests\GatewayTestCase;
/**
* @property \Omnipay\Stripe\CheckoutGateway gateway
*/
class CheckoutGatewayTest extends GatewayTestCase
{
public function setUp()
{
parent::setUp();
$this->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());
}
}

View File

@@ -0,0 +1,133 @@
<?php
namespace Omnipay\Stripe\Message;
use GuzzleHttp\Psr7\Request;
use Mockery;
use Omnipay\Tests\TestCase;
class AbstractRequestTest extends TestCase
{
/** @var Mockery\Mock|AbstractRequest */
private $request;
public function setUp()
{
$this->request = Mockery::mock('\Omnipay\Stripe\Message\AbstractRequest')->makePartial();
$this->request->initialize();
}
public function testCardReference()
{
$this->assertSame($this->request, $this->request->setCardReference('abc123'));
$this->assertSame('abc123', $this->request->getCardReference());
}
public function testCardToken()
{
$this->assertSame($this->request, $this->request->setToken('abc123'));
$this->assertSame('abc123', $this->request->getToken());
}
public function testSource()
{
$this->assertSame($this->request, $this->request->setSource('abc123'));
$this->assertSame('abc123', $this->request->getSource());
}
public function testCardData()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getCardData();
$this->assertSame($card['number'], $data['number']);
$this->assertSame($card['cvv'], $data['cvc']);
}
public function testCardDataEmptyCvv()
{
$card = $this->getValidCard();
$card['cvv'] = '';
$this->request->setCard($card);
$data = $this->request->getCardData();
$this->assertTrue(empty($data['cvv']));
}
public function testMetadata()
{
$this->assertSame($this->request, $this->request->setMetadata(array('foo' => 'bar')));
$this->assertSame(array('foo' => 'bar'), $this->request->getMetadata());
}
public function testIdempotencyKey()
{
$this->request->setIdempotencyKeyHeader('UUID');
$this->assertSame('UUID', $this->request->getIdempotencyKeyHeader());
$headers = $this->request->getHeaders();
$this->assertArrayHasKey('Idempotency-Key', $headers);
$this->assertSame('UUID', $headers['Idempotency-Key']);
$httpRequest = new Request(
'GET',
'/',
$headers
);
$this->assertTrue($httpRequest->hasHeader('Idempotency-Key'));
}
public function testStripeVersion()
{
$this->request->setStripeVersion('2019-05-16');
$this->assertSame('2019-05-16', $this->request->getStripeVersion());
$headers = $this->request->getHeaders();
$this->assertArrayHasKey('Stripe-Version', $headers);
$this->assertSame('2019-05-16', $headers['Stripe-Version']);
$httpRequest = new Request(
'GET',
'/',
$headers
);
$this->assertTrue($httpRequest->hasHeader('Stripe-Version'));
}
public function testConnectedStripeAccount()
{
$this->request->setConnectedStripeAccountHeader('ACCOUNT_ID');
$this->assertSame('ACCOUNT_ID', $this->request->getConnectedStripeAccountHeader());
$headers = $this->request->getHeaders();
$this->assertArrayHasKey('Stripe-Account', $headers);
$this->assertSame('ACCOUNT_ID', $headers['Stripe-Account']);
$httpRequest = new Request(
'GET',
'/',
$headers
);
$this->assertTrue($httpRequest->hasHeader('Stripe-Account'));
}
public function testExpandedEndpoint()
{
$this->request->shouldReceive('getEndpoint')->andReturn('https://api.stripe.com/v1');
$this->request->setExpand(['foo', 'bar']);
$actual = $this->request->getExpandedEndpoint();
$this->assertEquals('https://api.stripe.com/v1?expand[]=foo&expand[]=bar', $actual);
}
}

View File

@@ -0,0 +1,272 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Common\ItemBag;
use Omnipay\Tests\TestCase;
class AuthorizeRequestTest extends TestCase
{
/**
* @var AuthorizeRequest
*/
private $request;
public function setUp()
{
$this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '12.00',
'currency' => 'USD',
'card' => $this->getValidCard(),
'description' => 'Order #42',
'metadata' => array(
'foo' => 'bar',
),
'applicationFee' => '1.00'
)
);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame(1200, $data['amount']);
$this->assertSame('usd', $data['currency']);
$this->assertSame('Order #42', $data['description']);
$this->assertSame('false', $data['capture']);
$this->assertSame(array('foo' => 'bar'), $data['metadata']);
$this->assertSame(100, $data['application_fee']);
}
public function testDataWithLevel3()
{
$this->request->setItems([
[
'name' => 'Cupcakes',
'description' => 'Yummy Cupcakes',
'price' => 4,
'quantity' => 2,
'taxes' => 0.4
],
[
'name' => 'Donuts',
'description' => 'A dozen donuts',
'price' => 1.5,
'quantity' => 12,
'discount' => 1.8,
'taxes' => 0.81
]
]);
$this->request->setTransactionId('ORD42-P1');
$this->request->setAmount(25.41);
$data = $this->request->getData();
$this->assertSame('Order #42', $data['description']);
$expectedLevel3 = [
'merchant_reference' => 'ORD42-P1',
'line_items' => [
[
'product_code' => 'Cupcakes',
'product_description' => 'Yummy Cupcakes',
'unit_cost' => 400,
'quantity' => 2,
'tax_amount' => 40,
],
[
'product_code' => 'Donuts',
'product_description' => 'A dozen donuts',
'unit_cost' => 150,
'quantity' => 12,
'discount_amount' => 180,
'tax_amount' => 81,
]
]
];
$this->assertEquals($expectedLevel3, $data['level3']);
}
public function testDataWithInvalidLevel3()
{
$this->request->setItems([
[
'name' => 'Cupcakes',
'description' => 'Yummy Cupcakes',
'price' => 4,
'quantity' => 2,
'taxes' => 0.4
],
[
'name' => 'Donuts',
'description' => 'A dozen donuts',
'price' => 1.5,
'quantity' => 12,
'discount' => 1.8,
'taxes' => 0.8
]
]);
$this->request->setTransactionId('ORD42-P1');
$this->request->setAmount(25.41);
$data = $this->request->getData();
$this->assertArrayNotHasKey('level3', $data,
'should not include level 3 data if the line items do not add up to the amount');
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The source parameter is required
*/
public function testCardRequired()
{
$this->request->setCard(null);
$this->request->getData();
}
public function testDataWithCustomerReference()
{
$this->request->setCard(null);
$this->request->setCustomerReference('abc');
$data = $this->request->getData();
$this->assertSame('abc', $data['customer']);
}
public function testDataWithCardReference()
{
$this->request->setCustomerReference('abc');
$this->request->setCardReference('xyz');
$data = $this->request->getData();
$this->assertSame('abc', $data['customer']);
$this->assertSame('xyz', $data['source']);
}
public function testDataWithStatementDescriptor()
{
$this->request->setStatementDescriptor('OMNIPAY');
$data = $this->request->getData();
$this->assertSame('OMNIPAY', $data['statement_descriptor']);
}
public function testDataWithSourceAndDestination()
{
$this->request->setSource('abc');
$this->request->setDestination('xyz');
$data = $this->request->getData();
$this->assertSame('abc', $data['source']);
$this->assertSame('xyz', $data['destination']);
}
public function testDataWithToken()
{
$this->request->setCustomerReference('abc');
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('abc', $data['customer']);
$this->assertSame('xyz', $data['source']);
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['source']['number']);
}
public function testDataWithTracks()
{
$cardData = $this->getValidCard();
$tracks = "%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F";
$cardData['tracks'] = $tracks;
unset($cardData['cvv']);
unset($cardData['billingPostcode']);
$this->request->setCard(new CreditCard($cardData));
$data = $this->request->getData();
$this->assertSame($tracks, $data['source']['swipe_data']);
$this->assertCount(2, $data['source'], "Swipe data should be present. All other fields are not required");
// If there is any mismatch between the track data and the parsed data, Stripe rejects the transaction, so it's
// best to suppress fields that is already present in the track data.
$this->assertArrayNotHasKey('number', $data, 'Should not send card number for card present charge');
$this->assertArrayNotHasKey('exp_month', $data, 'Should not send expiry month for card present charge');
$this->assertArrayNotHasKey('exp_year', $data, 'Should not send expiry year for card present charge');
$this->assertArrayNotHasKey('name', $data, 'Should not send name for card present charge');
// Billing address is not accepted for card present transactions.
$this->assertArrayNotHasKey('address_line1', $data, 'Should not send billing address for card present charge');
$this->assertArrayNotHasKey('address_line2', $data, 'Should not send billing address for card present charge');
$this->assertArrayNotHasKey('address_city', $data, 'Should not send billing address for card present charge');
$this->assertArrayNotHasKey('address_state', $data, 'Should not send billing address for card present charge');
}
public function testDataWithTracksAndZipCVVManuallyEntered()
{
$cardData = $this->getValidCard();
$tracks = "%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F";
$cardData['tracks'] = $tracks;
$this->request->setCard(new CreditCard($cardData));
$data = $this->request->getData();
$this->assertSame($tracks, $data['source']['swipe_data']);
$this->assertSame($cardData['cvv'], $data['source']['cvc']);
$this->assertSame($cardData['billingPostcode'], $data['source']['address_zip']);
$this->assertCount(4, $data['source'], "Swipe data, cvv and zip code should be present");
}
public function testSendSuccess()
{
$this->setMockHttpResponse('PurchaseSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference());
$this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference());
$this->assertSame('req_8PDHeZazN2LwML', $response->getRequestId());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('PurchaseFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IUAZQWFYrPooM', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Your card was declined', $response->getMessage());
}
public function testSetItems()
{
$items = new ItemBag([
[
'amount' => '120.00',
'currency' => 'USD',
'card' => $this->getValidCard(),
'description' => 'Order #42',
'metadata' => [
'foo' => 'bar',
],
'applicationFee' => '2.00'
]
]);
$this->request->setItems($items);
$this->assertEquals($items, $this->request->getItems());
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CancelSubscriptionRequestTest extends TestCase
{
/**
* @var CancelSubscriptionRequest
*/
private $request;
public function setUp()
{
$this->request = new CancelSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_7lfqk3Om3t4xSU');
$this->request->setSubscriptionReference('sub_7mU0FokE8GQZFW');
$this->request->setAtPeriodEnd(true);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_7lfqk3Om3t4xSU/subscriptions/sub_7mU0FokE8GQZFW', $this->request->getEndpoint());
$this->assertSame(true, $this->request->getAtPeriodEnd());
$data = $this->request->getData();
$this->assertSame('true', $data['at_period_end']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CancelSubscriptionSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('sub_7mU0FokE8GQZFW', $response->getSubscriptionReference());
$this->assertNotNull($response->getPlan());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CancelSubscriptionFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSubscriptionReference());
$this->assertNull($response->getPlan());
$this->assertSame('Customer cus_7lqqgOm33t4xSU does not have a subscription with ID sub_7mU0DonX8GQZFW', $response->getMessage());
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CaptureRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransactionReference('foo');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/charges/foo/capture', $this->request->getEndpoint());
}
public function testAmount()
{
// default is no amount
$this->assertArrayNotHasKey('amount', $this->request->getData());
$this->request->setAmount('10.00');
$data = $this->request->getData();
$this->assertSame(1000, $data['amount']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CaptureSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1lvgjcQgrNWUuZ', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CaptureFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Charge ch_1lvgjcQgrNWUuZ has already been captured.', $response->getMessage());
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateCardRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CreateCardRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCard($this->getValidCard());
}
public function testEndpoint()
{
$this->request->setCustomerReference('');
$this->assertSame('https://api.stripe.com/v1/customers', $this->request->getEndpoint());
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99/cards', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The source parameter is required
*/
public function testCard()
{
$this->request->setCard(null);
$this->request->getData();
}
public function testDataWithToken()
{
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
public function testDataWithCardReference()
{
$this->request->setCard(null);
$this->request->setCardReference('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
public function testDataWithSource()
{
$this->request->setCard(null);
$this->request->setSource('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['source']['number']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCardSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_5i75ZdvSgIgLdW', $response->getCustomerReference());
$this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('CreateCardFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage());
}
public function testCardWithoutEmail()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertArrayNotHasKey('email', $card);
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateCouponRequestTest extends TestCase
{
/**
* @var CreateCouponRequest
*/
private $request;
public function setUp()
{
$this->request = new CreateCouponRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setId('50_OFF');
$this->request->setDuration('repeating');
$this->request->setCurrency('EUR');
$this->request->setRedeemBy(1606460031);
$this->request->setPercentOff(50);
$this->request->setDurationInMonths(3);
$this->request->setMaxRedemptions(10);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/coupons', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCouponSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('50_OFF', $response->getCouponId());
$this->assertNotNull($response->getCoupon());
$this->assertNull($response->getMessage());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage Either amount_off or percent_off is required
*/
public function testAmountPercentRequired()
{
$this->request->setPercentOff(null);
$this->request->setAmountOff(null);
$this->request->getData();
}
public function testSendError()
{
$this->setMockHttpResponse('CreateCouponFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getCoupon());
$this->assertNull($response->getCouponId());
$this->assertSame('Coupon already exists.', $response->getMessage());
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateCustomerRequestTest extends TestCase
{
/** @var CreateCustomerRequest */
protected $request;
public function setUp()
{
$this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers', $this->request->getEndpoint());
}
public function testData()
{
$this->request->setEmail('customer@business.dom');
$this->request->setDescription('New customer');
$this->request->setMetadata(['field' => 'value']);
$this->request->setPaymentMethod('payment_method_id');
$this->request->setName('Customer Name');
$data = $this->request->getData();
$this->assertSame('customer@business.dom', $data['email']);
$this->assertSame('New customer', $data['description']);
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
$this->assertSame('payment_method_id', $data['payment_method']);
$this->assertSame('Customer Name', $data['name']);
}
public function testDataWithToken()
{
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['card']);
$this->assertFalse(isset($data['email']));
}
public function testDataWithTokenAndEmail()
{
$this->request->setToken('xyz');
$this->request->setEmail('xyz@test.com');
$data = $this->request->getData();
$this->assertSame('xyz', $data['card']);
$this->assertSame('xyz@test.com', $data['email']);
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['card']['number']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCustomerSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZSEtqSghKx99', $response->getCustomerReference());
$this->assertSame('card_15WhVwIobxWFFmzdQ3QBSwNi', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('CreateCustomerFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage());
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateInvoiceItemRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CreateInvoiceItemRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_7vX2emm98A7crY');
$this->request->setAmount(1000);
$this->request->setCurrency('usd');
$this->request->setDescription('One-time setup fee');
$this->request->setInvoiceReference('in_7vX2emm98A7crY7vX2');
$this->request->setSubscriptionReference('sub_7vX2emm98A7crY7vX2');
$this->request->setDiscountable(false);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoiceitems', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateInvoiceItemSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ii_17hCVWCry4L0tg4v2hLQvxrX', $response->getInvoiceItemReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CreateInvoiceItemFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getInvoiceItemReference());
$this->assertSame('No such customer: cus_7vX2emm98A7YcrY', $response->getMessage());
}
}

Some files were not shown because too many files have changed in this diff Show More