PHP code example of yves / mopay

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

    

yves / mopay example snippets


return [
    "MOPAY_API_URL" => env("MOPAY_API_URL","http://api.ishema.rw/api/v1/debit"),
    "MOPAY_API_TOKEN" => env("MOPAY_API_TOKEN"),
    "MOPAY_WEBHOOK" => env("MOPAY_WEBHOOK",env("APP_URL")."/mopay/payments/webhook"),
    "APP_NAME_ON_EMAILS"=>  env("APP_NAME", "MOPAY RWANDA"),
    "MAIL_USERNAME"=> env("MAIL_USERNAME"),
    "USE_NEW_EMAIL_IN_CONTEXT_MODEL"=> env("USE_NEW_EMAIL_IN_CONTEXT_MODEL", false),
];


namespace App;

use Illuminate\Database\Eloquent\Model;
use Yves\Mopay\Traits\MopayTrait; // 


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Passenger;

class PassengerPaymentController extends Controller
{

    public function initiatePayment(Passenger $passenger){
        $payment = $passenger->pay(1000);// 1000 is the amount to be requested from this passenger
        if($payment){
            return "payment successfuly initiated";
        }
    }
}



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Passenger;
use Yves\Mopay\Utils\PaymentCart;
use Yves\Mopay\Utils\PaymentForm;
use Yves\Mopay\Utils\PaymentFormItem;
use Yves\Mopay\Utils\PaymentProductCart;

class PassengerPaymentController extends Controller
{

    // show user a form to fill in phone number
    public function showPaymentForm(Request $request){

        //initialize payment form
        $paymentForm = new PaymentForm();

        // adding items
        $paymentForm->addItem(new PaymentFormItem(PaymentFormItem::AMOUNT,"1000"));
        $paymentForm->addItem(new PaymentFormItem(PaymentFormItem::CURRENCY,"Rwf"));
        $paymentForm->addItem(new PaymentFormItem(PaymentFormItem::MSISDN,"250783588655",false));
        $paymentForm->addItem(new PaymentFormItem(PaymentFormItem::CLIENT_NAME,"Mukunzi Joshua"));
        $paymentForm->addItem(new PaymentFormItem(PaymentFormItem::EMAIL,"[email protected]"));

        $paymentCart = new PaymentCart();// if you wish to show cart on the sibar if template  view
        $paymentCart->addProduct(new PaymentProductCart("Ticket",1000));// adding product to cart
        $paymentForm->setCart($paymentCart);// set payment cart

        return $paymentForm->view();// this will return view for the payment
    }

}

bash
$ php artisan mopay:install
bash
$ php artisan migrate
bash 
$ php artisan queue:work