danialpanah/webpay 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danialpanah/webpay

Composer 安装命令:

composer require danialpanah/webpay

包简介

Laravel Package for Processing Online Payments Through Webpay Payment Gateway

README 文档

README

Build Status Latest Release on Packagist Software License

Introduction

Laravel package for connecting and accept payments via Webpay payment gateway in your Laravel application.

Installation

  • Use following command to install:
composer require danialpanah/webpay

This package supports Laravel auto-discovery feature. If you are using Laravel 5.5 or greater no need to do any further actions, otherwise follow below steps.

  • Add the service provider to your providers[] array in config/app.php in your laravel application:
DanialPanah\Webpay\WebpayServiceProvider::class
  • For using Laravel Facade add the alias to your aliases[] array in config/app.php in Laravel:
'Webpay': DanialPanah\Webpay\Facades\Webpay::class

Configuration

  • After installation, you need to add your Webpay api settings. You can update config/webpay.php published file or in you Laravel .env file.

  • Run the following command to publish the configuration file:

php artisan vendor:publish --provider "DanialPanah\Webpay\WebpayServiceProvider"
  • config/webpay.php
return [
    'api_key' => env('WEBPAY_API_KEY', ''),
    'callback_url' => env('WEBPAY_CALLBACK_URL', '')
];
  • Add this to .env.example and .env files:
#Webpay API key and Settings

#your webpay api key e.g "webpay:2bbc6c62-4fe..."
WEBPAY_API_KEY=

#address of rediricting after payment e.g "/payment/test"
WEBPAY_CALLBACK_URL=

Usage

Following are some approaches which you can have for initiate a payment through Webpay package:

  • Initiate Payment and Receive the Payment URL:
// Importing the class namespaces before using it
use DanialPanah\WebPay\Webpay;

$samplePayment = [
   'amount' => 10000,  //required
   'reference_number' => '#####',  //required - invoice number(unique)
   'payer_mobile' => '',  //optional - payer mobile number for save/load cards in gateway
   'cards' => '',  //optional - allowed cards for perform payment
];

$webPay = new Webpay();
$paymentUrl = $webPay->sendPayment($samplePayment);
  • Using Facades (Initiate Payment):
use DanialPanah\WebPay\Facades\Webpay;

$paymentUrl = Webpay::sendPayment($samplePayment);
  • Verify Payment:
$paymentDetails = [
   'amount' => 10000,  //required
   'reference_number' => '#####'  //required - invoice number
];

$webPay = new Webpay();
$response = $webPay->verifyPayment($paymentDetails);
  • Using Facades (Verify Payment):
use DanialPanah\WebPay\Facades\Webpay;

$response = Webpay::verifyPayment($paymentDetails);
  • Sample Response of Verify Successful Payment:
array: [
  "ok" => true
  "result" => {
      "state": "paid"
      "total": 10000
      "wage": 1500
      "gateway": "sep"
      "terminal": "11423087"
      "pay_ref": "KmsctypmKSs0WfEB01H3ROJPLN2ZQrauExLR90nnXk"
      "pay_trace": "228945"
      "pay_pan": "610422******8585"
      "pay_cid": "4470D3E90AA5Z3FB7B21B3348D34EE25EC331915BCQP68BC4D0D1C0678548B8D"
      "pay_time": "2020-04-02T17:47:14.391164Z"
  }
]
  • Laravel Sample Controller:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DanialPanah\WebPay\Facades\Webpay;

class PaymentController extends Controller
{
    /**
     * @return RedirectResponse|Redirector
     * @throws WebpayException
     */    
     public function pay()
    {
        $userTrustedCards = ['6219196262191962', '6104046161040461'];

        $samplePayment = [
           'amount' => 10000,
           'reference_number' => '999999',
           'payer_mobile' => '09121111111',
           'cards' => $userTrustedCards,
        ];

        $paymentUrl = Webpay::sendPayment($samplePayment);

        return redirect($paymentUrl);
    }


    /**
     * @param Request $request
     * @throws VerifyException
     */
    public function verify(Request $request)
    {
        $paymentDetails = [
            'amount' => 10000,
            'reference_number' => '999999',
        ];

        $response = Webpay::verifyPayment($paymentDetails);

        if(!$reponse['ok'] === true) {
            //Transactions was not successful
        }

        //Do something for successful transactoin

    }
}

Support & Security

This package supports Laravel 5.1 or greater, 6.x and 7.x with PHP 7.2 and above.

  • In case of discovering any issues, please create one on the Issues section.
  • For contribution, fork this repo and implements your code then create a PR.

License

This repository is an open-source software under the MIT license.

统计信息

  • 总下载量: 80
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固