# Help : SCA and PHP Payment Form

**URL:** <https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990>\
**Category:** Questions\
**Tags:** payment-form\
**Created:** [March 1, 2021, 4:31pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990 "2021-03-01T16:31:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjamieson](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/benjamieson/32/317_2.png) [@benjamieson](https://developer.squareup.com/forums/u/benjamieson)\
**Post date:** [March 1, 2021, 4:31pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/1 "2021-03-01T16:31:35Z")

</div>

Hi All,

Banging my head against a wall here on implementing the SCA verification in the Payment Form.

Using Sandbox, and attempting to verify with the test nonce set as "cnon:card-nonce-requires-verification. Using test card to trigger what I would think would be an authentication step.

Basic javascript is:

```
cardNonceResponseReceived: function(errors, nonce, cardData, billingContact, shippingContact) {

    document.getElementById('card-nonce').value = nonce;
		total = document.getElementById('total');

  	const verificationDetails = {
		amount: total,
		intent: "CHARGE", //Allowed values: "CHARGE", "STORE"
		locationId : locationId,
		currencyCode: 'GBP',
		billingContact: {
			familyName: document.getElementById('familyName').value,
			givenName: document.getElementById('givenName').value,
			country: document.getElementById('country').value,
			city: document.getElementById('city').value,
    }
  };
  try {
	nonce= 'cnon:card-nonce-requires-verification';
    paymentForm.verifyBuyer( nonce, verificationDetails,
          function callback(err,verification) {
              if (err == null) {
              document.getElementById('buyerVerification-token').value = verification;
             }
         });
   document.getElementById('nonce-form').submit();

```

Everything seems to proceed until the submit is triggered. Nothing is added to the hidden field byerVerification-token (unsure if I’m meant to pass this at all?).

then I receive the following errors in console:

**1: [Error] Failed to load resource: the server responded with a status of 400 () [https://connect.squareupsandbox.com/v2/analytics/verifications](https://connect.squareupsandbox.com/v2/analytics/verifications)**

**2: XMLHttpRequest cannot load [https://pci-connect.squareupsandbox.com/v2/v?version=ca1c99ac2e](https://pci-connect.squareupsandbox.com/v2/v?version=ca1c99ac2e) due to access control checks. (repeated 3 times)**

Then the form ‘submits’ to the ‘process.php’ page, where it tells me it’s failed.

There’s no verification step, and the transaction fails on the following page (obviously)

Can anyone point me in the direction fo where I may look to fix?

Ben

---

<div class="post-metadata">

**Author:** ![sjosey](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/sjosey/32/40_2.png) [@sjosey](https://developer.squareup.com/forums/u/sjosey)\
**Post date:** [March 1, 2021, 5:24pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/2 "2021-03-01T17:24:21Z")

</div>

Hi @benjamieson welcome to the forums!

The test nonces aren’t really meant to be used like that; they would be used directly with `CreatePayment` call, and bypass the Square Payment Form altogether. Try using the Visa EU test card (`4310 0000 0020 1019`) by directly typing in the form to generate it as a nonce instead and see if that works. If it doesn’t, please provide your Square app id and I’ll see if I can uncover anything in our logs.

---

<div class="post-metadata">

**Author:** ![benjamieson](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/benjamieson/32/317_2.png) [@benjamieson](https://developer.squareup.com/forums/u/benjamieson)\
**Post date:** [March 1, 2021, 6:02pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/3 "2021-03-01T18:02:00Z")

</div>

Thanks so much - I’m getting somewhere - managing to pass the Verification token through to my process page, but here I’m stuck again.

How do I then pass _that_ to CreatePaymentRequest

The only args I can see it taking are the nonce, a uniqueID, and the charge details.

I currently have (pre SCA):

```
$payments_api = $client->getPaymentsApi();

$money = new Money();
$money->setAmount($_POST['amount']);
$money->setCurrency('GBP');

$create_payment_request = new CreatePaymentRequest($nonce, uniqid(), $money);

```

Where do I place the v.token in there?

Ben

---

<div class="post-metadata">

**Author:** ![sjosey](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/sjosey/32/40_2.png) [@sjosey](https://developer.squareup.com/forums/u/sjosey)\
**Post date:** [March 1, 2021, 6:10pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/4 "2021-03-01T18:10:49Z")

</div>

Are you using one of our SDKs? The [CreatePayment](https://developer.squareup.com/reference/square/payments-api/create-payment) endpoint definitely takes a `verification_token` argument as can be seen in this documentation.

Edit: if you’re using one of our SDKs, it’s possible you’re using an older version before SCA existed?

---

<div class="post-metadata">

**Author:** ![benjamieson](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/benjamieson/32/317_2.png) [@benjamieson](https://developer.squareup.com/forums/u/benjamieson)\
**Post date:** [March 1, 2021, 6:13pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/5 "2021-03-01T18:13:54Z")

</div>

Using the PHP SDK yes.

I’ve installed with composer, and updated along the way, so presume I’m using the latest version?

I updated the above, but so far I have:

```
$payments_api = $client->getPaymentsApi();

$money = new Money();
$money->setAmount($_POST['amount']);
$money->setCurrency('GBP');

$create_payment_request = new CreatePaymentRequest($nonce, uniqid(), $money);

```

This was fine pre-SCA as nothing else was needed, but I need to know where in that I pass the v.token?

Sorry if I’m an idiot - photographer by trade!

---

<div class="post-metadata">

**Author:** ![sjosey](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/sjosey/32/40_2.png) [@sjosey](https://developer.squareup.com/forums/u/sjosey)\
**Post date:** [March 1, 2021, 6:56pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/6 "2021-03-01T18:56:55Z")

</div>

Not an idiot at all, no worries 🙂 . So per the [PHP SDK docs](https://github.com/square/square-php-sdk/blob/master/doc/models/create-payment-request.md), there should also be a `verificationToken` field in the `CreatePaymentRequest`. You should be able to do something like:

```auto
$create_payment_request = new CreatePaymentRequest($nonce, uniqid(), $money);
$create_payment_request->setVerificationToken($verificationToken);
...

```

To be clear, according to the [code](https://github.com/square/square-php-sdk/blob/master/src/Models/CreatePaymentRequest.php), `sourceId`, `idempotencyKey`, and `amountMoney` are all required constructor parameters, but there’s several additional fields you can set as you can see in the first link I provided above.

---

<div class="post-metadata">

**Author:** ![benjamieson](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/benjamieson/32/317_2.png) [@benjamieson](https://developer.squareup.com/forums/u/benjamieson)\
**Post date:** [March 1, 2021, 7:14pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/7 "2021-03-01T19:14:43Z")

</div>

I figured it just before you posted!

Thanks for setting my sails in the right direction!

---

<div class="post-metadata">

**Author:** ![benjamieson](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/benjamieson/32/317_2.png) [@benjamieson](https://developer.squareup.com/forums/u/benjamieson)\
**Post date:** [March 2, 2021, 11:33am UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/8 "2021-03-02T11:33:49Z")

</div>

OK, one more question, as I have SCA working now.

How do I create a customer at the same time - I see there’s a reference to INSTANT\_PROFILE in the docs, but I am unsure how to utilise this within the createPayment?

Do I need to do a separate request for this, and if so, how would I tie to the payment just processed?

Currently, I have:

```
$payments_api = $client->getPaymentsApi();

$money = new Money();
$money->setAmount(number_format($_POST['amount'] * 100, 0,'.',''));
$money->setCurrency('GBP');

$create_payment_request = new CreatePaymentRequest($nonce, uniqid(), $money);

if ($_POST['buyerVerification-token'] !=''):
	$create_payment_request->setVerificationToken($_POST['buyerVerification-token']);
endif;

$create_payment_request->setBuyerEmailAddress($_POST['email']); //unsure where this is used?

try {
  $response = $payments_api->createPayment($create_payment_request);

    ...

```

Any pointers on this one?

---

<div class="post-metadata">

**Author:** ![sjosey](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/sjosey/32/40_2.png) [@sjosey](https://developer.squareup.com/forums/u/sjosey)\
**Post date:** [March 2, 2021, 4:49pm UTC](https://developer.squareup.com/forums/t/help-sca-and-php-payment-form/1990/9 "2021-03-02T16:49:19Z")

</div>

Essentially, you would want to use the [Customers API](https://developer.squareup.com/docs/customers-api/what-it-does) to actually create the customer first. After you create a customer, you’ll have the `customer_id`, in which case you can pass into the `CreatePayment` request to attach the customer to the payment.

Instant profiles can be created automatically _if_ we have any information on our side about the customer. For instance, if card “1234” was used at a Square merchant previously, and they opted for text receipts, then technically we have that information on our side. So, if the card is used again (and no `customer_id` is passed), then we can attempt to recognize that this customer actually exists, and create an instant profile. I definitely would not recommend relying on instant profiles, as more often than not very little information will actually be provided (it’s possible for an instant profile to have no information, because the receipt text/email information is not public, so we wouldn’t actually share it with any merchant).
