DEV Community

oliver-pyon
oliver-pyon

Posted on

How to get payment Link From SumUp using sumup-ecom-php-sdk?

I am looking to get a payment link for our invoice using sumup-ecom-php-sdk. How can I implement my idea?

$sumup = new \SumUp\SumUp([
    'app_id' => '...',
    'app_secret' => '...',
    'grant_type' => 'client_credentials',
]);

$checkoutService = $sumup->getCheckoutService();
$amount =$invoice->amount;
$currency = $invoice->currency;
$checkoutRef = $invoice->number;
$payToEmail = $invoice->recipient;
$description = $invoice->description;

$checkoutResponse = $checkoutService->create($amount, $currency, $checkoutRef, $payToEmail, $description);
$checkoutId = $checkoutResponse->getBody()->id;
Enter fullscreen mode Exit fullscreen mode

How can I get a payment link using $checkoutService? There's no payment link in the response of $checkoutResponse->getBody();

So I created payment link myself using $checkoutId like the following.

$redirectUrl = 'http://127.0.0.1:8000/sumup/checkout?ref='.$checkoutRef.'&token='.$checkoutId
Enter fullscreen mode Exit fullscreen mode

web.php

Route::get('/sumup/checkout', [SumupPayController::class, 'index']);
Enter fullscreen mode Exit fullscreen mode

SumUpController.php

public function index(Request $request)
{
    $invoiceNumber = $request->query('ref');
    $checkoutId = $request->query('token');
    return view('sumup_checkout', compact('invoiceNumber','checkoutId'));
}
Enter fullscreen mode Exit fullscreen mode

sumup_checkout.blade.php

<script src="https://gateway.sumup.com/gateway/ecom/card/v2/sdk.js"></script>
Enter fullscreen mode Exit fullscreen mode
@extends('layout.app_layout_client')
@section('body')
    <div id="sumup-card"></div>
@endsection
@push('post-body-script')
    <script>
        const checkoutId = @json($checkoutId);
        const invoiceNumber = @json($invoiceNumber);
        console.log(checkoutId, invoiceNumber);

        var sumupCard = SumUpCard.mount({
            checkoutId: checkoutId,
            showFooter: true,
            currency: "EUR",
            locale: "de-DE",
            onResponse: function (type, body) {
                switch(type) {
                    case "sent":
                        break;
                    case "invalid":
                        break;
                    case "auth-screen":
                        break;
                    case "error":
                        break;
                    case "success":
                        break;
                    default:
                        break;
                }
            },
        });
    </script>
@endpush
Enter fullscreen mode Exit fullscreen mode

As you can see, I developed front-end page using sumup-card-sdk. But I don't know where the request including card information that I input is sent when I click submit button of sumup-card. So I can't connect to backend. And I want to know how I can get input data including card information from sumup-card.

How can I get payment link using sumup-ecom-php-sdk and payment widget provided by SumUp?

Thanks in advice

Top comments (1)

Collapse
 
zetxek profile image
Adrián Moreno Peña

Hey @oliverpyon mind that the API for SumUp does not have payment links. That's a product that SumUp offers (sumup.com/en-gb/payment-links/), but not via API at this moment.

The docs in developer.sumup.com/docs/online-pa... apply to "online payments" - but you still need to build and host the page where the payment widget would be hosted (developer.sumup.com/docs/online-pa...) -- or building that functionality yourself too.