Creating a SumUp payment link with PHP SDK: What's the proper method?

I’m trying to set up a payment system using the SumUp PHP SDK. I’ve got the basic code working, but I’m stuck on getting the actual payment link. Here’s what I’ve done so far:

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

$paymentService = $sumup->getPaymentService();
$total = $bill->total;
$moneyType = $bill->moneyType;
$billId = $bill->id;
$customerEmail = $bill->customerEmail;
$details = $bill->details;

$paymentResponse = $paymentService->initiate($total, $moneyType, $billId, $customerEmail, $details);
$paymentId = $paymentResponse->getResponse()->id;

The problem is, I can’t find the payment URL in the response. I tried making my own like this:

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

I’ve set up a basic frontend with the SumUp Card SDK, but I’m not sure how to handle the card info or where it’s sent. How can I properly generate a payment link and process the payment using the SumUp SDK and their payment widget? Any help would be great!

From my experience with the SumUp SDK, you’re close but missing a crucial step. After initiating the payment, you need to create a checkout session. Try this approach:

$checkoutSession = $paymentService->createCheckoutSession([
    'payment_id' => $paymentId,
    'return_url' => 'https://your-success-url.com',
    'cancel_url' => 'https://your-cancel-url.com'
]);

$paymentUrl = $checkoutSession->getCheckoutUrl();

This should give you a valid payment URL. Remember to handle the webhook for payment confirmation on your server side. The SumUp widget will handle the card info securely, so you don’t need to worry about that part.

hey dashingdog, looks like ur on the right track! the sumup sdk can be tricky. have u tried using the checkout() method instead of initiate()? it should return a checkout ID that u can use to create the payment URL. something like:

$checkoutResponse = $paymentService->checkout($total, $moneyType, $billId);
$checkoutId = $checkoutResponse->getCheckoutId();
$paymentUrl = ‘https://pay.sumup.com/’ . $checkoutId;

hope this helps!

Hey there DashingDog! :wave: I’ve been tinkering with SumUp recently too, and I totally get your frustration. Have you considered using the Checkout API instead of the Payment API? It’s a bit simpler to work with.

Here’s a little snippet that might help:

$checkout = $sumup->getCheckoutService();
$checkoutResponse = $checkout->create([
    'amount' => $total,
    'currency' => $moneyType,
    'merchant_code' => 'YOUR_MERCHANT_CODE',
    'description' => $details,
    'pay_to_email' => $customerEmail,
    'redirect_url' => 'https://your-success-url.com'
]);

$paymentUrl = $checkoutResponse->getCheckoutUrl();

This should give you a direct payment link that you can send to your customer. No need to mess with the Card SDK on the frontend - SumUp handles all that for you!

What do you think? Have you tried this approach? I’m curious to hear how it goes for you!