Laravel tutorial: 3 minutes to realize wechat payment access of small program (2) — callback delivery logic

Time:2020-11-11

Continued:Laravel tutorial: 3 minutes to realize wechat payment access of small program (1) — evoking payment

code

Binding callback routes/ api.php

Route::any('/gateway/wxpay/callback', '[email protected]')->name('pay.callback');

Note the addition of the previous article.envKeep the same URL as the route here. :

WECHAT_PAYMENT_NOTIFY_URL=https://www.mysite.com/gateway/wxpay/callback

app/Http/Controllers/PayController.phpAdd callback method

/**
     *Wechat payment callback
     *
     * @return Response
     */
    public function callback(\App\Repositories\BuyRepository $buyRepository)
    {
        return $buyRepository->callback();
    }

app/Repositories/BuyRepository.phpAdd callback logic

public function callback()
    {
        $this->wxpay = app('easywechat.payment');
        return $this->wxpay->handlePaidNotify(
            function ($message, $fail) {
                if ($message['result_code'] === 'FAIL') {
                    logger()->warning('WXPAY_CALLBACK', ['FAIL', $message]);
                    return true;
                } else if ($message['return_code'] === 'SUCCESS') {
                    //Todo: your delivery logic
                    return true;
                }
            }
        );
    }

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress:https://github.com/nino-laiqiu/TiTanI recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]