在我的网站上,我使用的是Stripe,但出于某些原因,决定改用Heartland付款方式。 当我使用laravel时,我的知识是关于控制器和模型的,所以我试图了解如何利用心脏地带进行此操作,但没有得到。为了显示输入字段,它可以正常工作,所以现在我想通过单击“提交”按钮进行付款,但是我不知道如何将这些输入信息发送给控制器以完成付款。 请我需要一个很好的示例来显示控制器中的过程。 我试图从此链接中获取控制器内容,但未找到清晰的内容: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()
{
}
答案 0 :(得分:0)
因此,通过阅读文档,它看起来像您需要做的:
<?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
}
您需要在其中更新配置以匹配您自己的密钥和诸如此类的东西,而且我不确定您如何将金额/邮政编码传递给后端,因此请确保也执行此操作。