← All changes
|
app/Modules/PaymentMethods/StripeGateway/API/API.php
+18
-4
1.6.0
→
1.6.5
View file →
| @@ -127,18 +127,32 @@ | ||
| 127 | 127 | |
| 128 | 128 | return $data; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - public function getEvent($eventId) | |
| 131 | + /** | |
| 132 | + * Event ids are namespaced per mode, so a live id is unfetchable with a test key | |
| 133 | + * and vice versa. The store's global mode toggle is not a reliable proxy — a | |
| 134 | + * renewal is billed by Stripe on its own schedule, whatever the store is set to. | |
| 135 | + * | |
| 136 | + * @param string $eventId | |
| 137 | + * @param bool|null $livemode Mode the event belongs to; null falls back to the store setting. | |
| 138 | + * @return object|null|\WP_Error Null when the response body is not decodable JSON. | |
| 139 | + */ | |
| 140 | + public function getEvent($eventId, $livemode = null) | |
| 132 | 141 | { |
| 133 | - $api = $this->getApi(); | |
| 142 | + $mode = 'current'; | |
| 143 | + if (!is_null($livemode)) { | |
| 144 | + $mode = $livemode ? 'live' : 'test'; | |
| 145 | + } | |
| 146 | + | |
| 147 | + $api = $this->getApi($mode); | |
| 134 | 148 | return $api::request([], 'events/' . $eventId, 'GET'); |
| 135 | 149 | } |
| 136 | 150 | |
| 137 | - public function getApi() | |
| 151 | + public function getApi($mode = 'current') | |
| 138 | 152 | { |
| 139 | 153 | $api = new ApiRequest(); |
| 140 | - $api::set_secret_key((new StripeSettingsBase())->getApiKey()); | |
| 154 | + $api::set_secret_key((new StripeSettingsBase())->getApiKey($mode)); | |
| 141 | 155 | return $api; |
| 142 | 156 | } |
| 143 | 157 | |
| 144 | 158 | public function getApiKey($mode = 'current') |