我正在开发Square支付网关,我创建了创建客户、创建卡和付款三个步骤。
$create_customer_request = new SquareModelsCreateCustomerRequest();
$address = new SquareModelsAddress();
$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 SquareModelsCreateCustomerCardRequest($_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 SquareModelsCreatePaymentRequest($_POST['nonce'],uniqid(),$money);
$pay_body->setCustomerId($_SESSION['temp_customer_id']);
$response = $client->getPaymentsApi()->createPayment($pay_body);
我现在遇到的问题是,我需要用Nonce代币提出两个请求,但系统不允许我为Square支付网关这样做。现在不知道该怎么办,任何帮助都将不胜感激。请原谅我在这里犯的任何错误。
我从互联网上尝试了很多解决方案,但都不适合我,所以我自己尝试逻辑。我知道这不是一个好方法,然而,它对我有效
在付款表单中,我创建了另一个隐藏字段
<input type="hidden" id="card-nonce-1" name="nonce1">
在sq-payment-form.js 中创建一个新函数
function onGetCardNoncesecond(event) {
event.preventDefault();
paymentForm.requestCardNonce();
}
并将价值放在一个隐藏的字段中,提交并使用它。任何建议都将不胜感激。