Creating SumUp payment links with PHP SDK: Best practices?

I’m struggling to generate a payment link for invoices using the SumUp PHP SDK. Here’s what I’ve tried:

$sumup = new \PaymentGateway\Gateway([
    'client_id' => 'YOUR_ID',
    'client_secret' => 'YOUR_SECRET',
    'auth_type' => 'oauth',
]);

$paymentService = $sumup->getPaymentService();
$total = $bill->total;
$currencyCode = $bill->currency;
$reference = $bill->id;
$recipientEmail = $bill->customer_email;
$memo = $bill->notes;

$paymentResponse = $paymentService->initiate($total, $currencyCode, $reference, $recipientEmail, $memo);
$paymentId = $paymentResponse->getContent()->transaction_id;

The response doesn’t include a payment URL. I’ve tried creating one manually:

$paymentUrl = 'https://example.com/pay?ref=' . $reference . '&id=' . $paymentId;

I’ve set up a basic checkout page with the SumUp Card SDK, but I’m unsure how to handle the payment data securely.

How can I properly generate and use a SumUp payment link with the PHP SDK? Any tips on integrating the payment widget safely?

yo ethan, i’ve been there too. sumup can be tricky. have u tried the getCheckoutUrl() method after initiating the payment? something like:

$paymentUrl = $paymentResponse->getContent()->getCheckoutUrl();

that should give u the direct link. if not, maybe check ur sdk version? older ones might not have it. good luck man!

Hey Ethan_Cosmos, thanks for sharing your code! I’ve been tinkering with SumUp integration myself, and I can totally relate to the confusion. :sweat_smile:

Have you tried using the createCheckout method instead? It might be what you’re looking for to generate that elusive payment link. Something like:

$checkoutResponse = $paymentService->createCheckout($total, $currencyCode, $reference);
$checkoutId = $checkoutResponse->getContent()->id;
$paymentUrl = 'https://sumup.com/checkout/' . $checkoutId;

This should give you a direct SumUp-hosted checkout URL. It’s generally more secure since SumUp handles the payment data on their end.

As for integrating the payment widget, have you looked into SumUp’s JavaScript SDK? It’s pretty nifty for client-side implementations. You could use the PHP SDK to create the checkout, then use the JS SDK to render the payment form.

Just curious - what kind of business are you implementing this for? I’m always interested in hearing about different use cases for payment integrations.

Oh, and don’t forget to implement webhook handling for payment status updates. It’s a lifesaver for keeping your system in sync with SumUp’s!

Let me know if you make any progress or if you need any more help. Happy coding! :rocket: