openapi / epay
ePay.bg & EasyPay API
dev-master
2020-03-15 13:34 UTC
This package is auto-updated.
Last update: 2024-09-05 00:10:39 UTC
README
- 示例配置
{
"sandbox": 1,
"encoding": "UTF-8",
"production": {
"expire_after": "6 hours",
"debug": false,
"credentials": {
"secret": "secret_key_production",
"client_id": "merchant_client_ident_number",
"client_email": "merchant_email"
},
"endpoint_url": "https://www.epay.bg/",
"return_url": "https://yourdomain.com/thank-you.php",
"cancel_url": "https://yourdomain.com/cancel.php"
},
"development": {
"expire_after": "24 hours",
"debug": true,
"credentials": {
"secret": "secret_key_demo",
"client_id": "merchant_client_ident_number_demo",
"client_email": "merchant_email"
},
"endpoint_url": "https://devep2.datamax.bg/ep2/epay2_demo/",
"return_url": "https://staging.yourdomain.com/thank-you.php",
"cancel_url": "https://staging.yourdomain.com/cancel.php"
}
}
- 在项目中使用
require_once 'vendor/autoload.php';
use Openapi\Epay\Payments\WebPayment;
use Openapi\Epay\Types\InvoiceType;
- 加载WebPayment类
$config = file_get_contents('config.json');
$credentials = json_decode($config, true);
$epay = new WebPayment($credentials);
$epay->paymentWeb();
- 创建新的发票类型 - 类的参数实例
$invoice = new InvoiceType([
'amount' => '120.80',
'description' => 'Test Invoice',
'invoice_number' => sprintf("%.0f", rand(0, 999999)) //if invoice number is not set, it will be automatically generated
]);
- 或创建新的发票类型 - 只实例化类
$invoice = new InvoiceType();
$invoice->amount = '120.80';
$invoice->description = 'Test Invoice';
//if invoice number is not set, it will be automatically generated
$invoice->invoice_number = sprintf("%.0f", rand(0, 999999));
- 生成发票
$epay->generateInvoice($invoice);
- 生成发送数据到ePay端点URL的web表单(示例来自https://epay.openapiservices.com/的演示页面)
<form action="<?= $epay->getEndpointUrl() ?>" method=POST>
<div class="row">
<table class="table table-hover">
<thead>
<tr>
<th>Order</th>
<th>Invoice</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><?= $invoice->description ?></td>
<td><?= $invoice->invoice_number ?></td>
<td><?= $invoice->amount ?> <?= $invoice->currency ?></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<div class="row">
<hr />
<!--generate hidden input fields required from ePay-->
<input type=hidden name=PAGE value="<?= $epay->getPaymentType() ?>">
<input type=hidden name=ENCODED value="<?= $epay->getEncoded() ?>">
<input type=hidden name=CHECKSUM value="<?= $epay->getChecksum() ?>">
<input type=hidden name=URL_OK value="<?= $epay->getReturnUrl() ?>">
<input type=hidden name=URL_CANCEL value="<?= $epay->getCancelUrl() ?>">
<button type="submit" class="btn btn-primary btn-rounded btn-sm waves-effect waves-light">Checkout</button>
</div>
</form>