PHP code example of artisanpay / artisanpay-laravel

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

    

artisanpay / artisanpay-laravel example snippets





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
];



$data = $request->validate([
            'phone'     => 'ator'  => 'or 

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

        }

    


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





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
    }
}
bash
php artisan artisanpay:install 
bash
php artisan make:job ArtisanpayHookHandleJob