PHP code example of krisnasw / faspay

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

    

krisnasw / faspay example snippets


'Faspay' => Krisnasw\Faspay\Facades\Faspay::class,
'Payment' => Krisnasw\Faspay\Facades\Payment::class,

// Customer class example. You can apply to any model you want.

use Krisnasw\Faspay\CustomerInterface;

class Customer implements CustomerInterface
{
  public function getFaspayCustomerNumber()
  {
    return 'customer-number';
  }

  public function getFaspayCustomerName()
  {
    return 'customer-name';
  }

  public function getFaspayCustomerEmail()
  {
    return 'customer-email';
  }
  
  public function getFaspayCustomerPhone()
  {
    return 'customer-phone';
  }

  public function getFaspayPreferredCurrency()
  {
    return 'customer-currency';
  }
}

// Item class example. You can apply to any model you want.

use Krisnasw\Faspay\Payable;

class Item implements Payable
{
  public function getPayableName()
  {
    return 'Product Name';
  }

  public function getPayablePrice()
  {
    return 300000;
  }
}

// An example how to use the API.

Route::get('/', function () {

  $customer = new Customer();
  $payable = new Item();

  $payment = Payment::performedBy($customer)
    ->via('web')
    ->payWith('tcash')
    ->addTax(10)
    ->addMiscFee(1000);

  $payment->addItem($payable, 2);

  $response = Faspay::registerPayment($payment);

  return Faspay::redirectToPay($payment);
});

Route::get('/callback-notif', function(\Illuminate\Http\Request $request) {
  return Faspay::notified($request, function(\Krisnasw\Faspay\Notification $notification) {
    return $notification;
  });
});

class TopupBillingProfile implements BillingProfileInterface
{
  public function description()
  {
    return 'Topup Saldo'; 
  }

  public function generate(Payment $payment)
  {
    return str_random(15);
  }
}