承接 litvinjuan/laravel-payments 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

litvinjuan/laravel-payments

Composer 安装命令:

composer require litvinjuan/laravel-payments

包简介

A Payments package for Laravel

README 文档

README

This package provides traits and interfaces that will let you easily create and store payments, as well as provide you with a streamlined interface to interact with payment gateways.

Installation

You can install the package via composer:

composer require litvinjuan/laravel-payments

If you are using a Laravel version below 5.5, you need to add the following to your config/app.php file:

'providers' => [
    litvinjuan\LaravelPayments\LaravelPaymentsServiceProvider::class,
]

Next, you need to publish the config and migration files. Run the following command in your project's root:

php artisan vendor:publish --provider="litvinjuan\LaravelPayments\LaravelPaymentsServiceProvider"

Last, run the migrations so that your payments table is created:

php artisan migrate

Usage

You will have to create a Model that implements the Payable interface and the HasPayment trait. This is the model your users will be paying for (ej. Order, Product).

The Payable interface has 3 methods you'll need to implement yourself: getPayablePrice() should return the total price that should be paid, getPayableDescription() should return the payment description that should be used in the bank statement and for future reference, payer() should return a reference to whoever should make the payment.

Here's an example:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use litvinjuan\LaravelPayments\Payments\HasPayment;
use litvinjuan\LaravelPayments\Payments\Payable;
use litvinjuan\LaravelPayments\Payments\Payer;
use litvinjuan\LaravelPayments\Payments\Payment;
use Money\Money;

/**
 * @property int $id
 * @property Money $total
 * @property User $buyer
 * @property Payment $payment
 */
class Order extends Model implements Payable
{
    use HasPayment;

    public function getPayablePrice(): Money
    {
        return $this->total;
    }

    public function getPayableDescription(): string
    {
        return 'This is a dummy bank statement';
    }

    public function payer(): Payer
    {
        return $this->buyer;
    }
}

You will also need to create a Model that implements the Payer interface and the CanPay trait. This is the model that represents whoever will be paying (tip: this is generally your User model).

The Payer interface has 1 method you'll need to implement yourself: getPayerEmail() should return the payer's email address.

Here's an example:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use litvinjuan\LaravelPayments\Payments\CanPay;
use litvinjuan\LaravelPayments\Payments\Payer;
use litvinjuan\LaravelPayments\Payments\Payment;

/**
 * @property int $id
 * @property string $email
 * @property-read Payment[] $payments
 */
class User extends Model implements Payer
{
    use CanPay;

    public function getPayerEmail(): string
    {
        return $this->email;
    }
}

Whenever you need to make a purchase, create your Payable model as you normally would.

$order = new Order();
$order->total = new Money(2900, 'USD');
$order->save();

Once you have your Payable instance, you can call the createPayment method.

$payment = order->createPayment();

To interact with gateways, you first need to get a Gateway instance:

$gateway = GatewayFactory::make($payment);

This will return a Gateway instance based on the payment's gateway_name attribute.

Then we can check that the gateway supports the call we are trying to make:

if (! $gateway->supportsPurchase()) {
    throw InvalidRequestException::notSupported();
}

if (! $gateway->supportsRefund()) {
    throw InvalidRequestException::notSupported();
}

// ...
// See full list of calls below

The following 10 calls are currently supported:

* Authorize             // Authorize an amount on the customer's card
* CompleteAuthorize     // Handle return from off-site authorization  
* Capture               // Capture a previously authorized amount
* Purchase              // Automatically authorize and purchase an amount on the customer's card
* CompletePurchase      // Handle return from off-site authorization
* GetPayment            // Get information about a specific payment
* PaymentNotification   // Process a received payment notification
* Refund                // Refund a previously charged amount to the customer's card
* Void                  // Void a payment
* ValidatePayment       // Validates whether a payment was successful or not

Note: It is recommended that you use the ValidatePayment call before approving your customer's purchase.

Note: Individual gateways might not support every call, and thus you should always check the corresponding supports() method.

Changelog

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

Security

If you discover any security related issues, please email litvinjuan@gmail.com instead of using the issue tracker.

Credits

Support us

License

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

litvinjuan/laravel-payments 适用场景与选型建议

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

它主要适用于以下技术方向: 「php」 「payments」 「pay」 「laravel」 「argentina」 「pagos」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-06