中期php
中期trans❤️php!
这是与作曲家兼容的Mid Trans付款API的官方PHP包装器/图书馆。有关该产品的更多信息,请访问https://*midtra*ns.c*om,并在http://docs.midtrans.com上查看文档,以获取更多技术详细信息。启动版2.6,该库现在支持Snap-bi。您可以转到此文档以了解有关Snap-Bi的更多信息。
1。安装
1.作曲家安装
如果您使用的是作曲家,则可以通过Composer CLI安装:
composer require midtrans/midtrans-php
或者
将此要求行添加到您的composer.json文件:
{
"require" : {
"midtrans/midtrans-php" : " 2.* "
}
}并在终端上运行composer install 。
注意:如果您使用的是Laravel框架,在某些情况下,您还需要运行
composer dumpautoload
然后,
/Midtrans将作为您的Laravel项目中的对象可用(自动加载)。
1.B手动安装
如果您不使用作曲家,则可以克隆或下载此存储库。
然后,您应该在代码上需要/autoLoad Midtrans.php文件。
require_once dirname ( __FILE__ ) . ' /pathofproject/Midtrans.php ' ;
// my code goes here 2。如何使用
2.1一般设置
// Set your Merchant Server Key
Midtrans Config:: $ serverKey = ' ' ;
// Set to Development/Sandbox Environment (default). Set to true for Production Environment (accept real transaction).
Midtrans Config:: $ isProduction = false ;
// Set sanitization on (default)
Midtrans Config:: $ isSanitized = true ;
// Set 3DS transaction for credit card to true
Midtrans Config:: $ is3ds = true ;覆盖通知URL
您可以选择更改或添加每个事务上的自定义通知URL。可以通过将其他HTTP标头添加到负责请求中来实现。
// Add new notification url(s) alongside the settings on Midtrans Dashboard Portal (MAP)
Config:: $ appendNotifUrl = " https://ex**am*ple.com/test1,https://example.com/test2 " ;
// Use new notification url(s) disregarding the settings on Midtrans Dashboard Portal (MAP)
Config:: $ overrideNotifUrl = " https://ex*am*ple.c*om/test1 " ;更多细节
注意:当一起使用
appendNotifUrl和overrideNotifUrl时,仅将使用过度overrideNotifUrl。
两个标头只能收到最多3个URL 。
智力 - 键
您可以选择在充电事务上添加divempotency键。可以通过将其他HTTP标头添加到负责请求中来实现。是一个独特的值,它在API请求上放在标题上。 Midtrans API接受标头上的IDEMPOTENCY-KEY,可以安全处理重试请求,而无需两次执行相同的操作。对于由于网络问题或其他意外错误而未收到响应的情况,这很有帮助。
Config:: $ paymentIdempotencyKey = " Unique-ID " ;更多细节
2.2选择产品/方法
我们有3种不同的付款产品,您可以使用:
- SNAP-可自定义的付款弹出窗口将出现在您的Web/App上(无重定向)。 Doc Ref
- SNAP重定向 - 需要将客户重定向到由中型托管托管的付款URL。 Doc Ref
- Core API(VT -Direct) - 基本的后端实现,您可以根据自己的意愿自定义嵌入在Web/应用程序上的前端(无重定向)。 Doc Ref
选择最适合自己独特需求的一种。
2.2
您可以在此处看到快照示例。
获得快照令牌
$ params = array (
' transaction_details ' => array (
' order_id ' => rand (),
' gross_amount ' => 10000 ,
)
);
$ snapToken = Midtrans Snap:: getSnapToken ( $ params );当客户点击付款按钮时,初始化snap js
JSON result will appear here after payment: