How to send passthrough using laravel cashier (paddle) and how to receive and store that passthrough after payment succeeded?

  laravel, laravel-7

Hi there, I’m using laravel 7 and cashier (paddle) package.

I want to send the product id as an array with Laravel cashier (paddle) passthrough and after payment succeeded, I want to store it in the database. But how to send passthrough and how to store that passthrough data after payment succeeded?

Here is myController code:

$id = Auth::id();
$user = User::find($id);
$payLink = $user->charge(12.99, '3D Walpaper');
return view('fontend.pay', ['payLink' => $payLink]);

Here is pay.blade.php page

<x-paddle-checkout :override="$payLink" class="w-full" height="500" />

Here is WebhookController

protected function handlePaymentSucceeded(array $payload)
{

    if ($this->receiptExists($payload['order_id'])) {
        return;
    }

    $customer = $this->findOrCreateCustomer($payload['passthrough']);

    $receipt = $customer->receipts();

    $userid = Auth::id();

    $data = array();
    $data['user_id'] = $userid; 
    $data['customer_name'] = $payload['customer_name']; 
    $data['email'] = $payload['email']; 
    $data['test'] = $payload['passthrough'];
    $data['checkout_id'] = $payload['checkout_id'];
    $data['order_id'] = $payload['order_id'];
    $data['amount'] = $payload['sale_gross'];
    $data['currency'] = $payload['currency'];
    $data['quantity'] = $payload['quantity'];
    $data['receipt_url'] = $payload['receipt_url'];
    $data['paid_at'] = Carbon::createFromFormat('Y-m-d H:i:s', $payload['event_time'], 'UTC');
    $data['fee'] = $payload['fee'];
    Receipt::create($data);


    PaymentSucceeded::dispatch($customer, $receipt, $payload);
}

Here, $data['test'] = $payload['passthrough']; does not work.

Source: Laravel

Leave a Reply