PHP code example of maksa988 / laravel-wayforpay

1. Go to this page and download the library: Download maksa988/laravel-wayforpay 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/ */

    

maksa988 / laravel-wayforpay example snippets


Maksa988\WayForPay\WayForPayServiceProvider::class,

'WayForPay' => Maksa988\WayForPay\Facades\WayForPay::class,

$order_id = time(); // Payment`s order ID
$amount = 100; // Payment`s amount

$client = new \Maksa988\WayForPay\Domain\Client('John', 'Doe', '[email protected]');

$products = new \Maksa988\WayForPay\Collection\ProductCollection([
    new \WayForPay\SDK\Domain\Product('iPhone 12', 10, 1),
]);

//

$data = WayForPay::purchase($order_id, $amount, $client, $products)->getData(); // Array of data for using to create your own form.
$form = WayForPay::purchase($order_id, $amount, $client, $products)->getAsString($submitText = 'Pay', $buttonClass = 'btn btn-primary'); // Get html form as string

$widget = WayForPay::purchase($order_id, $amount, $client, $products)->getWidget($callbackJsFunction = null, $buttonText = 'Pay', $buttonClass = 'btn btn-primary'); // Get html form as string

$card = new \Maksa988\WayForPay\Domain\Card('5276999765600381', '05', '2021', '237', 'JOHN DOU');
$cardToken = new \Maksa988\WayForPay\Domain\Card('1aa11aaa-1111-11aa-a1a1-0000a00a00aa');

$response = WayForPay::charge($order_id, $amount, $client, $products, $card);
$response = WayForPay::charge($order_id, $amount, $client, $products, $cardToken);

echo "Status: ". $response->getTransaction()->getStatus();

$order = WayForPay::check($order_id)->getOrder();

echo "Status: ". $order->getStatus();

WayForPay::refund($order_id, $amount, $currency, $comment)->getTransactionStatus();

$invoice = WayForpay::createInvoice($order_id, $amount, $client, $products);

$url = $invoice->getInvoiceUrl();
$qrCode = $invoice->getQrCode();

$response = WayForPay::complete3ds($authTicket, $d3Md, $d3Pares);

$response->getTransaction();

// Controller action

public function handle(Request $request)
{
    return WayForPay::handleServiceUrl($request, function (\WayForPay\SDK\Domain\Transaction $transaction, $success) {
        if($transaction->getReason()->isOK()) {

            // Payment confirmation process and etc...

            return $success();
        }

        return "Error: ". $transaction->getReason()->getMessage();
    });
}
 bash
php artisan vendor:publish --provider="Maksa988\WayForPay\WayForPayServiceProvider"