PHP code example of litvinjuan / laravel-payments

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

    

litvinjuan / laravel-payments example snippets


'providers' => [
    litvinjuan\LaravelPayments\LaravelPaymentsServiceProvider::class,
]



namespace App;

use Illuminate\Database\Eloquent\Model;
use litvinjuan\LaravelPayments\Payments\HasPayment;
use litvinjuan\LaravelPayments\Payments\Payable;
use litvinjuan\LaravelPayments\Payments\Payer;
use litvinjuan\LaravelPayments\Payments\Payment;
use Money\Money;

/**
 * @property int $id
 * @property Money $total
 * @property User $buyer
 * @property Payment $payment
 */
class Order extends Model implements Payable
{
    use HasPayment;

    public function getPayablePrice(): Money
    {
        return $this->total;
    }

    public function getPayableDescription(): string
    {
        return 'This is a dummy bank statement';
    }

    public function payer(): Payer
    {
        return $this->buyer;
    }
}



namespace App;

use Illuminate\Database\Eloquent\Model;
use litvinjuan\LaravelPayments\Payments\CanPay;
use litvinjuan\LaravelPayments\Payments\Payer;
use litvinjuan\LaravelPayments\Payments\Payment;

/**
 * @property int $id
 * @property string $email
 * @property-read Payment[] $payments
 */
class User extends Model implements Payer
{
    use CanPay;

    public function getPayerEmail(): string
    {
        return $this->email;
    }
}


$order = new Order();
$order->total = new Money(2900, 'USD');
$order->save();

$payment = order->createPayment();

$gateway = GatewayFactory::make($payment);

if (! $gateway->supportsPurchase()) {
    throw InvalidRequestException::notSupported();
}

if (! $gateway->supportsRefund()) {
    throw InvalidRequestException::notSupported();
}

// ...
// See full list of calls below

* Authorize             // Authorize an amount on the customer's card
* CompleteAuthorize     // Handle return from off-site authorization  
* Capture               // Capture a previously authorized amount
* Purchase              // Automatically authorize and purchase an amount on the customer's card
* CompletePurchase      // Handle return from off-site authorization
* GetPayment            // Get information about a specific payment
* PaymentNotification   // Process a received payment notification
* Refund                // Refund a previously charged amount to the customer's card
* Void                  // Void a payment
* ValidatePayment       // Validates whether a payment was successful or not
 bash
php artisan vendor:publish --provider="litvinjuan\LaravelPayments\LaravelPaymentsServiceProvider"
 bash
php artisan migrate