Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

php - Create two nonce in one transaction for Square payment gateway

I am working on Square payment gateway and I created three steps creating a customer, creating a card, and then making a payment.

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

creating a card request

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

making a payment

$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);

The issue I am having right now, I need to make two requests with the Nonce token but the system doesn't allow me to do it for the Square payment gateway. Don't know what to do now, Any kind of help will be appreciated. Pardon me for any mistakes here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I tried many solutions from the internet but none of them work for me, so I try logic by myself. I know it's not a good approach, however, it works for me

in payment form, I create another hidden field

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

create a new function in sq-payment-form.js

function onGetCardNoncesecond(event) {
 event.preventDefault();
 paymentForm.requestCardNonce();
}

and put the value in a hidden field and submit and use it. Any suggestion would be appreciated for the betterment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...