Skip to content

Commit 085276c

Browse files
committed
Rename namespace of the library to handle more than one gateway
1 parent d2c1ae0 commit 085276c

93 files changed

Lines changed: 385 additions & 371 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 12 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
[![Build Status][ico-travis]][link-travis]
44
[![Quality Score][ico-code-quality]][link-code-quality]
55

6-
## Payum Stripe checkout session gateway
6+
## Payum Stripe gateways
77

8-
This library is designed to add a new gateway to Payum to support Stripe checkout session
9-
10-
See https://stripe.com/docs/payments/checkout for more information.
8+
This library is designed to add a new gateways to Payum to support Stripe (with SCA support)
119

1210
## Installation
1311

1412
Install using Composer :
1513

1614
```bash
17-
composer require prometee/payum-stripe-checkout-session
15+
composer require prometee/payum-stripe
1816
```
1917

2018
Choose one of [php-http/client-implementation](https://packagist.org/providers/php-http/client-implementation),
@@ -26,121 +24,18 @@ composer require php-http/guzzle6-adapter
2624

2725
## Configuration
2826

29-
### API keys
30-
31-
Get your `publishable_key` and your `secret_key` on your Stripe account :
32-
33-
https://dashboard.stripe.com/test/apikeys
34-
35-
### Webhook key
36-
Then get a `webhook_secret_key` configured with at least two events :
37-
`payment_intent.canceled` and `checkout.session.completed`
38-
and configured with the url to the URL to `notify.php`
39-
40-
https://dashboard.stripe.com/test/webhooks
41-
42-
```php
43-
<?php
44-
45-
declare(strict_types=1);
46-
47-
$loader = require_once( __DIR__.'/vendor/autoload.php');
48-
49-
use Payum\Core\GatewayFactoryInterface;
50-
use Prometee\PayumStripeCheckoutSession\StripeCheckoutSessionGatewayFactory;
51-
use Payum\Core\PayumBuilder;
52-
use Payum\Core\Payum;
53-
54-
/** @var Payum $payum */
55-
$payum = (new PayumBuilder())
56-
->addDefaultStorages()
57-
->addGatewayFactory('stripe_checkout_session', function(array $config, GatewayFactoryInterface $coreGatewayFactory) {
58-
return new StripeCheckoutSessionGatewayFactory($config, $coreGatewayFactory);
59-
})
60-
->addGateway('stripe_checkout_session', [
61-
'factory' => 'stripe_checkout_session',
62-
'publishable_key' => 'pk_test_abcdefghijklmnopqrstuvwx',
63-
'secret_key' => 'sk_test_abcdefghijklmnopqrstuvwx',
64-
'webhook_secret_keys' => [
65-
'whsec_abcdefghijklmnopqrstuvwxyz012345'
66-
],
67-
])
68-
->getPayum()
69-
;
70-
```
71-
72-
## Usage quick Example
73-
74-
More effort is needed to get a full working Payum solution, but here is a generic example.
75-
76-
```php
77-
<?php
78-
79-
declare(strict_types=1);
80-
81-
use Payum\Core\Model\Payment;
82-
83-
$gateway = $payum->getGateway('stripe_checkout_session');
84-
85-
$payment = new Payment();
86-
$payment->setNumber('00001');
87-
$payment->setTotalAmount(123);
88-
$payment->setCurrencyCode('USD');
89-
$payment->setClientEmail('test@domain.tld');
90-
$payment->setDescription('My test order');
91-
$payment->setDetails([]);
92-
93-
$token = $payum->getTokenFactory()
94-
->createCaptureToken('stripe_checkout_session', $payment, '/after-pay.php');
95-
96-
$gateway->execute(new Capture($token));
97-
```
98-
99-
## Webhooks
100-
101-
For generic info on Stripe webhooks read this :
102-
https://stripe.com/docs/webhooks
103-
104-
### How the webhooks are handle into this gateway ?
105-
106-
The starting point is always an `Action` with Payum and generically you have to use `Notify*Action` to handle webhooks.
107-
108-
Because we have to set a static url without any token variable params on Stripe backend,
109-
we can't use `NotifyAction` but we can use [`NotifyUnsafeAction`](src/Action/NotifyAction.php) instead.
110-
111-
This `Action` will ask for 2 other actions to :
112-
113-
1. Resolve the webhook event, meaning :
114-
- retrieve the Stripe signature in the request headers.
115-
- try to construct the webhook `Event` object checking it with the webhook secret key.
116-
2. Give this resolved `Event` to an `Action` able to consume this `Event`.
117-
118-
So if you want to consume another webhook event type, you just need to create an `Action` extending `Prometee\PayumStripeCheckoutSession\Action\Api\WebhookEvent\AbstractWebhookEventAction`.
119-
Examples available into the `src/Action/Api/WebhookEvent` folder.
120-
121-
## TODO
122-
123-
- Add a `RefundAction` if it's possible just with Payum interface.
124-
- Add Subscription basic webhooks.
125-
- Add `Extension` or `ConvertPayment` to handle subscription and card storing.
126-
127-
## More
128-
129-
Check the corresponding bundle :
130-
131-
https://github.com/Prometee/PayumStripeCheckoutSessionBundle
27+
- [Stripe Checkout Session gateway](docs/stripe-checkout-session/README.md)
28+
- [Stripe JS gateway](docs/stripe-js/README.md)
13229

133-
And the Sylius plugin :
13430

135-
https://github.com/Prometee/SyliusPayumStripeCheckoutSessionPlugin
13631

13732

138-
[ico-version]: https://img.shields.io/packagist/v/Prometee/payum-stripe-checkout-session.svg?style=flat-square
33+
[ico-version]: https://img.shields.io/packagist/v/Prometee/payum-stripe.svg?style=flat-square
13934
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
140-
[ico-travis]: https://img.shields.io/travis/Prometee/PayumStripeCheckoutSession/master.svg?style=flat-square
141-
[ico-code-quality]: https://img.shields.io/scrutinizer/g/Prometee/PayumStripeCheckoutSession.svg?style=flat-square
35+
[ico-travis]: https://img.shields.io/travis/Prometee/PayumStripe/master.svg?style=flat-square
36+
[ico-code-quality]: https://img.shields.io/scrutinizer/g/Prometee/PayumStripe.svg?style=flat-square
14237

143-
[link-packagist]: https://packagist.org/packages/prometee/payum-stripe-checkout-session
144-
[link-travis]: https://travis-ci.org/Prometee/PayumStripeCheckoutSession
145-
[link-scrutinizer]: https://scrutinizer-ci.com/g/Prometee/PayumStripeCheckoutSession/code-structure
146-
[link-code-quality]: https://scrutinizer-ci.com/g/Prometee/PayumStripeCheckoutSession
38+
[link-packagist]: https://packagist.org/packages/prometee/payum-stripe
39+
[link-travis]: https://travis-ci.org/Prometee/PayumStripe
40+
[link-scrutinizer]: https://scrutinizer-ci.com/g/Prometee/PayumStripe/code-structure
41+
[link-code-quality]: https://scrutinizer-ci.com/g/Prometee/PayumStripe

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "prometee/payum-stripe-checkout-session",
3-
"description": "Payum Stripe checkout session gateway",
2+
"name": "prometee/payum-stripe",
3+
"description": "Payum Stripe gateways",
44
"type": "library",
55
"require": {
66
"php": "^7.3",
@@ -14,10 +14,10 @@
1414
"phpstan/phpstan": "^0.12.18"
1515
},
1616
"autoload": {
17-
"psr-4": { "Prometee\\PayumStripeCheckoutSession\\": "src/" }
17+
"psr-4": { "Prometee\\PayumStripe\\": "src/" }
1818
},
1919
"autoload-dev": {
20-
"psr-4": { "Tests\\Prometee\\PayumStripeCheckoutSession\\": "tests/" }
20+
"psr-4": { "Tests\\Prometee\\PayumStripe\\": "tests/" }
2121
},
2222
"license": "MIT",
2323
"extra": {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Payum Stripe checkout session gateway
2+
3+
See https://stripe.com/docs/payments/checkout for more information.
4+
5+
## Configuration
6+
7+
First get [your credentials](../stripe-credentials.md) from Stripe dashboard.
8+
9+
```php
10+
<?php
11+
12+
declare(strict_types=1);
13+
14+
$loader = require_once( __DIR__.'/vendor/autoload.php');
15+
16+
use Payum\Core\GatewayFactoryInterface;
17+
use Prometee\PayumStripe\StripeCheckoutSessionGatewayFactory;
18+
use Payum\Core\PayumBuilder;
19+
use Payum\Core\Payum;
20+
21+
/** @var Payum $payum */
22+
$payum = (new PayumBuilder())
23+
->addDefaultStorages()
24+
->addGatewayFactory('stripe_checkout_session', function(array $config, GatewayFactoryInterface $coreGatewayFactory) {
25+
return new StripeCheckoutSessionGatewayFactory($config, $coreGatewayFactory);
26+
})
27+
->addGateway('stripe_checkout_session', [
28+
'factory' => 'stripe_checkout_session',
29+
'publishable_key' => 'pk_test_abcdefghijklmnopqrstuvwx',
30+
'secret_key' => 'sk_test_abcdefghijklmnopqrstuvwx',
31+
'webhook_secret_keys' => [
32+
'whsec_abcdefghijklmnopqrstuvwxyz012345'
33+
],
34+
])
35+
->getPayum()
36+
;
37+
```
38+
39+
## Usage quick Example
40+
41+
More effort is needed to get a full working Payum solution, but here is a generic example.
42+
43+
```php
44+
<?php
45+
46+
declare(strict_types=1);
47+
48+
use Payum\Core\Model\Payment;
49+
use Payum\Core\Request\Capture;
50+
51+
$gateway = $payum->getGateway('stripe_checkout_session');
52+
53+
$payment = new Payment();
54+
$payment->setNumber('00001');
55+
$payment->setTotalAmount(123);
56+
$payment->setCurrencyCode('USD');
57+
$payment->setClientEmail('test@domain.tld');
58+
$payment->setDescription('My test order');
59+
$payment->setDetails([]);
60+
61+
$token = $payum->getTokenFactory()
62+
->createCaptureToken('stripe_checkout_session', $payment, '/after-pay.php');
63+
64+
$gateway->execute(new Capture($token));
65+
```
66+
67+
## Webhooks
68+
69+
For generic info on Stripe webhooks read this :
70+
https://stripe.com/docs/webhooks
71+
72+
### How the webhooks are handle into this gateway ?
73+
74+
The starting point is always an `Action` with Payum and generically you have to use `Notify*Action` to handle webhooks.
75+
76+
Because we have to set a static url on Stripe backend (eg: without any token variable params),
77+
we have to use what Payum is calling a `NotifyUnsafe`, it's a `Notify` with a `null` `Token`.
78+
You can find this action here : [`NotifyAction.php`](../../src/Action/NotifyAction.php).
79+
If the token is null then we will try to handle a webhook, and if a token is detected
80+
then it's a normal `Notify` so we must handle a `Sync` to refresh a payment details.
81+
82+
#### Resolving a webhook : `NotifyUnsafe`
83+
The [`NotifyAction.php`](../../src/Action/NotifyAction.php) will ask for 2 other actions to :
84+
85+
1. Resolve the webhook event, meaning :
86+
- retrieve the Stripe signature in the request headers.
87+
- try to construct the webhook `Event` object, checking it with the webhook secret key.
88+
2. Give this resolved `Event` to an `Action` able to consume this `Event`.
89+
90+
So if you want to consume another webhook event type, you just need to create an `Action`
91+
extending [`Prometee\PayumStripe\Action\Api\WebhookEvent\AbstractWebhookEventAction`](../../src/Action/Api/WebhookEvent/AbstractWebhookEventAction.php).
92+
Examples available into the [`src/Action/Api/WebhookEvent/`](../../src/Action/Api/WebhookEvent) folder.
93+
94+
## More
95+
96+
Check the dedicated bundle :
97+
98+
https://github.com/Prometee/PayumStripeCheckoutSessionBundle
99+
100+
And the Sylius plugin :
101+
102+
https://github.com/Prometee/SyliusPayumStripeCheckoutSessionPlugin

docs/stripe-credentials.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Credentials
2+
3+
## API keys
4+
5+
Get your `publishable_key` and your `secret_key` on your Stripe account :
6+
7+
https://dashboard.stripe.com/test/apikeys
8+
9+
## Webhook key
10+
Then get a `webhook_secret_key` configured with at least two events :
11+
`payment_intent.canceled` and `checkout.session.completed`
12+
and configured with the url to the URL to `notify.php`
13+
14+
https://dashboard.stripe.com/test/webhooks

docs/stripe-js/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Payum Stripe js gateway
2+
3+
See https://stripe.com/docs/payments for more information.
4+
5+
WORK IN PROGRESS !

src/Action/Api/ConstructEventAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Prometee\PayumStripeCheckoutSession\Action\Api;
5+
namespace Prometee\PayumStripe\Action\Api;
66

77
use Payum\Core\Action\ActionInterface;
88
use Payum\Core\Exception\RequestNotSupportedException;
9-
use Prometee\PayumStripeCheckoutSession\Request\Api\ConstructEvent;
10-
use Prometee\PayumStripeCheckoutSession\Wrapper\EventWrapper;
9+
use Prometee\PayumStripe\Request\Api\ConstructEvent;
10+
use Prometee\PayumStripe\Wrapper\EventWrapper;
1111
use Stripe\Exception\SignatureVerificationException;
1212
use Stripe\Webhook;
1313

src/Action/Api/RedirectToCheckoutAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Prometee\PayumStripeCheckoutSession\Action\Api;
5+
namespace Prometee\PayumStripe\Action\Api;
66

77
use Payum\Core\Action\ActionInterface;
88
use Payum\Core\ApiAwareInterface;
@@ -11,7 +11,7 @@
1111
use Payum\Core\GatewayAwareTrait;
1212
use Payum\Core\Reply\HttpResponse;
1313
use Payum\Core\Request\RenderTemplate;
14-
use Prometee\PayumStripeCheckoutSession\Request\Api\RedirectToCheckout;
14+
use Prometee\PayumStripe\Request\Api\RedirectToCheckout;
1515

1616
final class RedirectToCheckoutAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface
1717
{

src/Action/Api/ResolveWebhookEventAction.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Prometee\PayumStripeCheckoutSession\Action\Api;
5+
namespace Prometee\PayumStripe\Action\Api;
66

77
use LogicException;
88
use Payum\Core\Action\ActionInterface;
@@ -11,9 +11,9 @@
1111
use Payum\Core\GatewayAwareInterface;
1212
use Payum\Core\GatewayAwareTrait;
1313
use Payum\Core\Request\GetHttpRequest;
14-
use Prometee\PayumStripeCheckoutSession\Request\Api\ConstructEvent;
15-
use Prometee\PayumStripeCheckoutSession\Request\Api\ResolveWebhookEvent;
16-
use Prometee\PayumStripeCheckoutSession\Wrapper\EventWrapperInterface;
14+
use Prometee\PayumStripe\Request\Api\ConstructEvent;
15+
use Prometee\PayumStripe\Request\Api\ResolveWebhookEvent;
16+
use Prometee\PayumStripe\Wrapper\EventWrapperInterface;
1717

1818
class ResolveWebhookEventAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface
1919
{

src/Action/Api/Resource/AbstractAllAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Prometee\PayumStripeCheckoutSession\Action\Api\Resource;
5+
namespace Prometee\PayumStripe\Action\Api\Resource;
66

77
use Payum\Core\Exception\LogicException;
88
use Payum\Core\Exception\RequestNotSupportedException;
9-
use Prometee\PayumStripeCheckoutSession\Action\Api\StripeApiAwareTrait;
10-
use Prometee\PayumStripeCheckoutSession\Request\Api\Resource\AllInterface;
9+
use Prometee\PayumStripe\Action\Api\StripeApiAwareTrait;
10+
use Prometee\PayumStripe\Request\Api\Resource\AllInterface;
1111
use Stripe\ApiOperations\All;
1212
use Stripe\Collection;
1313
use Stripe\Exception\ApiErrorException;

src/Action/Api/Resource/AbstractCreateAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Prometee\PayumStripeCheckoutSession\Action\Api\Resource;
5+
namespace Prometee\PayumStripe\Action\Api\Resource;
66

77
use Payum\Core\Exception\LogicException;
88
use Payum\Core\Exception\RequestNotSupportedException;
9-
use Prometee\PayumStripeCheckoutSession\Action\Api\StripeApiAwareTrait;
10-
use Prometee\PayumStripeCheckoutSession\Request\Api\Resource\CreateInterface;
9+
use Prometee\PayumStripe\Action\Api\StripeApiAwareTrait;
10+
use Prometee\PayumStripe\Request\Api\Resource\CreateInterface;
1111
use Stripe\ApiOperations\Create;
1212
use Stripe\ApiResource;
1313
use Stripe\Exception\ApiErrorException;

0 commit comments

Comments
 (0)