在一次交易中为 Square 支付网关创建两个随机数

Create two nonce in one transaction for Square payment gateway

我正在开发 Square 支付网关,我创建了创建客户、创建卡和付款这三个步骤。

            $create_customer_request = new \Square\Models\CreateCustomerRequest();
            $address = new \Square\Models\Address();
            $address->setAddressLine1($ship_address);
            $address->setPostalCode($_POST['ship_postcode']);
            $address->setCountry('US');
            $create_customer_request->setGivenName($_POST['f_name']);
            $create_customer_request->setFamilyName($_POST['f_name']);
            $create_customer_request->setEmailAddress($_POST['email']);
            $create_customer_request->setAddress($address);
            $create_customer_request->setPhoneNumber($_POST['phone']);
            $create_customer_request->setReferenceId($_POST['f_name']."-customer-".rand(10,15));
            $create_customer_request->setNote('A customer');
            $custcreateapiResponse = $client->getCustomersApi() >createCustomer($create_customer_request);
            $custcreateapiResponse->isSuccess();
            $_SESSION['temp_customer_id'] = $cust_res->getCustomer()->getId(); 

正在创建卡片请求

$body_card = new \Square\Models\CreateCustomerCardRequest($_POST['nonce']);
$card_api_response = $client->getCustomersApi()->createCustomerCard($_SESSION['temp_customer_id'], $body_card);

付款

$payments_api = $client->getPaymentsApi();
$money->setAmount(10);
$money->setCurrency('USD');
$pay_body = new \Square\Models\CreatePaymentRequest($_POST['nonce'],uniqid(),$money);
$pay_body->setCustomerId($_SESSION['temp_customer_id']);
$response = $client->getPaymentsApi()->createPayment($pay_body);

我现在遇到的问题是,我需要使用 Nonce 令牌发出两个请求,但系统不允许我对 Square 支付网关执行此操作。不知道现在该怎么办,任何形式的帮助将不胜感激。请原谅我这里的任何错误。

我尝试了很多来自互联网的解决方案,但 none 对我有用,所以我自己尝试逻辑。我知道这不是一个好方法,但是,它对我有用

在付款表单中,我创建了另一个隐藏字段

<input type="hidden" id="card-nonce-1" name="nonce1">

在 sq-payment-form.js

中创建一个新函数
function onGetCardNoncesecond(event) {
 event.preventDefault();
 paymentForm.requestCardNonce();
}

并将值放在隐藏字段中并提交并使用它。如果有任何改进建议,我们将不胜感激。