Our HTML/Javascript client sends a request to our PHP proxy Class and method to invoke the communication with the Sumup API.
The Sumup Developer Documentation appears to require three steps:
- Use Curl to obtain an Authorisation Code from the API
- Use that Code with the PHP SDK for the first time to retrieve an Access Token
- Then use that Token with the PHP SDK for the second time to retrieve a Checkout Id.
Finally the Checkout ID is returned to the HTML/Javascript client to be used by the Payment Widget
I have spent many days trying to interpret the Sumup Developer documentation. There are no examples provided and support@sumup is prompt but only interested in answering detailed questions.
This is the first time I have needed to use Stackoverflow for a question for at least 10 years. I hope a colleague has achieved success and can provide some assistance.
$checkoutId = ""; $token = ""; $code = "";
$curl = new Curl\Curl();
$curl->get('https://api.sumup.com/authorize', [
'response_type' => 'code',
// 'client_id' => 'cc_classic_*************',
'client_id' => 'sup_sk_*********************',
'redirect_uri' => 'https://api.*****',
]);
if($curl->isSuccess()) {
// do something with response
$code = $curl->response;
} else {
$code = 'Curl error';
}
// ensure to close the curl connection
$curl->close();
$sumup = new \SumUp\SumUp([
'app_id' => "cc_classic_***********", // required,
'app_secret' => "cc_sk_classic_*******************",
'grant_type' => 'authorization_code',
'code' => $code,
]);
$accessToken = $sumup->getAccessToken();
$token = $accessToken->getValue();
$sumupb = new \SumUp\SumUp([
'app_id' => "cc_classic_*****************", // required,
'app_secret' => "cc_sk_classic_********************",
'code' => $token,
]);
$checkoutService = $sumupb->getCheckoutService();
$checkoutResponse = $checkoutService->create($this->rq->data['amount'], $this->rq->data['currency'], $this->rq->data['id'], $this->mdl['email']);
$checkoutId = $checkoutResponse->getBody()->id;
// pass the $chekoutId to the front-end to be processed