承接 morningtrain/wp-nets-easy 相关项目开发

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

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

morningtrain/wp-nets-easy

Composer 安装命令:

composer require morningtrain/wp-nets-easy

包简介

Nets Easy SDK for WordPress

README 文档

README

A Morningtrain package to simple handle NETS Easy payments.

Table of Contents

Introduction

Getting Started

To get started install the package as described below in Installation.

To use the tool have a look at Usage

Installation

Install with composer

composer require morningtrain/wp-nets-easy

Dependencies

Usage

Initializing package

Initialize \Morningtrain\WpNetsEasy\NetsEasy with NETS Easy test or live secret key.

\Morningtrain\WpNetsEasy\NetsEasy::init('live-secret-key-abcdefghijklmnopqrstuvwxyz123456789');

Running migrations

This needs to be done before using the package, or after updating the package.
You can run all new migrations like so:

Using wp cli:

wp dbmigrate

Using php:

<?php
    \Morningtrain\WP\Database\Database::migrate();
?>

Create payment

use Morningtrain\WpNetsEasy\Classes\Payment\Payment;
use Morningtrain\WpNetsEasy\Classes\Payment\Customer;
use Morningtrain\WpNetsEasy\Classes\Payment\Address;
use Morningtrain\WpNetsEasy\Classes\Payment\Item;

// Create payment and set payment information and urls
$payment = Payment::create()
    ->setReference($orderId)
    ->setCustomer(
        Customer::create()
            ->setReference($customer->id)
            ->setEmail($customer->email)
            ->setPhone($customer->phone)
            ->setName($customer->firstName, $customer->lastName)
            ->setCompanyName($customer->companyName)
            ->setShippingAddress(
                Address::create()
                    ->setAddressLine1($customer->address1)
                    ->setAddressLine2($customer->address2)
                    ->setPostalCode($customer->zipCode)
                    ->setCity($customer->city())
            )
        )
    ->setTermsUrl(get_post_permalink($termsPageId))
    ->setReturnUrl(Route::route('payment-success', ['token' => $order->token]))
    ->setCancelUrl(Route::route('payment-cancel', ['token' => $order->token]));

// Add items to payments
foreach($order->items as $item) {
    $payment->addItem(
        Item::create($item->sku)
            ->setName($item->name)
            ->setQuantity($item->quantity)
            ->setUnitPriceInclusiveTax($item->price)
    );
}

// Persist payment in NETS Easy
$response = $payment->createRequest();

if(wp_remote_retrieve_response_code($response) !== 201) {
    // Error handling when something was wrong with the payment
    wp_redirect($checkoutUrl);
    exit();
}

// Save payment reference to order
$order->setPaymentId($payment->getPaymentId());

// Redirect to payment page
wp_redirect($payment->getPaymentPageUrl());
exit();

Auto charge payment

If your product allows you to auto charge payment. You can tell Nets Easy to charge the payment automatically before you persist the payment.

$payment->autoCharge()

Handle existing payment

When a payment requrest has been created, the payment reference will be saved to the database.

Get payment

Payment is a model implementet with Eloquent. To get payments you can use all methods from Eloquent (see documentation).

You can use the custom method Payment::getByPaymentId($paymentId);

$payment = Payment::getByPaymentId($order->payment_id);

Terminate payment

To terminate payment, the customer must not have finished checkout. You can use it on the cancel callback to avoid double payments later.

$payment->terminate()

Check if payment is reserved

$payment->isReserved()

Check if payment is charged

$payment->isCharged()

Charge payment

$payment->charge()

NOTE: Partly charges is not implementet yet

Refund payment

NOTE: Refund and partly refund is not implementet yet

Create subscription

NOTE: Subscriptions is not implementet yet

Handle existing subscription

NOTE: Subscriptions is not implementet yet

Handle webhoks

The implementation handle webhooks and sets the payment status automatically.

If you need to do something on a specific webhook, you can do that throug actions and filters.

List of implemented webhooks

Name Descritpion
payment.created A payment has been created.
payment.reservation.created The amount of the payment has been reserved.
payment.reservation.failed A reservation attempt has failed.
payment.checkout.completed The customer has completed the checkout.
payment.charge.created.v2 The customer has successfully been charged, partially or fully.
payment.charge.failed A charge attempt has failed.
payment.refund.initiated.v2 A refund has been initiated.
payment.refund.failed A refund attempt has failed.
payment.refund.completed A refund has successfully been completed.
payment.cancel.created A reservation has been canceled.
payment.cancel.failed A cancellation has failed.

Actions

Hook Name Description
morningtrain/nets-easy/webhook/{$webhookName} Do something on the webhook (before the implementet handling but after we have checked for previous handling)

Filters

Hook Name Filtered value Extra parameters Description
morningtrain/nets-easy/webhook/{$webhookName}/bypass false none Return something to bypass all webhook handling logic
morningtrain/nets-easy/webhook/{$webhookName}/after-handle false or value from handle function $webhook - The Webhook object with data Do something after default handling. Return something to bypass setting the webhook as handled and return status 200
morningtrain/nets-easy/webhook/{$webhookName}/response WP_REST_Response with default values (status 200) $webhook - The Webhook object with data Filter the response after webhook fully handled

Credits

License

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

morningtrain/wp-nets-easy 适用场景与选型建议

morningtrain/wp-nets-easy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 morningtrain/wp-nets-easy 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-02