-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStubStripeClient.php
More file actions
168 lines (138 loc) · 5.13 KB
/
Copy pathStubStripeClient.php
File metadata and controls
168 lines (138 loc) · 5.13 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
namespace MatchBot\Client;
use MatchBot\Domain\Money;
use MatchBot\Domain\StripeConfirmationTokenId;
use MatchBot\Domain\StripeCustomerId;
use MatchBot\Domain\StripePaymentMethodId;
use Ramsey\Uuid\Uuid;
use Stripe\BalanceTransaction;
use Stripe\Charge;
use Stripe\ConfirmationToken;
use Stripe\Customer;
use Stripe\CustomerSession;
use Stripe\PaymentIntent;
use Stripe\PaymentMethod;
use Stripe\SetupIntent;
use Stripe\StripeObject;
/**
* Does not connect to stripe. For use in load testing to allow testing Matchbot with high traffic levels
* without sending all that traffic to Stripe. Test mode stripe does not allow sending high volumes of test traffic
* so we have to stub it out.
*/
class StubStripeClient implements Stripe
{
#[\Override]
public function cancelPaymentIntent(string $paymentIntentId): void
{
$this->pause();
}
/** Pause to simulate waiting for an HTTP response from Stripe */
public function pause(): void
{
// half second
usleep(500_000);
}
#[\Override]
public function updatePaymentIntent(string $paymentIntentId, array $updateData): void
{
$this->pause();
}
#[\Override]
public function confirmPaymentIntent(string $paymentIntentId, array $params): PaymentIntent
{
$this->pause();
$pi = new PaymentIntent($paymentIntentId);
$pi->status = PaymentIntent::STATUS_SUCCEEDED;
return $pi;
}
#[\Override]
public function retrievePaymentIntent(string $paymentIntentId): PaymentIntent
{
$this->pause();
$pi = new PaymentIntent($paymentIntentId);
$pi->setup_future_usage = null;
return $pi;
}
#[\Override]
public function createPaymentIntent(array $createPayload): PaymentIntent
{
$this->pause();
return new PaymentIntent('pi_stub_' . self::randomString());
}
private static function randomString(): string
{
return substr(Uuid::uuid4()->toString(), 0, 15);
}
#[\Override]
public function createCustomerSession(StripeCustomerId $stripeCustomerId): CustomerSession
{
$session = new CustomerSession();
$session->client_secret = 'fake_client_secret';
$session->expires_at = time() + 10;
return $session;
}
#[\Override]
public function retrieveConfirmationToken(StripeConfirmationTokenId $confirmationTokenId): ConfirmationToken
{
$confirmationToken = new ConfirmationToken();
/** @psalm-suppress InvalidPropertyAssignmentValue */
$confirmationToken->payment_method_preview = new StripeObject();
/** @psalm-suppress InvalidPropertyAssignmentValue */
$confirmationToken->payment_method_preview['type'] = 'card';
/** @psalm-suppress InvalidPropertyAssignmentValue */
$confirmationToken->payment_method_preview['card'] = ['brand' => 'discover', 'country' => 'GB'];
/** @psalm-suppress InvalidPropertyAssignmentValue */
$confirmationToken->payment_method_preview['pay_by_bank'] = null;
return $confirmationToken;
}
#[\Override]
public function createRegularGivingCustomerSession(StripeCustomerId $stripeCustomerId): CustomerSession
{
return $this->createCustomerSession($stripeCustomerId);
}
#[\Override]
public function retrieveCharge(string $chargeId): Charge
{
throw new \Exception("Retrieve Charge not implemented in stub- not currently used in load tests");
}
#[\Override]
public function retrieveBalanceTransaction(string $id): BalanceTransaction
{
throw new \Exception("Retrieve Balance Transaction not implemented in stub- not currently used in load tests");
}
#[\Override]
public function createSetupIntent(StripeCustomerId $stripeCustomerId): SetupIntent
{
throw new \Exception("Create setup intent not implemented in stub - not currently used in load tests");
}
#[\Override]
public function retrievePaymentMethod(StripeCustomerId $customerId, StripePaymentMethodId $methodId): PaymentMethod
{
throw new \Exception("Retrieve Payment Method not implemented in stub - not currently used in load tests");
}
#[\Override]
public function retrievePendingPaymentMethod(StripePaymentMethodId $methodId): PaymentMethod
{
throw new \Exception("Retrieve Pending Payment Method not implemented in stub - not currently used in load tests");
}
#[\Override]
public function detatchPaymentMethod(StripePaymentMethodId $paymentMethodId): void
{
throw new \Exception("Detatch Payment Method not implemented in stub - not currently used in load tests");
}
#[\Override]
public function deleteCustomer(StripeCustomerId $getStripeCustomerId): void
{
$this->pause();
}
#[\Override]
public function retrieveCustomer(StripeCustomerId $stripeCustomerId, array $params): Customer
{
throw new \Exception("Retrieve Customer not implemented in stub - not currently used in load tests");
}
#[\Override]
public function refundCustomerBalance(StripeCustomerId $stripeCustomerId, Money $money): void
{
$this->pause();
}
}