-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiveStripeClient.php
105 lines (90 loc) · 3.8 KB
/
LiveStripeClient.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace MatchBot\Client;
use MatchBot\Domain\Donation;
use MatchBot\Domain\StripeConfirmationTokenId;
use MatchBot\Domain\StripeCustomerId;
use MatchBot\Domain\StripePaymentMethodId;
use Stripe\BalanceTransaction;
use Stripe\Charge;
use Stripe\ConfirmationToken;
use Stripe\CustomerSession;
use Stripe\Exception\InvalidArgumentException;
use Stripe\PaymentIntent;
use Stripe\PaymentMethod;
use Stripe\StripeClient;
/**
* Connects to a real Stripe service, either in test mode or production mode.
*
*/
class LiveStripeClient implements Stripe
{
public const array SESSION_COMPONENTS = [
'payment_element' => [
'enabled' => true,
'features' => [
'payment_method_allow_redisplay_filters' => ['always', 'unspecified'],
'payment_method_redisplay' => 'enabled',
'payment_method_redisplay_limit' => 3, // Keep default 3; 10 is max stripe allows.
// default value – need to ensure it stays off to avoid breaking Regular Giving by mistake,
// since the list can include `off_session` saved cards that may be mandate-linked.
'payment_method_remove' => 'disabled',
'payment_method_save' => 'enabled',
'payment_method_save_usage' => 'on_session',
],
]
];
public function __construct(private StripeClient $stripeClient)
{
}
public function cancelPaymentIntent(string $paymentIntentId): void
{
$this->stripeClient->paymentIntents->cancel($paymentIntentId);
}
public function updatePaymentIntent(string $paymentIntentId, array $updateData): void
{
$this->stripeClient->paymentIntents->update($paymentIntentId, $updateData);
}
public function confirmPaymentIntent(string $paymentIntentId, array $params = []): PaymentIntent
{
return $this->stripeClient->paymentIntents->confirm($paymentIntentId, $params);
}
public function retrievePaymentIntent(string $paymentIntentId): PaymentIntent
{
return $this->stripeClient->paymentIntents->retrieve($paymentIntentId);
}
public function retrieveConfirmationToken(StripeConfirmationTokenId $confirmationTokenId): ConfirmationToken
{
return $this->stripeClient->confirmationTokens->retrieve($confirmationTokenId->stripeConfirmationTokenId);
}
public function retrieveCharge(string $chargeId): Charge
{
return $this->stripeClient->charges->retrieve($chargeId);
}
public function createPaymentIntent(array $createPayload): PaymentIntent
{
return $this->stripeClient->paymentIntents->create($createPayload);
}
public function createCustomerSession(StripeCustomerId $stripeCustomerId): CustomerSession
{
return $this->stripeClient->customerSessions->create([
'customer' => $stripeCustomerId->stripeCustomerId,
'components' => self::SESSION_COMPONENTS,
]);
}
public function createRegularGivingCustomerSession(StripeCustomerId $stripeCustomerId): CustomerSession
{
$components = self::SESSION_COMPONENTS;
$components['payment_element']['features']['payment_method_save_usage'] = 'off_session';
$components['payment_element']['features']['payment_method_redisplay'] = 'disabled';
unset($components['payment_element']['features']['payment_method_allow_redisplay_filters']);
unset($components['payment_element']['features']['payment_method_redisplay_limit']);
return $this->stripeClient->customerSessions->create([
'customer' => $stripeCustomerId->stripeCustomerId,
'components' => $components,
]);
}
public function retrieveBalanceTransaction(string $id): BalanceTransaction
{
return $this->stripeClient->balanceTransactions->retrieve($id);
}
}