marshmallow/payable 问题修复 & 功能扩展

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

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

marshmallow/payable

Composer 安装命令:

composer require marshmallow/payable

包简介

This package will make it possible to accept payments on all our laravel resources. This was orignaly build for our e-commerce package but can be used on anything.

README 文档

README

alt text

Marshmallow Payable

Latest Version on Packagist Total Downloads PHP Syntax Checker

This package will make it possible to accept payments on all our laravel resources. This was orignaly build for our e-commerce package but can be used on anything.

It ships integrations for Mollie, MultiSafepay, Stripe and Buckaroo, a set of payment models and Laravel Nova resources, payment status events, and a callback/webhook handler.

Requirements

  • PHP ^8.2
  • Laravel (provider auto-discovered via package discovery)

Installation

Composer

You can install the package via composer:

composer require marshmallow/payable

The service provider is auto-discovered. Migrations are loaded automatically from the package.

Publish the config

php artisan vendor:publish --provider="Marshmallow\Payable\PayableServiceProvider"

This publishes config/payable.php.

Publish Nova Resources

php artisan marshmallow:resource Payment Payable
php artisan marshmallow:resource PaymentProvider Payable
php artisan marshmallow:resource PaymentType Payable

Configuration

After publishing you can tweak config/payable.php. The most relevant keys:

Key Default Description
test_payments env('PAYABLE_TEST_PAYMENTS', false) Run payments in test mode.
use_order_payments false Send full order/item information to the payment provider (requires the PayableWithItems trait).
shared_with_expose env('SHARED_WITH_EXPOSE', false) Set when sharing the app through Expose so callback/webhook URLs resolve correctly.
mollie.capture_mode env('PAYABLE_MOLLIE_CAPTURE_MODE') Set to manual for the authorize → capture flow used by pay-later methods (klarna, billie, in3, riverty). Leave null for immediate capture.
routes.* payment.open, payment.paid, ... Named routes a payment status redirects to (payment_open, payment_paid, payment_failed, payment_canceled, payment_expired, payment_unknown).
locale env('CASHIER_CURRENCY_LOCALE', 'nl_NL') Currency locale.
locale_iso_639 env('CASHIER_CURRENCY_LOCALE_ISO_639', 'nl') ISO 639 language code.
models.* Package models Override the payment, payment_provider, payment_type, payment_webhook, payment_status and user models.
nova.resources.* Package Nova resources Override the Nova resources used for payment, payment_provider and payment_type.
actions.prepare_callback PrepareForCallback::class Action invoked when preparing a payment callback.
stripe.* env-driven Stripe key, secret, webhook secret and the subscribed Stripe event types.
multisafepay.key env('MULTI_SAFE_PAY_KEY') MultiSafepay API key.
buckaroo.* env-driven Buckaroo website_key and secret.

Environment variables

MOLLIE_KEY="test_*****"
MULTI_SAFE_PAY_KEY="*****"
PAYABLE_TEST_PAYMENTS=true

Usage

Prepare your models

Add the Payable trait to the model that should support payments and implement the required abstract methods:

use Marshmallow\Payable\Traits\Payable;

class Order extends Model
{
    use Payable;

    public function getTotalAmount(): int
    {
        return $this->total_in_cents;
    }

    public function getPayableDescription(): string
    {
        return "Order #{$this->id}";
    }

    public function getCustomerName(): ?string
    {
        return $this->customer?->name;
    }

    public function getCustomerEmail(): ?string
    {
        return $this->customer?->email;
    }

    public function getCustomer(): ?\Illuminate\Database\Eloquent\Model
    {
        return $this->customer;
    }
}

Start a payment

use Marshmallow\Payable\Models\PaymentType;

$paymentType = PaymentType::first();

$order->startPayment($paymentType);

// Recurring payment
$order->startRecurringPayment($paymentType);

The payments related to a model are available through the payments() morph relation.

Use order information

First let the payable package know we want to sent order information to the payment provider.

return [
    'use_order_payments' => true,
]

Add the trait PayableWithItems to your Payable model.

Implements the following methods on your Payable model.

getBillingOrganizationName(),
getBillingTitle(),
getBillingGivenName(), //required
getBillingFamilyName(), //required
getBillingEmailaddress(), //required
getBillingPhonenumber(),
getBillingStreetAndNumber(), //required
getBillingStreetAdditional(),
getBillingPostalCode(),
getBillingCity(), //required
getBillingRegion(),
getBillingCountry(), //required

Events

The package dispatches the following events as a payment moves through its lifecycle:

PaymentStatusOpen::class
PaymentStatusPaid::class
PaymentStatusFailed::class
PaymentStatusCanceled::class
PaymentStatusExpired::class
PaymentStatusRefunded::class
PaymentStatusUnknown::class
ExternalCustomerModified::class

Providers

Multisafe pay

  • Simple checkout
  • Complex checkout

Mollie

  • Simple checkout
  • Complex checkout

Tests

Test mollie simple checkout

\Marshmallow\Payable\Facades\PayableTest::mollie($test = false, $api_key = 'live_xxxx');

Changelog

Please see CHANGELOG for more information what has changed recently.

Upgrading

Please see UPGRADE for details on upgrading between versions.

Security

If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.

Credits

License

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

marshmallow/payable 适用场景与选型建议

marshmallow/payable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.76k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 marshmallow/payable 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-02