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.

Maintainers

Package info

github.com/marshmallow-packages/payable

Homepage

pkg:composer/marshmallow/payable

Statistics

Installs: 7 764

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 1


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.