public function makeStripeCall($method, $url, $body = null)
{
$apiKey = $this->accountGateway->getConfig()->apiKey;
if (!$apiKey) {
return 'No API key set';
}
try {
$options = ['headers' => ['content-type' => 'application/x-www-form-urlencoded'], 'auth' => [$apiKey, '']];
if ($body) {
$options['body'] = $body;
}
$response = (new \GuzzleHttp\Client(['base_uri' => 'https://api.stripe.com/v1/']))->request($method, $url, $options);
return json_decode($response->getBody(), true);
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
$response = $e->getResponse();
$body = json_decode($response->getBody(), true);
if ($body && $body['error'] && $body['error']['type'] == 'invalid_request_error') {
return $body['error']['message'];
}
return $e->getMessage();
}
}