定制 necessarylion/opn-payments-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

necessarylion/opn-payments-laravel

最新稳定版本:1.0.3

Composer 安装命令:

composer require necessarylion/opn-payments-laravel

包简介

Laravel package for Opn Payments

README 文档

README

php php

A Laravel package for integrating Opn Payments (formerly Omise) using the omise-php SDK. This package provides a simple way to implement payments in your Laravel project with a ready-made payment form and automatic payment handling.

View Full Documentation

drawing drawing

flow diagram

Installation

  1. Install Package
composer require necessarylion/opn-payments-laravel
  1. Generate vendor
php artisan vendor:publish --provider="OpnPayments\OpnPaymentsServiceProvider" --force
  1. Run Migration
php artisan migrate
  1. Register Event Listener (optional)
  • Register OpnPaymentCompleted class in app/Providers/EventServiceProvider.php
    to handle your order, sending email etc...
public function boot()
{
    ...
    Event::listen(
        \OpnPayments\Events\OpnPaymentCompleted::class,
        [\App\Listeners\OpnPaymentHandler::class, 'handle']
    );
}
  1. Add credentials in .env file
OPN_MODE=test  # test or live
OPN_TEST_PUBLIC_KEY=pkey_***
OPN_TEST_SECRET_KEY=skey_***
OPN_LIVE_PUBLIC_KEY=pkey_***
OPN_LIVE_SECRET_KEY=skey_***
  • Make sure that APP_URL include port if you are running on port
  • Example
APP_URL=http://localhost:8000

Create Charge

Create charge using redirect url function

$payload = new OpnPaymentsRedirectPayload();
$payload->amount = 1000;
$payload->currency = OpnPaymentsCurrency::THAILAND_BAHT;
$payload->cancelUri = 'http://localhost:8000';
$payload->redirectUri = 'http://localhost:8000';
$payload->orderId = Str::uuid();
$payload->locale = OpnPaymentsLocale::ENGLISH;
$payload->paymentMethods = OpnPayments::paymentMethods();

return redirect(OpnPayments::getRedirectUrl($payload)->authorized_uri);
Fields Type Description
amount int Amount to charge
currency string Currency of the amount eg. THB, SGD, RGN. You can use OpnPaymentsCurrency helper class for this field
cancelUri string Url to redirect back if the user cancel payment
redirectUri string Url to redirect back if the payment completed
orderId string Unique order Id.
paymentMethods array Array of payment methods. You can see list of supported methods here
locale string Language, such ash , en, th, ja. You can use OpnPaymentsLocale helper class for this field
metaData array Extra meta data to append.

Product List

If you want to show list of products in payment page, you can do as below.

$payload->metaData = [
    'product' => [
        'image' => 'https://placehold.jp/75767a/ffffff/150x150.png'
        'name' => 'I Phone',
        'quantity' => '1',
        'price' => '320000',
    ]
];

OR

$payload->metaData = [
    'products' => [
        [
            'image' => 'https://placehold.jp/75767a/ffffff/150x150.png'
            'name' => 'I Phone',
            'quantity' => '1',
            'price' => '320000',
        ]
    ]
];

Event Listener

Handle Completed Payment using OpnPaymentHandler Listener

in app/Listeners/OpnPaymentHandler.php, you can check the payment_successful status of payment attempt.
to handle order, sending email etc..

public function handle(OpnPaymentCompleted $event) {
    $attempt = $event->attempt;
    $charge = $event->charge;
    if ($attempt->payment_successful) {
        // handle payment success here
    } else {
        // handle payment failed here
    }
}

Scheduler

Register scheduler for pending charges.

This scheduler will get all pending charge from records withing 24 hours. Then it will fetch status from Opn API and update if success or failed.

In app/Console/Kernel.php inside schedule() function add below line.

$schedule->command('opn-payments-scheduler')->everyFiveMinutes();

Additional Functions

Name Description
OpnPayments::charge() To create/retrieve charge
OpnPayments::account() To retrieve account information
OpnPayments::capability() To retrieve capability data
OpnPayments::card() To create/retrieve card
OpnPayments::token() To create/retrieve token
OpnPayments::refund() To create/retrieve refund
OpnPayments::event() To create/retrieve event
OpnPayments::source() To create/retrieve source
OpnPayments::customer() To create/retrieve customer
OpnPayments::receipt() To create/retrieve receipt
OpnPayments::transfer() To create/retrieve transfer
OpnPayments::balance() To create/retrieve balance

Contribute

Want to contribute? Great! Fork the repo and create PR to us.

Development Process

  • In your Laravel project
  • Create packages folder mkdir packages
  • And clone our package git clone git@github.com:necessarylion/opn-payments-laravel.git
{
    ...
    "repositories": {
        "opn-payments-laravel" : {
            "type": "path",
            "url" : "packages/opn-payments-laravel",
            "options": {
                "symlink": true
            }
        }
    },
}
"require": {
    ...
    "necessarylion/opn-payments-laravel" : "@dev"
},
composer update

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固