-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveStripeClient.php
80 lines (69 loc) · 2.95 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
<?php
namespace MatchBot\Client;
use MatchBot\Domain\Donation;
use MatchBot\Domain\StripeConfirmationTokenId;
use MatchBot\Domain\StripeCustomerId;
use MatchBot\Domain\StripePaymentMethodId;
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 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 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' => [
'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',
// off-session (Regular Giving) payment methods will be saved separately.
// @todo-regular-giving link to that when implemented.
'payment_method_save_usage' => 'on_session',
],
]
],
]);
}
}