-
Notifications
You must be signed in to change notification settings - Fork 31
/
StripeCheckoutGatewayFactory.php
68 lines (57 loc) · 2.74 KB
/
StripeCheckoutGatewayFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Payum\Stripe;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\LogicException;
use Payum\Core\GatewayFactory;
use Payum\Stripe\Action\Api\CreateChargeAction;
use Payum\Stripe\Action\Api\CreateCustomerAction;
use Payum\Stripe\Action\Api\CreatePlanAction;
use Payum\Stripe\Action\Api\CreateSubscriptionAction;
use Payum\Stripe\Action\Api\CreateTokenAction;
use Payum\Stripe\Action\Api\ObtainTokenAction;
use Payum\Stripe\Action\CaptureAction;
use Payum\Stripe\Action\ConvertPaymentAction;
use Payum\Stripe\Action\GetCreditCardTokenAction;
use Payum\Stripe\Action\StatusAction;
use Payum\Stripe\Extension\CreateCustomerExtension;
use Stripe\Stripe;
class StripeCheckoutGatewayFactory extends GatewayFactory
{
protected function populateConfig(ArrayObject $config): void
{
if (! class_exists(Stripe::class)) {
throw new LogicException('You must install "stripe/stripe-php:~2.0|~3.0" library.');
}
$config->defaults([
'payum.factory_name' => 'stripe_checkout',
'payum.factory_title' => 'Stripe Checkout',
'payum.template.obtain_token' => '@PayumStripe/Action/obtain_checkout_token.html.twig',
'payum.action.capture' => new CaptureAction(),
'payum.action.convert_payment' => new ConvertPaymentAction(),
'payum.action.status' => new StatusAction(),
'payum.action.get_credit_card_token' => new GetCreditCardTokenAction(),
'payum.action.obtain_token' => fn (ArrayObject $config) => new ObtainTokenAction($config['payum.template.obtain_token']),
'payum.action.create_charge' => new CreateChargeAction(),
'payum.action.create_customer' => new CreateCustomerAction(),
'payum.action.create_plan' => new CreatePlanAction(),
'payum.action.create_token' => new CreateTokenAction(),
'payum.action.create_subscription' => new CreateSubscriptionAction(),
'payum.extension.create_customer' => new CreateCustomerExtension(),
]);
if (! $config['payum.api']) {
$config['payum.default_options'] = [
'publishable_key' => '',
'secret_key' => '',
];
$config->defaults($config['payum.default_options']);
$config['payum.required_options'] = ['publishable_key', 'secret_key'];
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
return new Keys($config['publishable_key'], $config['secret_key']);
};
}
$config['payum.paths'] = array_replace([
'PayumStripe' => __DIR__ . '/Resources/views',
], $config['payum.paths'] ?: []);
}
}