# Webhook for Completed Payment

**URL:** <https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633>\
**Category:** Questions\
**Tags:** webhooks-api\
**Created:** [September 11, 2023, 1:49am UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633 "2023-09-11T01:49:01Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 11, 2023, 1:49am UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/1 "2023-09-11T01:49:01Z")

</div>

I am completely new to the concept of webhooks, and I have read up on the subject. But some assistance would still be appreciated.

Currently, my eCommerce app has a shopping cart that sends customers to the Square Checkout page when they want to pay via `online-checkout/payment-links`. What I need is for Square to notify my app when the customers have successfully completed payment. Once the customer has successfully payment, my app needs to add the customers’ name to a list within the app and send a confirmation email.

I have looked through the Square API document on webhooks, but I am not sure which webhook to use. I see there’re `payment.updated` and `invoice.payment_made`. Am I on the right track?

Thanks.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 11, 2023, 6:10pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/2 "2023-09-11T18:10:36Z")

</div>

With our webhooks you’ll want to listen to the `payments.updated` events to pull the `customer_id` from the payment. Once you have the `customer_id` you can call [RetrieveCustomer](https://developer.squareup.com/reference/square/customers-api/retrieve-customer) to get the name of the customer to send the email confirmation. 🙂

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 11, 2023, 7:30pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/3 "2023-09-11T19:30:14Z")

</div>

Great! I will give this a shot.

Another question related to this. Right now while I am in development mode, I can successfully send access Square’s online customer checkout page. My understanding is I cannot simulate a successful payment/transaction in that page. If that is the case, how do I test my webhooks?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 11, 2023, 8:11pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/4 "2023-09-11T20:11:57Z")

</div>

You’ll be able to test in sandbox. The sandbox will allow you to preview the link and process a payment that will trigger the `payment.updated` webhook events. 🙂

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 14, 2023, 5:22am UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/5 "2023-09-14T05:22:24Z")

</div>

I don’t see `customer_id` returned to me.

 ![image](https://global.discourse-cdn.com/square/original/2X/d/dcbad38786d562369fba24e13fd89a6712a8564c.png)

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 14, 2023, 4:52pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/6 "2023-09-14T16:52:31Z")

</div>

Was a `customer_id` passed in the `CreatePayment` request? This payment is an `EXTERNAL` payment and there isn’t any additional information for us to infer the customer. 🙂

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 14, 2023, 7:35pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/7 "2023-09-14T19:35:29Z")

</div>

I didn’t use `CreatePayment`. I used `online-checkout/payment-links`. I did not notice before, but now I can see that under the `order` parameter. It now says `customer_id` is in BETA. Does that mean it’s new and is being tested? Is it ok to use?

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 14, 2023, 8:28pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/8 "2023-09-14T20:28:46Z")

</div>

I added `customer_id` to the `online-checkout/payment-links` POST request, but it still did not reutrn with the customer ID:

 ![Screenshot 2023-09-14 132557](https://global.discourse-cdn.com/square/original/2X/0/08c460c96b8cda8a804a8b586855d4ceab3093e1.png)

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 14, 2023, 10:36pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/9 "2023-09-14T22:36:39Z")

</div>

Okay, this is sandbox and the sandbox experience isn’t great with the Payment links. It will be there in production. Unfortunately there isn’t a way to test this end to end in sandbox. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. 🙂

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 18, 2023, 11:02pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/10 "2023-09-18T23:02:06Z")

</div>

Well, is there any way for me to _pretend I do receive_ `customer_id` so that I can build and test out the steps that are supposed to execute afterwards?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 18, 2023, 11:21pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/11 "2023-09-18T23:21:58Z")

</div>

If you call CreatePayment with directly with the following it will trigger a webhook event with the `customer_id`:

```auto
{
    "idempotency_key": "{{$guid}}",
    "autocomplete": true,
    "amount_money": {
        "amount": 100,
        "currency": "USD"
    },
    "source_id": "cnon:card-nonce-ok",
    "customer_id": "{{customer_id}}"
}

```

🙂

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 18, 2023, 11:34pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/12 "2023-09-18T23:34:30Z")

</div>

I can call both `payment-links` and `CreatePayment`? Which comes first? Won’t this cause 2 transactions rather than 1?

Does `CreatePayment` also send the customer to Square’s checkout session?

I am obviously confused. Haha.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 19, 2023, 4:39pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/13 "2023-09-19T16:39:04Z")

</div>

No, you won’t call both for production. For testing I’m suggesting that you call `CreatePayment` with a `customer_id` to pretend to get the `customer_id` for testing. 🙂

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 19, 2023, 5:35pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/14 "2023-09-19T17:35:07Z")

</div>

Ah. Let me give that a shot. Thanks.

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 19, 2023, 6:34pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/15 "2023-09-19T18:34:02Z")

</div>

Can I get clarification on `customer id`. Isn’t it generated randomly by Square?

It looks like the call for `CreatePayment` is POST /v2/payments.

If the customer is new, do I have to call `POST /v2/customers` to create a new customer before calling `CreatePayment` so that a Square-generated ID can be inputted as part of that call?

Because right now, my app generates an ID that is in a different format than that of Square.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 19, 2023, 11:47pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/16 "2023-09-19T23:47:09Z")

</div>

Yes, you’ll need to first create a customer within Square to get an ID to pass in the payment request. 🙂

---

<div class="post-metadata">

**Author:** ![Cinji18](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Cinji18](https://developer.squareup.com/forums/u/Cinji18)\
**Post date:** [September 23, 2023, 6:51pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/17 "2023-09-23T18:51:20Z")

</div>

Ok, so right now, I am finally able to create a new customer, then from there, I succeeded in using `CreatePayment`.

However, I’m not sure I understand the step-by-step process and I can’t seem to find the documentation for it.

I want to be able to send the customer to the Square-hosted checkout page, but I am not sure when or if at all it happens.

Is it:

1. Create customer
2. Create payment
3. Send customer to Square-hosted checkout page

OR

1. Create customer
2. Send customer to Square-hosted checkout page
3. Create payment

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 25, 2023, 4:55pm UTC](https://developer.squareup.com/forums/t/webhook-for-completed-payment/10633/18 "2023-09-25T16:55:12Z")

</div>

Glad to hear your making progress. So remember you were only calling `CreatePayment` to test seeing the `customer_id` in the webhook. In production you won’t be calling `CreatePayment`.

You’ll call `CreateCustomer` if your collecting the customer information prior to creating the link and if the customer doesn’t exist within the directory already. Otherwise we will create the customer profile when the customer checkouts out through the link. 🙂
