php - laravel - 如何在控制器中实现 Heartland 支付方式
问题描述
在我的网站上,我使用的是 Stripe,但由于某些原因决定更改为 Heartland 付款方式。由于我使用的是 laravel,所以我的知识是关于控制器和模型的,我试图了解如何使用 heartland 来做到这一点,但没有得到它。为了显示输入字段,它对我来说很好,所以现在我想通过单击提交按钮进行付款,但我不知道如何将这些输入信息发送到控制器以完成付款。请我需要很好的例子来显示控制器中的过程。我试图从此链接获取控制器内容,但没有找到明确的内容:https ://developer.heartlandpaymentsystems.com/Ecommerce/Card 提前谢谢
这里的代码:
路线:
Route::get('/Payment/Charge', 'PaymentController@heartlandPost')->name('heartlandpost');
付款表格和jquery代码:
<form id="payment-form" action="/Payment/Charge" method="get">
<div id="credit-card"></div>
</form>
<script src="https://api2.heartlandportico.com/SecureSubmit.v1/token/gp-1.0.1/globalpayments.js"> </script>
<script type="text/javascript">
GlobalPayments.configure({
publicApiKey: "pkapi_cert_*****"
});
// Create Form
const cardForm = GlobalPayments.creditCard.form("#credit-card");
cardForm.on("token-success", (resp) => {
// add payment token to form as a hidden input
const token = document.createElement("input");
token.type = "hidden";
token.name = "payment_token";
token.value = resp.paymentReference;
// Submit data to the integration's backend for processing
const form = document.getElementById("payment-form");
form.appendChild(token);
form.submit();
});
cardForm.on("token-error", (resp) => {
// show error to the consumer
});
</script>
控制器:
public function heartlandPost()
{
}
解决方案
因此,通过阅读文档,您似乎需要执行以下操作:
<?php
use GlobalPayments\Api\ServicesConfig;
use GlobalPayments\Api\ServicesContainer;
use GlobalPayments\Api\Entities\Address;
use GlobalPayments\Api\PaymentMethods\CreditCardData;
use GlobalPayments\Api\Entities\Exceptions\ApiException;
public function heartlandPost()
{
$config = new ServicesConfig();
$config->secretApiKey = "skapi_cert_***";
$config->developerId = "000000";
$config->versionNumber = "0000";
$config->serviceUrl = "https://cert.api2.heartlandportico.com";
ServicesContainer::configure($config);
$card = new CreditCardData();
$card->token = $request->input('payment_token');
$address = new Address();
$address->postalCode = $request->input('postal_code');
try {
$response = $card->charge(10)
->withCurrency("USD")
->withAddress($address)
->execute();
} catch (ApiException $e) {
// handle error
}
// return your response to the client
}
您需要更新配置以匹配您自己的密钥和诸如此类的东西,而且我不确定您如何将金额/邮政编码传递到您的后端,因此请确保您也这样做。
推荐阅读
- javascript - Angular 继承注入不同的实例
- javascript - sku.tpl 在哪里获取 opencart 中的 $sku_images
- proxysql - 使用 Proxy SQL 查询缓存
- linux - 如何从另一个 shell 脚本运行 shell 脚本,从 CSV 文件中读取第一个 shell 脚本名称
- json - 防止暴露 jSON 数据 - wp-json/contact-form-7/v1/
- c++ - Qt QToolBar 获取 addAction 添加的按钮
- jena - 使用 Fuseki 即服务时如何设置 Jena Fuseki 端口?
- angular - 根据 Angular 中的 JSON 数据显示价格
- c++ - Pimpl - 为什么可以在不完整的类型上调用 make_unique
- c# - 共享网络文件以进行读写