GithubHelp home page GithubHelp logo

artisanpay / artisanpay-laravel Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 181 KB

Laravel bridge for artisanpay

Home Page: https://artisanpay.com

License: MIT License

PHP 100.00%
orangemoney mtnmobilemoney laravel cameroon artisanpay

artisanpay-laravel's Introduction

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 [email protected] instead of using the issue tracker.

Credits

License

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

artisanpay-laravel's People

Contributors

genl avatar gildastema avatar

Stargazers

 avatar  avatar

Watchers

 avatar

artisanpay-laravel's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.