PHP code example of professionalweb / payment-laravel

1. Go to this page and download the library: Download professionalweb/payment-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

professionalweb / payment-laravel example snippets




public function action(PayService $paymentService) {
    redirect()->to(
        $paymentService->getPaymentLink($order->id,
            $payment->id,
            $payment->amount,
            $payment->currency,
            PayService::PAYMENT_TYPE_CARD
            $successfulPaymentReturnUrl,
            $failedPaymentReturnUrl,
            $description
        );
    );
}



public function responseHandler(PayService $paymentService) {
    if($paymentService->setResponse($this->getRequest()->all())->isSuccess()) {
        $orderId = $paymentService->getOrderId();
        $status = $paymentService->getStatus();
        $amount = $paymentService->getAmount();
        $errorCode = $paymentService->getErrorCode();
        $pan = $paymentService->getPan();
        $paymentDate = $paymentService->getDateTime();
        $transactionId = $paymentService->getTransactionId();
        $provider = $service->getProvider();

        // Update order, payment record, etc...
    } else {
        // something else
    }
}

/**
 * Prepare Receipt
 *
 * @param Order $order
 *
 * @return Receipt
 */
public function prepareReceipt(Order $order)
{
    $receipt = new Receipt($order->user->email);
    /** @var Item $item */
    foreach ($order->items as $item) {
        $receipt->addItem(new ReceiptItem($item->name, $item->qty, $item->price, config('payment.tax')));
    }

    return $receipt;
}

use professionalweb\payment\contracts\ReceiptService;

$receipt = new Receipt($order->user->email);
$receipt->setTransactionId($transactionIdFromPayOnlineResponse);
/** @var Item $item */
foreach ($order->items as $item) {
    $receipt->addItem(new ReceiptItem($item->name, $item->qty, $item->price, config('payment.tax')));
}

app(ReceiptService::class)->sendReceipt(
    $this->prepareReceipt()
);