maksa988/laravel-wayforpay 问题修复 & 功能扩展

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

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

maksa988/laravel-wayforpay

Composer 安装命令:

composer require maksa988/laravel-wayforpay

包简介

WayForPay payments for Laravel

README 文档

README

Latest Stable Version StyleCI CodeFactor Total Downloads License

Accept payments via WayForPay (wayforpay.com) using this Laravel framework package (Laravel).

  • receive payments, adding just the two callbacks

Laravel >= 5.5.*, PHP >= 7.2

Installation

Require this package with composer.

composer require "maksa988/laravel-wayforpay"

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

Maksa988\WayForPay\WayForPayServiceProvider::class,

Add the WayForPay facade to your facades array:

'WayForPay' => Maksa988\WayForPay\Facades\WayForPay::class,

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="Maksa988\WayForPay\WayForPayServiceProvider"

Configuration

Once you have published the configuration files, please edit the config file in config/wayforpay.php.

  • Create an account and merchant on wayforpay.com
  • Add your project, copy the merchantAccount, merchantAccount, merchantSecretKey params and paste into config/wayforpay.php
  • After the configuration has been published, edit config/wayforpay.php

Usage

This package using official WayForPay SDK for PHP. You can find a full description and content of the classes used by this package in the official SDK repository - wayforpay/php-sdk

1. Purchase

Purchase request is used to effect payment with client on the protected wayforpay site.

Official documentation - https://wiki.wayforpay.com/en/view/852102

The method purchase() allows you to prepare data for a widget or form. And also you can get an array with data to build your form.

$order_id = time(); // Payment`s order ID
$amount = 100; // Payment`s amount

$client = new \Maksa988\WayForPay\Domain\Client('John', 'Doe', 'johndoe@gmail.com');

$products = new \Maksa988\WayForPay\Collection\ProductCollection([
    new \WayForPay\SDK\Domain\Product('iPhone 12', 10, 1),
]);

//

$data = WayForPay::purchase($order_id, $amount, $client, $products)->getData(); // Array of data for using to create your own form.
$form = WayForPay::purchase($order_id, $amount, $client, $products)->getAsString($submitText = 'Pay', $buttonClass = 'btn btn-primary'); // Get html form as string

You can get JS code for widget (https://wiki.wayforpay.com/en/view/852091) using getWidget method after call purchase method.

$widget = WayForPay::purchase($order_id, $amount, $client, $products)->getWidget($callbackJsFunction = null, $buttonText = 'Pay', $buttonClass = 'btn btn-primary'); // Get html form as string

2. Charge

Charge request is used for quick payment making in one action. It is performed within the limits of single-staged pattern.

The result of request processing is the withdrawal of monetary assets from client’s card.

Official documentation - https://wiki.wayforpay.com/en/view/852194

The method charge() allows you to send request for charge operation and get object of response.

$card = new \Maksa988\WayForPay\Domain\Card('5276999765600381', '05', '2021', '237', 'JOHN DOU');
$cardToken = new \Maksa988\WayForPay\Domain\Card('1aa11aaa-1111-11aa-a1a1-0000a00a00aa');

You can use \Maksa988\WayForPay\Domain\Card::class instead of WayForPay\SDK\Domain\Card and or WayForPay\SDK\Domain\CardToken. This class simplify input card and card token using one class. When you put only first argument, this card defined as card-token. If you are put all arguments, this be defined as bank card.

$response = WayForPay::charge($order_id, $amount, $client, $products, $card);
$response = WayForPay::charge($order_id, $amount, $client, $products, $cardToken);

echo "Status: ". $response->getTransaction()->getStatus();

3. Check Status

Check Status request is used for checking of payment status on orderReference.

Official documentation - https://wiki.wayforpay.com/en/view/852117

The method check() allows you to send request for check status of your order using order id.

$order = WayForPay::check($order_id)->getOrder();

echo "Status: ". $order->getStatus();

4. Refund

Refund request is to be used for making of assets refund or cancellation of payment.

Official documentation - https://wiki.wayforpay.com/en/view/852115

The method refund() allows you to send request for refund of payment.

WayForPay::refund($order_id, $amount, $currency, $comment)->getTransactionStatus();

5. Create invoice

The present API allows to issue invoices to the clients for payment for goods/services.

Official documentation - https://wiki.wayforpay.com/en/view/608996852

The method createInvoice() allows you to create invoice.

$invoice = WayForpay::createInvoice($order_id, $amount, $client, $products);

$url = $invoice->getInvoiceUrl();
$qrCode = $invoice->getQrCode();

6. Complete 3DS

In case of merchantTransactionSecureTtype= 3DS, there is initially performed the checking of the card for participation in 3d secure program. If the card supports 3D Secure verification the system Wayforpay will return the parameters for authentication of the client. With these parameters the merchant has to transfer the client to url of issuer for authentication. The time during which the session for verification is active - 10 minutes. If within 10 minutes COMPLETE_3DS will not be obtained the system will cancel transaction as unsuccessful.

$response = WayForPay::complete3ds($authTicket, $d3Md, $d3Pares);

$response->getTransaction();

7. Handle payment

You can use handle payment process using service url at WayForPay. And using controller at Laravel with this package you can handle payment.

For handle request from wayforpay you should create controller and action. In the action you should use method handleServiceUrl().

In the first argument you should put array of request data or Arrayble class. In the second argument you should put Closure what be called when payment is success, and this function will be passed two parameters: Transaction object and Closure using for create success response.

// Controller action

public function handle(Request $request)
{
    return WayForPay::handleServiceUrl($request, function (\WayForPay\SDK\Domain\Transaction $transaction, $success) {
        if($transaction->getReason()->isOK()) {

            // Payment confirmation process and etc...

            return $success();
        }

        return "Error: ". $transaction->getReason()->getMessage();
    });
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please send me an email at maksa988ua@gmail.com instead of using the issue tracker.

Credits

License

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

maksa988/laravel-wayforpay 适用场景与选型建议

maksa988/laravel-wayforpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.88k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2019 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 maksa988/laravel-wayforpay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 maksa988/laravel-wayforpay 我们能提供哪些服务?
定制开发 / 二次开发

基于 maksa988/laravel-wayforpay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-25