webcraft/lunar-mollie
Composer 安装命令:
composer create-project webcraft/lunar-mollie
包简介
Mollie payment driver for Lunar.
关键字:
README 文档
README
Lunar is a leading package that brings e-commerce functionality to Laravel.
Mollie is a payment provider that offers support for a diverse range of payment methods, such as: Apple Pay, Bancontact, Bank Transfer, Belfius, Credit Card, Direct Debit, EPS, Gift Card, Giropay, iDEAL, KBC, MyBank, PayPal, Paysafecard, Przelewy24 and Sofort.
This addon provides an implementation of Lunar's AbstractPayment interface for Mollie, and a payment component to be used in your storefront. It is built using Laravel Livewire and Tailwind.
Requirements
- Lunar >=
0.4 - A Mollie account
- Laravel Livewire (if using frontend components)
Installation
Require the composer package
composer require webcraft/lunar-mollie
Publish the configuration
This will publish the configuration under config/lunar/mollie.php.
php artisan vendor:publish --tag=lunar.mollie.config
Publish the views (optional)
Lunar Mollie comes with a helper component for you to use on your checkout, if you intend to edit the views it provides, you can publish them.
php artisan vendor:publish --tag=lunar.mollie.components
Publish the translations (optional)
The checkout component uses translations for the buttons, payment methods, etc. If you want to edit these, you can publish them.
php artisan vendor:publish --tag=lunar.mollie.translations
Enable the driver
Set the driver in config/lunar/payments.php
<?php return [ // ... 'types' => [ 'mollie' => [ 'driver' => 'mollie', ], ], ];
Add your Mollie credentials and other config
Take a look at the configuration in config/mollie.php. Where approriate, edit or set the environment variables in your .env file. At least the keys will need to be set.
MOLLIE_LIVE_KEY= MOLLIE_TEST_KEY=
Keys can be found in your Mollie account: https://my.mollie.com/dashboard/developers/api-keys
You can use the MOLLIE_TEST_MODE environment variable to switch between live and test mode.
Storefront Usage
This addon provides a payment component to be used in your storefront. It is built using Laravel Livewire and Tailwind. Make sure these dependencies are installed and configured before continuing.
Add the payment component
Wherever you want the payment form to appear, add this component:
@livewire('mollie.payment', [ 'cart' => $cart, ])
If you are using Lunar's Livewire Starter Kit, you can add this code to the payment.blade.php view, e.g.:
<div class="bg-white border border-gray-100 rounded-xl"> <div class="flex items-center h-16 px-6 border-b border-gray-100"> <h3 class="text-lg font-medium"> Payment </h3> </div> @if ($currentStep >= $step) <div class="p-6 space-y-4"> @livewire('mollie.payment', [ 'cart' => $cart, ]) </div> @endif </div>
By default, the component will just show a Proceed to payment button, redirecting the user to Mollie's hosted payment method selection screen.
If you want the available payment methods to be shown straight from your checkout form, go to config/lunar/mollie.php, set specify_payment_methods to true and uncomment all your available payment methods in payment_methods.
Don't forget these payment methods will need to be enabled in your Mollie account as well.
[
//...
'specify_payment_methods' => true,
'payment_methods' => [
'bancontact',
'creditcard',
'ideal',
'paypal',
],
]
Webhooks
Mollie will send a webhook to your application after every payment attempt (whether successful or not). The route and logic for handling this webhook is already implemented.
If you prefer to write your own logic however, you can create a named route for this yourself, and change the webhook_route config value to the name of your route.
Implement the redirect routes
After a payment attempt, Mollie will redirect the user back to your application. By default, the MollieRedirectController will handle this redirect and redirect the user to the checkout success or failure pages.
If you want to implement your own logic, you can create a named route for this yourself, and change the redirect_route config value to the name of your route.
While the MollieRedirectController is already implemented by the package, this is just a pass-through controller that will redirect the user to the checkout success or failure pages.
These status pages are not implemented by the package, since they probably are specific to your theme. There are 4 statuses that need a page: paid, canceled, open and failed. You need to create named routes for these yourself, named checkout-success.view, checkout-canceled.view, checkout-open.view and checkout-failure.view respectively. You can change these names in the config if you want to.
[
//...
'payment_paid_route' => 'checkout-success.view',
'payment_canceled_route' => 'checkout-canceled.view',
'payment_open_route' => 'checkout-open.view',
'payment_failed_route' => 'checkout-failure.view',
]
Here is an example of how a component for the checkout success page could look like:
//app/Http/Livewire/CheckoutSuccessPage.php <?php namespace App\Http\Livewire; use Livewire\Component; use Lunar\Facades\CartSession; use Lunar\Models\Cart; use Lunar\Models\Order; class CheckoutSuccessPage extends Component { public ?Cart $cart; public Order $order; public function mount() { $this->cart = CartSession::current(); if (! $this->cart || ! $this->cart->completedOrder) { $this->redirect('/'); return; } $this->order = $this->cart->completedOrder; CartSession::forget(); } public function render() { return view('livewire.checkout-success-page'); } }
//resources/views/livewire/checkout-success-page.blade.php <section class="bg-white"> <div class="max-w-screen-xl px-4 py-32 mx-auto sm:px-6 lg:px-8 lg:py-48"> <div class="max-w-xl mx-auto text-center"> <h1 class="mt-8 text-3xl font-extrabold sm:text-5xl"> <span class="block mt-1 text-blue-500"> Thank you for your order </span> </h1> <p class="mt-4 font-medium sm:text-lg"> Your order reference number is <strong> {{ $order->reference }} </strong> </p> <a class="inline-block px-8 py-3 mt-8 text-sm font-medium text-center text-white bg-blue-600 rounded-lg hover:ring-1 hover:ring-blue-600" href="{{ url('/') }}"> Back Home </a> </div> </div> </section>
//routes/web.php Route::get('checkout/success', \App\Http\Livewire\CheckoutSuccessPage::class)->name('checkout-success.view');
You can do something similar for the other status pages.
Testing
composer test
Contributing
Contributions are welcome, if you are thinking of adding a feature, please submit an issue first.
About Webcraft
Webcraft is the company of Michiel Loncke, a freelance web developer from Belgium, specialized in building custom web applications and e-commerce solutions using Laravel and Lunar. If you need help with your project, feel free to get in touch.
webcraft/lunar-mollie 适用场景与选型建议
webcraft/lunar-mollie 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 265 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「shop」 「ecommerce」 「cart」 「store」 「paypal」 「headless」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webcraft/lunar-mollie 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webcraft/lunar-mollie 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webcraft/lunar-mollie 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nevogate Payment Gateway SDK
Laravel 11 and above Shopping cart
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
Dealing with payments through the Egyptian payment gateway PayMob
Submodule for SilverShop which allows you to compare products in a table.
Product catalog for your Symfony2 applications.
统计信息
- 总下载量: 265
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-14