# Way to generate Payment Links with exisitng customers

**URL:** <https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842>\
**Category:** Questions\
**Tags:** checkout-api\
**Created:** [May 21, 2024, 8:09pm UTC](https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842 "2024-05-21T20:09:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clouden](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@Clouden](https://developer.squareup.com/forums/u/Clouden)\
**Post date:** [May 21, 2024, 8:09pm UTC](https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842/1 "2024-05-21T20:09:44Z")

</div>

I have been using payment links to handle the checkout process for my customers. If I have already created an associated customer with my database. How can I create a payment link that passes that customer ID through. I think it seems to be creating a new customer every time, even when I am passing in the customer ID in the order. I saw there was an older post regarding this question, [which I found here.](https://developer.squareup.com/forums/t/how-to-generate-the-checkout-link-for-existing-customer/3328) This post is a few years old, and I was wondering if there was a way to do this or at least a workaround, so I don’t have to make my own checkout page and process.

When in sandbox mode, using the "Checkout API Sandbox Testing Panel " that appears when viewing the payment link and clicking the test payment button works completely fine. It’s when I switch to production and do real test payments that it’s creating a new customer.

If there is some way to keep the process I have by using a payment link, that would be greatly appreciated, as it would much more work to create a checkout process myself when its sooo close to working.

---

<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:** [May 21, 2024, 8:51pm UTC](https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842/2 "2024-05-21T20:51:38Z")

</div>

At this time adding a known customer to a quick pay link isn’t currently available. You’ll need to add the customer in an order. For example:

```auto
{
    "idempotency_key": "{{$guid}}",
    "checkout_options": {
        "enable_coupon": true,
        "accepted_payment_methods": {
            "afterpay_clearpay": true,
            "apple_pay": true,
            "cash_app_pay": true,
            "google_pay": true
        },
        "allow_tipping": true,
        "ask_for_shipping_address": true,
        "custom_fields": [
            {
                "title": "Auto color"
            }
        ],
        "enable_loyalty": true,
        "shipping_fee": {
            "charge": {
                "amount": 100,
                "currency": "USD"
            },
            "name": "Shipping"
        }
    },
    "order": {
        "location_id": "{{location_id}}",
        "customer_id": "{{customer_id}}",
        "line_items": [
            {
                "name": "60,000 mile maintenance",
                "quantity": "1",
                "base_price_money": {
                    "amount": 25,
                    "currency": "USD"
                },
                "note": "1st line item note"
            },
            {
                "name": "Tire rotation and balancing",
                "quantity": "1",
                "base_price_money": {
                    "amount": 25,
                    "currency": "USD"
                }
            },
            {
                "name": "Wiper fluid replacement",
                "quantity": "1",
                "base_price_money": {
                    "amount": 25,
                    "currency": "USD"
                }
            },
            {
                "name": "Oil change",
                "quantity": "1",
                "base_price_money": {
                    "amount": 25,
                    "currency": "USD"
                }
            }
        ]
    }
}

```

🙂

---

<div class="post-metadata">

**Author:** ![Clouden](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@Clouden](https://developer.squareup.com/forums/u/Clouden)\
**Post date:** [May 21, 2024, 9:23pm UTC](https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842/3 "2024-05-21T21:23:50Z")

</div>

Thanks for the response. So I create an order and pass that order into the create Payment Link. I am using the payment.updated webhook. Would I use the order attached to that payment and grab the customer id on that. Or would I have to setup an additional webhook for orders somehow. Because the payment.updated webhook works great as it tells when the payment is complete and works with the Square POS app as well, when payments are taken say through a card reader.

This is how I am passing it into the checkoutAPI function when creating a payment link, would I just then use the customer on that order. I guess I am just a bit confused on after a payment is completed how to see what customer is associated with that payment.

```auto
const response = await client.checkoutApi.createPaymentLink({
      idempotencyKey: idempotencyKey,
      order: {
        locationId: locationId,
        lineItems: lineItems,
        discounts: [],
        customerId: user.customerIds[0],
      },
      checkoutOptions: {
        redirectUrl: redirectUrl,
      },
    });

```

---

<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:** [May 21, 2024, 10:14pm UTC](https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842/4 "2024-05-21T22:14:15Z")

</div>

At this time the ability to create an order with the Orders API and then create a payment link isn’t currently available. You’ll have to pass in the `customer_id` when creating a payment link with an order. 🙂

---

<div class="post-metadata">

**Author:** ![Clouden](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@Clouden](https://developer.squareup.com/forums/u/Clouden)\
**Post date:** [May 21, 2024, 11:49pm UTC](https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842/5 "2024-05-21T23:49:38Z")

</div>

Thanks for the response, Bryan. I am still a little confused by this process.

My end goal is to take a payment through the payment link and have it associated with some existing customer. Get an update from a webhook and update my database with the new payment from that existing customer.

What I am currently doing is creating the payment link with the customer ID and passing in values for an order when I create the payment link.

When I receive the update for the payment (from payment.updated webhook) I do not receive the customer ID that I created the Payment Link with, rather one square has created. Here you said

> [@Bryan-Square](#):
>
> You’ll have to pass in the `customer_id` when creating a payment link with an order.

While this process works in sandbox mode. When in production, it creates the new customer, instead of using the customer ID I pass in. Just not sure why

In regard to

> [@Bryan-Square](#):
>
> At this time the ability to create an order with the Orders API and then create a payment link isn’t currently available

I am creating the order in the payment link itself which is what contains the payment link so I am just passing in the items needed for the order, I do not create the order beforehand with the Orders API just to clear things up.

If there is anyway to have payment link, payment/order to be associated with an existing customer that would be fantastic and if you could explain the process of doing so you would be a lifesaver Bryan and I would greatly appreciate it.

---

<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:** [May 22, 2024, 4:55pm UTC](https://developer.squareup.com/forums/t/way-to-generate-payment-links-with-exisitng-customers/16842/6 "2024-05-22T16:55:02Z")

</div>

Do you have a `payment_id` of a payment that the customer wasn’t added to? Also with payment links the customer can be added well after a payment is completed. A `payment.updated` event will be triggered but its possible that it will come well after the payment is created. 🙂
