定制 makstech/montonio-php-sdk 二次开发

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

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

makstech/montonio-php-sdk

最新稳定版本:v1.3.0

Composer 安装命令:

composer require makstech/montonio-php-sdk

包简介

Montonio PHP Library

README 文档

README

Latest Version Total Downloads Codecov

PHP SDK for Montonio Payments based on https://docs.montonio.com.

  • Allows to fluently create requests with structures.
  • Or a raw data can be passed to the structure object, to have it create all the child structures.
  • Uses cURL to make requests.

Requirements

PHP 8.0 or later.

Composer

You can install the SDK via Composer. Run the following command:

composer require makstech/montonio-php-sdk

Usage

You can find your API keys by going to your Montonio dashboard → Stores → Choose the store you are integrating → Go to API keys.

To use the SDK, start by initializing the Montonio\MontonioClient using your access and secret keys. And from there, you can fluently get the "sub-clients". For example, to get OrdersClient and create an order:

use Montonio\MontonioClient;

// Initialize the client
$client = new MontonioClient(
    $accessKey,
    $secretKey,
    MontonioClient::ENVIRONMENT_SANDBOX, // or MontonioClient::ENVIRONMENT_LIVE
);
 
// Get OrdersClient
$ordersClient = $client->orders();

// Create order structure

// This example shows only some setters and options. Check source
// structures for all options and check documentation for required fields.
// https://docs.montonio.com/api/stargate/guides/orders#complete-example

$address = (new \Montonio\Structs\Address([
        'firstName' => 'elon',
        'lastName' => 'musk',
    ]))
    // or
    ->setFirstName('jeff')
    ->setLastName('bezos')
    ...;

// This is same...
$orderData = new \Montonio\Structs\OrderData([
    'locale' => 'en',
    ...
    'billingAddress' => [
        'firstName' => 'jeff',
        ...
    ],
]);

// ... as this, but fluently
$orderData
    ->setLocale('en')
    ->setBillingAddress($address)
    ->setMerchantReference(uniqid())
    ->setReturnUrl('https://google.com?q=montonio+return+url')
    ->setNotificationUrl('https://google.com?q=montonio+notification')
    ->setGrandTotal(1337)
    ->setCurrency('EUR')
    ->setPayment(
        $payment = (new \Montonio\Structs\Payment())
            ->setCurrency('EUR')
            ->setAmount(1337)
            ->setMethod(Payment::METHOD_PAYMENT_INITIATION)
    )
    ->addLineItem(
        $item1 = (new \Montonio\Structs\LineItem())
            ->setName('elephant')
            ->setFinalPrice(668.5)
            ->setQuantity(2)
    )
    ->setShippingAddress($address)
;

// Send API request
$order = $ordersClient->createOrder($orderData);

// Get payment URL
$paymentUrl = $order['paymentUrl'];

// Redirect customer to that URL
header("Location: $paymentUrl");

You can find the documentation with the response data example, in the official docs.

License

This library is made available under the MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

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