makstech / montonio-php-sdk
Montonio PHP 库
v1.2.0
2024-04-21 15:49 UTC
Requires
- php: ^8.0
- ext-curl: *
- firebase/php-jwt: ^6.0
Requires (Dev)
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2024-09-21 16:38:42 UTC
README
基于https://docs.montonio.com的 Montonio 支付 PHP SDK。
- 允许流畅地使用结构创建请求。
- 或者可以将原始数据传递给结构对象,以便它创建所有子结构。
- 使用 cURL 进行请求。
要求
PHP 8.0 或更高版本。
Composer
您可以通过 Composer 安装 SDK。运行以下命令
composer require makstech/montonio-php-sdk
用法
您可以通过访问 Montonio 控制台 → 店铺 → 选择您要集成的店铺 → 转到 API 密钥 来找到您的 API 密钥。
要使用 SDK,请使用您的访问密钥和秘密密钥初始化 Montonio\MontonioClient
。然后,您可以流畅地获取“子客户端”。例如,要获取 OrdersClient
并创建一个订单
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");
您可以在 官方文档 中找到带有响应数据示例的文档。
许可
此库在 MIT 许可证(MIT)下提供。有关更多信息,请参阅许可文件。