PHP code example of kaoken / veritrans-jp-air-web-laravel

1. Go to this page and download the library: Download kaoken/veritrans-jp-air-web-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/ */

    

kaoken / veritrans-jp-air-web-laravel example snippets


class Kernel extends ConsoleKernel
{
    protected $commands = [
        // 追加
        \Kaoken\VeritransJpAirWeb\Console\MakeVeritransJpAirWebCommand::class,
    ];
}

    'providers' => [
        // 追加
        Kaoken\VeritransJpAirWeb\VeritransJpAirWebServiceProvide::class
    ],
    'aliases' => [
        // 追加
       'WebAir' => Kaoken\VeritransJpAirWeb\Facades\VeritransJpAirWeb::class
    ],
];


return [
    // マーチャントID
    'aw_merchant_id' => env('AW_MERCHANT_ID'),
    // AWへ送信するデータの検証用ハッシュキー
    'aw_merchant_hash_key' => env('AW_MERCHANT_HASH_KEY'),
    // ダミー取引フラグ ダミー取引フラグ 0 = 本番; 1 = テスト
    'aw_dummy_payment_flag' => env('AW_DUMMY_PAYMENT_FLAG', 0),

    // 売り上げフラグ:1:与信・売上、0:与信のみ。指定が無い場合は、0
    'aw_card_capture_flag' => env('AW_CARD_CAPTURE_FLAG', 1),
    // コンビニ決済の支払期限(当日からX日後)
    'aw_cvs_payment_limit' => env('AW_CVS_PAYMENT_LIMIT', 60),

    // 商品情報の商品ID未入力時に設定するダミー値
    'aw_dummy_commodity_id' => env('AW_DUMMY_COMMODITY_ID', 0),
    // 品情報のJAN_CODE未入力時に設定するダミー値
    'aw_dummy_commodity_jan_code' => env('AW_DUMMY_COMMODITY_JAN_CODE', '0'),
    // デフォルト決済方式。01 = クレジットカード、02 = コンビニ
    'aw_settlement_type' => env('AW_SETTLEMENT_TYPE', '01'),

    /**
     * 派生した場合は、クラスを変更すること
     */
    // 決済クラス
    'aw_payment_class' =>  \Kaoken\VeritransJpAirWeb\VeritransJpAirWebPayment::class,
    // 単体の商品クラス
    'aw_commodity_class' => \Kaoken\VeritransJpAirWeb\VeritransJpAirWebCommodity::class,
    // 決済完了通知クラス
    'aw_payment_notification_class' =>  \Kaoken\VeritransJpAirWeb\VeritransJpAirWebPaymentNotification::class,
    // コンビニ入金通知クラス
    'aw_cvs_payment_notification_class' =>  \Kaoken\VeritransJpAirWeb\VeritransJpAirWebCVSPaymentNotification::class,
    // 決済完了通知ジョブクラス
    'aw_payment_notification_job_class' =>  \Kaoken\VeritransJpAirWeb\Jobs\PaymentNotificationJob::class,
    // コンビニ入金通知ジョブクラス
    'aw_cvs_payment_notification_job_class' =>  \Kaoken\VeritransJpAirWeb\Jobs\CVSPaymentReceivedNotificationJob::class,
    // コンビニ決済期日を過ぎたジョブクラス
    'aw_cvs_due_date_has_passed_job_class' =>  \Kaoken\VeritransJpAirWeb\Jobs\CVSDueDateHasPassedJob::class
];

    protected function schedule(Schedule $schedule)
    {
        ...
        $schedule->call(function(){
            AirWeb::scheduleTask()->deleteNoPaymentNotification();
            AirWeb::scheduleTask()->queueCVSDueDateHasPassed();
        })->dailyAt('00:00');
    }

    protected $routeMiddleware = [
        ...
        'access_via_veritrans_jp' => \Kaoken\VeritransJpAirWeb\Middleware\AccessViaVeritransJp::class
    ];



namespace App\Providers;

use Illuminate\Queue\Events\JobFailed;
use Kaoken\VeritransJpAirWeb\Jobs\CVSDueDateHasPassedJob;
use Kaoken\VeritransJpAirWeb\Jobs\CVSPaymentReceivedNotificationJob;
use Kaoken\VeritransJpAirWeb\Jobs\PaymentNotificationJob;
use Illuminate\Support\ServiceProvider;

use Log;
use Queue;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Queue::failing(function (JobFailed $event){
            // Air Web Veritrans Jp
            if( $event->connectionName === 'payment' ){
                $e = $event->exception;
                $a['error']['msg'] = $e->getMessage();
                $a['error']['code'] = $e->getCode();
                $a['error']['file'] = $e->getFile();
                $a['error']['line'] = $e->getLine();
                $a['error']['trace'] = $e->getTrace();

                if( $event->job instanceof CVSDueDateHasPassedJob){
                    $a['obj'] = $event->job->obj;
                    Log::error("Veritrans Jp コンビニ決済で、入金期日が過ぎた",$a);
                }else if( $event->job instanceof CVSPaymentReceivedNotificationJob){
                    $a['item'] = $event->job->items;
                    Log::error("Veritrans Jp コンビニ入金通知",$a);
                }else if( $event->job instanceof PaymentNotificationJob){
                    $a['item'] = $event->job->items;
                    Log::error("Veritrans Jp 決済完了通知",$a);
                }
            }
        });
    }
}


/**
 * Veritans Jp Air Web に関する処理
 * @see https://air.veritrans.co.jp/map/settings/service_settings
 */
namespace App\Http\Controllers;

use Log;
use \Illuminate\Http\Request;
use App\Library\Http\Controllers\Controller;
use Kaoken\VeritransJpAirWeb\CVSPaymentReceivedNotification;
use Kaoken\VeritransJpAirWeb\PaymentNotification;

class AirWebController extends Controller
{
    use PaymentNotification, CVSPaymentReceivedNotification;

    /**
     * 決済完了通知
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function postPaymentNotification(Request $request)
    {
        return $this->paymentNotification($request);
    }


    /**
     * コンビニ入金通知
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function postCVSPaymentReceivedNotification(Request $request)
    {
        return $this->cvsPaymentReceivedNotification($request);
    }


    /**
     * 決済完了後の移動先
     * @param Request $request
     * @param int $threadId スレッドID
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function postFinishPayment(Request $request, $threadId)
    {
//        Log::info('決済完了後');
        return redirect('/');
    }

    /**
     * 未決済時の移動先
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function getUnFinishPayment(Request $request)
    {
        return redirect('/');
    }
    /**
     * 決済エラー時の移動先
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function postErrorPayment(Request $request)
    {
        return redirect('/');
    }
}

Route::group([
        'middleware' => ['access_via_veritrans_jp']
    ]
    function() {
        // 決済完了通知を受信するためのもの
        Route::post('notification/handling','AirWebController@postPaymentNotification' );
        // コンビニ入金通知を受信するためのもの
        Route::post('cvs-payment-received','AirWebController@postCVSPaymentReceivedNotification' );
    }
);
// 正常に支払い手続きが終了した購入者へ表示するURL
Route::post('payment/finish','AirWebController@postFinishPayment' );
// 決済入力画面から「戻る」をクリックした購入者へ表示する
Route::get('payment/unfinish','AirWebController@getUnFinishPayment' );
// 正常に支払い手続きが終了しなかった購入者へ表示する
Route::post('payment/error','AirWebController@postErrorPayment' );
bash
例 php artisan queue:work --queue=payment,default --sleep=3 --tries=3
bash
$ php artisan veritrans-jp:web-air:install
bash
$ php artisan migrate
PaymentEventSubscriber.php 

/**
 * 決済 リスナー
 */
namespace App\Listeners;

use AirWeb;
use Log;
use Carbon\Carbon;
use Kaoken\VeritransJpAirWeb\Events\ CVSDueDateHasPassed;
use Kaoken\VeritransJpAirWeb\Events\CVSPaymentReceivedNotificationEvent;
use Kaoken\VeritransJpAirWeb\Events\PaymentNotificationEvent;

class PaymentEventSubscriber
{
    /**
     * 購読するリスナーの登録
     * @param \Illuminate\Events\Dispatcher $events
     */
    public function subscribe($events)
    {
        // コンビニ入金期日を過ぎた
        $events->listen(
            'Kaoken\VeritransJpAirWeb\Events\CVSDueDateHasPassed',
            'App\Listeners\PaymentEventSubscriber@onCVSDueDateHasPassed'
        );
        // コンビニエンスストア、入金通知
        $events->listen(
            'Kaoken\VeritransJpAirWeb\Events\CVSPaymentReceivedNotificationEvent',
            'App\Listeners\PaymentEventSubscriber@onCVSPaymentReceivedNotification'
        );
        // 決済完了通知
        $events->listen(
            'Kaoken\VeritransJpAirWeb\Events\PaymentNotificationEvent',
            'App\Listeners\PaymentEventSubscriber@onPaymentNotification'
        );
    }

    /**
     * コンビニ入金期日を過ぎた
     * @param CVSDueDateHasPassed $event
     * @see \Kaoken\VeritransJpAirWeb\Jobs\CVSDueDateHasPassedJob::handle()
     * @throws \Exception
     */
    public function onCVSDueDateHasPassed(CVSDueDateHasPassed $event)
    {

    }

    /**
     * コンビニエンスストア、入金通知
     * @param CVSPaymentReceivedNotificationEvent $event
     * @see \Kaoken\VeritransJpAirWeb\Jobs\CVSPaymentReceivedNotificationJob::handle()
     * @throws \Exception 
     * @note 例外後、`failed_jobs`テーブルへ追加される。
     */
    public function onCVSPaymentReceivedNotification(CVSPaymentReceivedNotificationEvent $event)
    {
        $obj = $event->obj;

    }

    /**
     * 決済完了通知
     * @param PaymentNotificationEvent $event
     * @see \Kaoken\VeritransJpAirWeb\Jobs\PaymentNotificationJob::handle()
     * @throws \Exception
     */
    public function onPaymentNotification(PaymentNotificationEvent $event)
    {
        $obj = $event->obj;

    }
}