New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

artisanpay/artisanpay-laravel

Laravel to make payment in laravel
1,951 2
Install
composer require artisanpay/artisanpay-laravel
Latest Version:0.4.8
PHP:^7.4|^8.0|^8.1
Laravel:7 · 8 · 9
License:MIT
Last Updated:Apr 21, 2022
Links: GitHub  ·  Packagist
Maintainer: Gildas Tema

Laravel bridge for ArtisanPay

Latest Version on Packagist Total Downloads GitHub Actions

Installation

You can install the package via composer:

composer require artisanpay/artisanpay-laravel

Install package

php artisan artisanpay:install 

Add artisanpay api token in config file in .env

ARTISANPAY_TOKEN=xxxxxxxxxxxxxxxxxx

Generate Job to handle payment

php artisan make:job ArtisanpayHookHandleJob

Add Job to config file in dispatcher section


<?php

return [
    /**
     * -------------------------------------------
     *  Api Token provide buy ArtisanPay
     * -------------------------------------------
     */
    'token' => env('ARTISANPAY_TOKEN'),

    'base_url' => env('ARTISANPAY_BASE_URL', 'https://app.artisanpay.com/api/v1'),

    /**
     * --------------------------------------------
     * A Job to Handler Hook Payment
     * ---------------------------------------------
     */

    'job' => \App\Jobs\ArtisanpayHookChargeJob::class,  // ArtisanWebookHandler::class , 

    /**
     * ----------------------------------------------
     * URL route to handle payment
     * ----------------------------------------------
     * 
     */

    'url_webhook'   => env('ARTISANPAY_WEBHOOK', 'api/artisanpay/hooks'),
    'process_manuelly'  => false // indicate if you to define your own controller and route
];


Usage

Create payment artisanpay support for this version 2 operator

NB: Phone without prefix ( 691131446) OrangeMoney ==> 'om' MTN Mobile Money => 'momo'

$data = $request->validate([
            'phone'     => 'required', // 6911131446, 651881356
            'amount'    => 'required',
            'operator'  => 'required'
        ]);

        // for operator you can use const class Operator 

        try{
            $chargeResponse = ArtisanPay::charge( (new ChargeRequest($request->phone, 
                                            $request->amount, $request->operator , 
                                            "my-internal-id")) );
        }catch(Exception $exception){

        }

    

without Exception


    $chargeResponse =  ArtisanPay::withoutException()->charge(ChargeRequest("691131446", 500, Operator::OM, "my-internal-id"));


Job To handle payment hook

<?php

namespace App\Jobs;

use ChargeHookResponse;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ArtisanpayHookChargeJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private ChargeHookResponse $chargeHookResponse

    /**
     * Create a new job instance.
     * @param  ChargeHookResponse $name
     * @return void
     */
    public function __construct(ChargeHookResponse $chargeHookResponse)
    {
        $this->chargeHookResponse = $chargeHookResponse;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $myInternalId = $this->getRefId();
        $artisanPayId = $this->getId();
        $amount = $this->getAmount();
        $amountCharge = $this->getAmountCharge();
        // etc ...
      if($this->chargeHookResponse->getStatus() === ChargeStatus::SUCCESS){
         $this->proccessSuccess();
      }else{
          $this->proccessFailed();
      }  
    
    }

    private function proccessSuccess()
    {
       
        // make operation in case success
    }

    private function proccessFailed()
    {
        // make operation in case failed
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email artisanpay@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

valorin/random

Random is a simple helper package designed to make it easy to generate a range o...

413,065 233
php
cline/variable-keys

Laravel Blueprint macros for variable primary key and morph types

22,912 0
php
cline/struct

Lean, attribute-driven Laravel data objects with explicit validation and Eloquen...

17,788 0
php
cline/toggl

Advanced feature flag management with strategies, time bombs, and groups

12,171 0
php
cline/sequencer

Sequential migration and operation orchestration for Laravel

11,736 0
php

Version History

Version Released PHP Laravel License
0.4.8 ^7.4|^8.0|^8.1 ^7.0|^8.0|^9.0 MIT
0.4.7 ^7.4|^8.0 ^8.0|^7.0 MIT
0.4.6 ^7.4|^8.0 ^8.0|^7.0 MIT
0.4.5 ^7.4|^8.0 ^8.0|^7.0 MIT
0.4.4 ^7.4|^8.0 ^8.0|^7.0 MIT