agrekom/imoje-libs-module

支付核心库,包含实现支付方式(ING 银行)的基本功能

1.0.21 2024-06-30 13:51 UTC

This package is auto-updated.

Last update: 2024-08-30 14:11:22 UTC


README

这是一个简单的PHP库,允许直接实现支付网关方法。

要求

  • PHP需要至少为5.4.0版本
  • cURL需要启用

安装

  1. git克隆
  2. composer安装

如何使用

库提供了一些已经创建的方法,例如生成表单订单或仅生成表单字段。

如果您想生成完整的表单

  1. 首先您需要初始化支付实例并提供环境、服务密钥和服务ID。最后一个参数language是可选的,如果不提供,将使用默认值(即'en')
  2. 然后简单运行$payment->buildOrderForm($orderData)来构建完整表单,或者运行$payment->buildFormFields($orderData)来构建表单字段。

示例

构建完整表单

订单数据必须包含字段:amount, currency, orderId, customerFirstName, customerLastName

可选数据:customerEmail, urlSuccess, urlFailure, urlReturn, urlNotification, twistoData, version

示例 $orderData

$orderData = [
    'amount' => (int) (1.33 * 100), //INT, price should be multipled by 100 so for example 1.33 will be 133 
    'currency' => 'PLN', // see suported currences in 'Supported variables' sectiom
    'orderId' => '123456790',
    'customerFirstName' => 'John',
    'customerLastName' => 'Doe',
    'customerEmail' => 'john@doe.com',
    'urlSuccess' => 'https://example.com/success.php',
    'urlFailure' => 'https://example.com/failure.php',
    'urlReturn' => 'https://example.com/return.php',
];
use Payment\Payment;

public function yourFunction()
{
    // ...
    
    $payment = new Payment(\Payment\Util::ENVIRONMENT_PRODUCTION, 'b1c8bd6c7411455aab3295c48fcf26a7', 'e692d208484b4d5887755362d0587a00', 'pl');
    
    $form = $payment->buildOrderForm($orderData); // You can also pass second parameter `language` to generate form that will redirect to this language
}

$form必须包含$orderData和额外的键(签名必须包含所使用的哈希方法(例如sha256)),如

serviceId, merchantId, signature

<input type="hidden" value="133" name="serviceId">
<input type="hidden" value="133" name="merchantId">
<input type="hidden" value="133" name="amount">
<input type="hidden" value="PLN" name="currency">
<input type="hidden" value="123456790" name="orderId">
<input type="hidden" value="John" name="customerFirstName">
<input type="hidden" value="Doe" name="customerLastName">
<input type="hidden" value="john@doe.com" name="customerEmail">
<input type="hidden" value="https://example.com/success.php" name="urlSuccess">
<input type="hidden" value="https://example.com/failure.php" name="urlFailure">
<input type="hidden" value="https://example.com/return.php" name="urlReturn">
<input type="hidden" value="7c46b5c9836520a9a0552d31136a705d3f7a7ea3db13de87f41fb3ee31f6dbff;sha256" name="signature">

然后您可以将它包裹到自己的form HTML标签中

<form method="POST" action="http://example.com/pl/payment">
    <input type="hidden" value="133" name="serviceId">
    <input type="hidden" value="133" name="merchantId">
    <input type="hidden" value="133" name="amount">
    <input type="hidden" value="PLN" name="currency">
    <input type="hidden" value="123456790" name="orderId">
    <input type="hidden" value="John" name="customerFirstName">
    <input type="hidden" value="Doe" name="customerLastName">
    <input type="hidden" value="john@doe.com" name="customerEmail">
    <input type="hidden" value="https://example.com/success.php" name="urlSuccess">
    <input type="hidden" value="https://example.com/failure.php" name="urlFailure">
    <input type="hidden" value="https://example.com/return.php" name="urlReturn">
    <input type="hidden" value="7c46b5c9836520a9a0552d31136a705d3f7a7ea3db13de87f41fb3ee31f6dbff;sha256" name="signature">
    
    <input class="button" type="submit" value="Continue" id="submit-payment-form">
</form>

附加功能

库提供了一些您可以使用的附加方法。

首先您需要添加use Payment\Util;然后您可以

  • Util::getSupportedCurrencies() - 它将返回一个包含可用货币的数组。
  • Util::getSupportedLanguages() - 它将返回一个包含可用语言的数组。
  • Util::canUseForCurrency($currencyCode) - $currencyCode应采用ISO4217格式。该方法将返回bool值。

支持的变量

支持的货币是:PLN

支持的语言是:波兰语,英语

您应该使用ISO 639-1(Alpha-2代码)格式