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()


 {

 }


RISEBY
浏览 112回答 1
1回答

MMMHUHU

因此,通过阅读文档,您似乎需要执行以下操作:<?phpuse 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(){&nbsp; &nbsp; $config = new ServicesConfig();&nbsp; &nbsp; $config->secretApiKey = "skapi_cert_***";&nbsp; &nbsp; $config->developerId = "000000";&nbsp; &nbsp; $config->versionNumber = "0000";&nbsp; &nbsp; $config->serviceUrl = "https://cert.api2.heartlandportico.com";&nbsp; &nbsp; ServicesContainer::configure($config);&nbsp; &nbsp; $card = new CreditCardData();&nbsp; &nbsp; $card->token = $request->input('payment_token');&nbsp; &nbsp; $address = new Address();&nbsp; &nbsp; $address->postalCode = $request->input('postal_code');&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; $response = $card->charge(10)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->withCurrency("USD")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->withAddress($address)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->execute();&nbsp; &nbsp; } catch (ApiException $e) {&nbsp; &nbsp; &nbsp; &nbsp; // handle error&nbsp; &nbsp; }&nbsp; &nbsp; // return your response to the client}您需要更新配置以匹配您自己的密钥和诸如此类的东西,而且我不确定您如何将金额/邮政编码传递到您的后端,因此请确保您也这样做。
打开App,查看更多内容
随时随地看视频慕课网APP