# Self made website - Checkout help

**URL:** <https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666>\
**Category:** Questions\
**Created:** [January 22, 2021, 10:12pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666 "2021-01-22T22:12:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [January 22, 2021, 10:12pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/1 "2021-01-22T22:12:40Z")

</div>

Guys I been spending 3 days on this, no matter how many times I call support or research online I can’t figure this out ☹ And I’m even a programmer my self.

I have a website already built, from scratch. No 3rd party at all there’s no shopify or godaddy etc etc I built it from scratch. All I’m trying to do, is to allow my customers to pay for what ever product they add to their cart on my website.

I have the API credentials. I’m just trying to build a HTML \< form \> that will send the info to Square and customer entering their customer info but don’t know even where to start.  
I have ADHD so reading is soo hard. All I get are links that has soo many pages of content and I don’t even know which one applies to me.

am I supposed to build a form where customer enters credit card info on MY page and then send it via api to square? or am I supposed to have an iframe on my checkout page, load a square page in to that iframe where customer enters credit card info? I also want to offer to pay via apple pay etc etc…

Any help? I’m begging you guys ☹

---

<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:** [January 22, 2021, 10:18pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/2 "2021-01-22T22:18:39Z")

</div>

Hi @Andrea welcome to the forums!

If you’re wanting to build it all yourself, you would need to implement the [Square Payment Form](https://developer.squareup.com/docs/payment-form/overview), which essentially is four divs that allows a customer to enter their card details, and it generates a secure token called a `nonce`. You would then use this nonce to pass to the [CreatePayment](https://developer.squareup.com/reference/square/payments-api/create-payment) endpoint to actually…create a payment 🙂.

The Square Payment Form does support digital wallets as well, so that should fit your needs. It is a Javascript library, and you will need a backend server to handle the API requests, though. Please let me know if you have additional questions or concerns!

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [January 22, 2021, 10:47pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/3 "2021-01-22T22:47:19Z")

</div>

You’re awesome!  
I’m trying to build a multi-element (it looks a bit more user-friendly than single-element).

Question 1:  
So I build some type of HTML + Javascript, and have the customer fill out their credit card information on my website and then send it to squareup, correct?

Question 2:  
I was under the impression that I was not supposed to be the one handling any credit card information. And that when they enter their card info, it will actually be on their end and I wouldn’t have to send that info to them. Am I wrong?

Question 3:  
So this code below is pretty much all I need on my checkout for now (I know there’s a processing section but right now I’m talking about the initial stage)

\< script type=“text/javascript” src=“[https://js.squareupsandbox.com/v2/paymentform](https://js.squareupsandbox.com/v2/paymentform)” \>  
\< /script \>

\< script \>  
function onGetCardNonce(event) {  
paymentForm.requestCardNonce();  
}  
\< /script \>

\< script type=“text/javascript” \>  
const paymentForm = new SqPaymentForm({

```
 cardNumber: {
     elementId: 'sq-card-number',
     placeholder: 'Card Number'
 },
 cvv: {
     elementId: 'sq-cvv',
     placeholder: 'CVV'
 },
 expirationDate: {
     elementId: 'sq-expiration-date',
     placeholder: 'MM/YY'
 },
 postalCode: {
     elementId: 'sq-postal-code',
     placeholder: 'Postal'
 },
 // SqPaymentForm callback functions
 callbacks: {
     cardNonceResponseReceived: function (errors, nonce, cardData) {

        alert(`The generated nonce is:\n${nonce}`);
     }
 }

```

});  
\< /script \>

I’m so sorry for the inconvenience ☹

---

<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:** [January 22, 2021, 10:55pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/4 "2021-01-22T22:55:03Z")

</div>

1. All of the nonce generation is handled in the Javascript library. When the customer fills out the form and submits it, you will call `requestCardNonce` which will attempt to create a nonce based on the information provided. The form has a callback that will give you either errors or a nonce when a customer submits it. Then, you need to actually do something with the nonce (like pass it to `CreatePayment`) to charge their card.
2. Not sure what you mean by “send that info to them”. No card data will be transmitted over the network or to your back-end; the library is solely client-side until you have the nonce (which you can’t get raw data from anyway). You do not handle card data directly, nor do you need to be PCI compliant; Square handles all of that.
3. Looks like it’s missing some information. The SqPaymentForm will also need to know who’s requesting it (which is the `applicationId`, which is a parameter). The rest looks correct; the `elementId`'s will correspond to your front-end HTML divs (i.e give them the same ids so they match). The `cardNonceResponseReceived` will be the callback that lets you know if an error occurred or if you received a nonce.

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [January 22, 2021, 11:06pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/5 "2021-01-22T23:06:53Z")

</div>

ok so it’s all javascript based? the response and whole thing?

1. Can I handle the response via PHP instead of javascript ?

2. \< div id=“sq-card-number” \>\< /div \>  
does not actually create an \< input \> . Am I supposed to add that in my self within each layer?

3. Do you know a page where there’s sample code that has “applicationId” ?

---

<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:** [January 22, 2021, 11:41pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/6 "2021-01-22T23:41:36Z")

</div>

The nonce generation is part of the Javascript library. It cannot be handled by PHP since it’s a client-side implementation. The rest, you’ll need a backend language (like PHP), to actually call `CreatePayment`. So essentially, you’ll need to utilize both Javascript and PHP to go all the way from receiving the card info, to creating the payment.

1. If you set up everything else correctly, it will convert the div into an iframe with an input field inside. If you’re not seeing that, then something is going wrong and you should check your browser console for more information about potential errors.
2. There’s a full walkthrough here: [https://developer.squareup.com/docs/payment-form/payment-form-walkthrough](https://developer.squareup.com/docs/payment-form/payment-form-walkthrough) or the tech ref here: [https://developer.squareup.com/docs/api/paymentform#paymentform-configurationfields](https://developer.squareup.com/docs/api/paymentform#paymentform-configurationfields)

---

<div class="post-metadata">

**Author:** ![ZachH83](https://avatars.discourse-cdn.com/v4/letter/z/cdc98d/32.png) [@ZachH83](https://developer.squareup.com/forums/u/ZachH83)\
**Post date:** [January 25, 2021, 9:51pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/7 "2021-01-25T21:51:42Z")

</div>

> **[square/connect-api-examples](https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/php_payment)**
>
> master/connect-examples/v2/php\_payment

according to this, you can some how convert the nonce to a hidden form input element, and then on submission, that data can be used by php to be stored in your data base. However, I’ve had struggles getting this form to load. Its not as simple as the sqpaymentform, or maybe just dated. I dont know, but the nonce should be able to be converted to php according to this documentation.

---

<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:** [January 25, 2021, 11:39pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/8 "2021-01-25T23:39:21Z")

</div>

The above payment example is the Square Payment Form. It uses it in the front end Javascript, and passes the nonce to the backend PHP to process the payment. Definitely a good place to start, though to get an idea of how it should work.

---

<div class="post-metadata">

**Author:** ![ZachH83](https://avatars.discourse-cdn.com/v4/letter/z/cdc98d/32.png) [@ZachH83](https://developer.squareup.com/forums/u/ZachH83)\
**Post date:** [January 25, 2021, 11:43pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/9 "2021-01-25T23:43:24Z")

</div>

[https://developer.squareup.com/forums/t/converting-sqpaymentform-nonce-to-php/](https://developer.squareup.com/forums/t/converting-sqpaymentform-nonce-to-php/)

This is all you have to change on the sqpaymentform walkthrough to get your data to php.

The example I posted above adds a lot more unnecessary steps to make it happen.

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [January 27, 2021, 5:25am UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/10 "2021-01-27T05:25:37Z")

</div>

Thanks. I gotten a bit further thanks to your help! But there’s some things I’m really confused about.

A)  
My “applicationId” is TOTALLY exposed in the JS file (and location ID as well). is that ok ??

B)  
I been able to create my HTML And JS using this link:

> <https://gist.github.com/JohnMAustin78/40f2984af92268a1c4fe41c78ca69188>
>
> There are more than three files. show original

  
It seems to do the trick. Now what’s left is “process-card.php”.  
I can’t find the “autoload.php” anywhere though, any ideas?

---

<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:** [January 27, 2021, 5:16pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/11 "2021-01-27T17:16:53Z")

</div>

A. Yes, that’s fine. Application ids are not secrets, but access tokens are. You need the access token to make any API calls, and can’t do that with just the application id.

B. “autoload.php” is the file that is automatically created by Composer, if you install the PHP SDK from Composer. It’s a file that basically links all the SDK components for you so you don’t have to manually do it. If you use Composer, I believe it will be generate a `vendor` directory, and `autoload.php` will be in there.

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [February 5, 2021, 8:16pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/13 "2021-02-05T20:16:08Z")

</div>

So the index.php is at least complete:  
[https://filebin.net/6tv6yehkn1z24cv5/index.php?t=x01k5qcj](https://filebin.net/6tv6yehkn1z24cv5/index.php?t=x01k5qcj)

Here is sqpaymentform.js:  
[https://filebin.net/i031ptnfvkwkohbf/sqpaymentform.js?t=1481i9eg](https://filebin.net/i031ptnfvkwkohbf/sqpaymentform.js?t=1481i9eg)  
I know I’m supposed to fill out location id and application id.

It should take just few seconds to check the files. These 2 are all I need to process a payment right?

My second question, I was able to get the autoload stuff uploaded.  
But when trying a test square credit card I get:

> string(20) “AUTHENTICATION\_ERROR”  
> [“code”]=\>  
> string(12) “UNAUTHORIZED”  
> [“detail”]=\>  
> string(352) “The `Authorization` http header of your request was incorrect or expired. The header value is expected to be of the format “Bearer TOKEN” (without quotation marks), where TOKEN is a valid access token (e.g. “Bearer ABC123def456GHI789jkl0”). For more information, see /developer.squareup.com/docs/build-basics/using-rest-api# **set-the-headers**.”  
> }

Any idea what I might be doing wrong?

Question 3: I don’t need to install any certificate and stuff right?

I’m sorry guys…I spent TEN DAYS hours each day trying to figure this out  
I’m begging you guys…please help me

---

<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:** [February 5, 2021, 9:34pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/14 "2021-02-05T21:34:01Z")

</div>

1. You’ll need an additional file to actually call `CreatePayment`. In the above example, there is another PHP page titled `process-card.php` that does this.
2. UNAUTHORIZED errors means you’re inputting an invalid Square access token. If you’re trying to use sandbox, be sure to use sandbox environment and sandbox access token and vice-versa for production. The PHP SDK lets you do this by:

```auto
$client = new SquareClient([
    'accessToken' => 'YOUR SANDBOX ACCESS TOKEN HERE',
    'environment' => Environment::SANDBOX,
]);

```

1. Outside of localhost, you will need an SSL certificate to use the Square Payment Form, yes. Your hosting provider should be able to assist with that, though.

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [February 5, 2021, 10:07pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/15 "2021-02-05T22:07:55Z")

</div>

It is in fact “process-card.php” file I’m currently working on and having issues with.  
I am 100% sure I am using the correct SANDBOX token.

```
<?php
$access_token = "I did put my sandbox token here";

require 'vendor/autoload.php';
use Square\Models\Money;
use Square\Models\CreatePaymentRequest;
use Square\Exceptions\ApiException;
use Square\SquareClient;

// Initialize the Square client.

$client = new SquareClient([
  'accessToken' => $access_token,
  'environment' => Environment::SANDBOX
]);

```

Question 1: Any idea why the “$client = new SquareClient([” above stops the entire php code?

Question 2: Am I supposed to put SANDBOX\_APP\_ID in my “process-card.php” file?  
Here is my entire current process-card.php file:  
[https://filebin.net/shxwkbqe7pnsmzxl/process-card.php?t=uxa1r5ih](https://filebin.net/shxwkbqe7pnsmzxl/process-card.php?t=uxa1r5ih)

---

<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:** [February 5, 2021, 10:24pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/16 "2021-02-05T22:24:28Z")

</div>

1. You probably need to also include `use Square\Environment`, I believe, but if that’s not it…what’s the error?
2. No; your application id is only needed for the Square Payment Form, it’s not needed elsewhere.

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [February 5, 2021, 10:33pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/17 "2021-02-05T22:33:36Z")

</div>

It still stops as soon as this code runs:

```
$client = new SquareClient([
    'accessToken' => 'YOUR SANDBOX ACCESS TOKEN HERE',
    'environment' => Environment::SANDBOX,
]);

```

As soon as the code above runs, the PHP completely stops it does not continue :S  
Even if including Square\Environment, makes no difference.

Do you see anything wrong with this process-card.php? in the link above?

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [February 5, 2021, 10:51pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/18 "2021-02-05T22:51:29Z")

</div>

Hm, any idea why my posts are being flagged as spam? :S

---

<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:** [February 5, 2021, 11:17pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/19 "2021-02-05T23:17:29Z")

</div>

Are you seeing anything in your console log? You should be getting some information about _why_ it’s stopping. If it’s actually stopping on that line, it sounds like you may have broken the link again and it doesn’t know about `SquareClient` at all, but hard to know for sure without the errors. How were you getting the `UNAUTHORIZED` error earlier (that would be beyond the `SquareClient` line, so it seems like you were getting further earlier)?

As for the spam: I think due the numerous links; I restored your posts.

---

<div class="post-metadata">

**Author:** ![Andrea](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Andrea](https://developer.squareup.com/forums/u/Andrea)\
**Post date:** [February 5, 2021, 11:32pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/20 "2021-02-05T23:32:10Z")

</div>

The error file says:  
“Uncaught Error: Class ‘SquareConnect\Configuration’ not found”  
But this is from: require ‘vendor/autoload.php’;  
There’s no error refgarding the “$client = new SquareClient([” in the error file.

The word “Configuration” does not even exist in the “autoload.php” file.

The auth error I was getting before, was because I was using another “process-card.php” file.  
But that one didn’t have _“$client = new SquareClient([”_ and the word “createPayment” did not even exist in that version of process-card.php.

So I don’t know which one to use… seriously this is the most difficult project I ever worked on. Why in the world has square made it sooo difficult :S

---

<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:** [February 5, 2021, 11:39pm UTC](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666/21 "2021-02-05T23:39:18Z")

</div>

It sounds like you are getting the two files confused. `SquareConnect\Configuration’ not found` is from the previous one you mentioned earlier in the thread (and from the old SDK). If you’re seeing that error, then I’m guessing you’re using the wrong PHP file that still is using `SquareConnect\Configuration’` instead of the `SquareClient`, since the file you provided last has no mention of `SquareConnect\Configuration’` it wouldn’t be able to throw that error.

[Next page](https://developer.squareup.com/forums/t/self-made-website-checkout-help/1666.md?page=2)
