Allowing users to subscribe to my service

I have a simple webpage with registered users. Users have a user object, and that object has username, email and id. All 3 fields are unique.

I want those users to subscribe to more services. So what I would like to do is a have a button called subscribe, they click on it, and it will take them to square page, where they will enter their card info and whatnot, and I will know whether or not they subscribed.

I can not seem to find any means of doing so in square. Does square support this? It sounds simple enough, yet somehow I can not understand how to achieve this since I have done this previously for another customer using stripe, but I personally use square and would like to achieve same thing for square.

So just have an id, ass it to page where user enters their card info and confirms subscription. Then receive that id with either pass or fail. And ability to check if user has a subscription based off of an id. Doesn’t have to be id, by id I mean any unique string relating to user and linking him to square.

Sorry if this is obvious, but I can’t find answer from documentation.

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Get Started
Square Developer
Payment API: Process Online and In-Person Payments

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Yes, Square supports this functionality through the Subscription Plan Checkout feature of the Checkout API. You can create a checkout link for a Square subscription plan. When a user clicks on the “Subscribe” button, you can generate a Square-hosted checkout page for them to pay and subscribe to the plan.

You will need to provide the initial phase price as defined in the subscription plan and the ID of the subscription plan in a CreatePaymentLink request. After the buyer pays the specified amount, Square creates a customer if one doesn’t exist in the seller’s Customer Directory, adds a card on file to the customer profile, and charges the card on file for the first priced subscription phase. The card is then automatically charged for recurring payments as defined by the subscription plan.

You can then verify all the objects (customer, card on file order, order, and subscription) created. You can use the SearchSubscriptions endpoint (Subscriptions API) and provide the customer ID to retrieve the subscription. This way, you can check if a user has a subscription based on their customer ID.

This answer was reviewed by @Bryan-Square.

What would Java library equivalent be for this? The Java SDK is somewhat poorly documented so I am struggling to find which methods to call that would be equivalent of POST /v2/online-checkout/payment-links - Square API Explorer
And how would I play with this in sandbox mode? Or do I have to make a subscription and pay for it myself in order to be able to retrieve the data?

Here’s the link to the CreatePaymentLink in the Java SDK.

Once you open the link it will allow you preview the checkout and see what the buyer see’s. Please note that the sandbox experience with payment links isn’t feature complete but it will allow you to complete the payment. :slightly_smiling_face:

Thank you!!!
I have made a payment link request like so

CreatePaymentLinkRequest body = new CreatePaymentLinkRequest.Builder()
.idempotencyKey(user.getKey())
.quickPay(new QuickPay.Builder(
“Schooling Subscription”,
new Money.Builder()
.amount(300L)
.currency(“CAD”)
.build(),
webLocationId
)
.build())
.build();

And it does generate a link as I would expect it to.

In my square dashboard I have created a plan and assigned an item to it. Now how would I go about specifying in the create payment link request that I want it to be in regards to the plan I have? I am not sure how I can verify if the link I created is referring to my subscription or a one time purchase.

You’ll add the subscription plan in the CreatePaymentLink call. Here’s the documentation on adding a subscription to the call. :slightly_smiling_face:

Thank you so much for your help!

I have two questions:

  1. How do I find id of a subscription plan? In my Square dashboard I see a plan and the item added to it, but I can’t seem to figure out how to get id of subscription plan. I would like to use Java SDK if I can do so.

  2. Once I do obtain subscription id, how do I add it to CreatePaymentLinkRequest object in Java sdk? I see it in curl calls from examples however I do not see how I can do so with Java.

You can use the Catalog API to get the subscriptions. You’ll call /v2/catalog/list?types=SUBSCRIPTION_PLAN. :slightly_smiling_face:

I used Catalog API and obtained the CatalogObject for the subscription I want and saved it as subscriptionPlan variable

Then I tried creating payment link from this request

CreatePaymentLinkRequest body = new CreatePaymentLinkRequest.Builder()
		.idempotencyKey(user.getSquareKey())
		.checkoutOptions(
				new CheckoutOptions.Builder()
						.askForShippingAddress(false)
						.allowTipping(false)
						.merchantSupportEmail(contactEmail)
						.enableLoyalty(false)
						.enableCoupon(false)
						.redirectUrl(Constants.HOST)
						.subscriptionPlanId(subscriptionPlan.getId())
						.build())
		.quickPay(
				new QuickPay.Builder(null, null, null)
						.name("Schooling Subscription")
						.locationId(webLocationId)
						.priceMoney(
								new Money.Builder()
										.amount(300L)
										.currency("CAD")
										.build())
						.build())
		.build();

When I do this, I get an error saying

Invalid object `########################`: incorrect object type `SUBSCRIPTION_PLAN`.

How exactly do I add CatalogObject into the CreatePaymentLinkRequest? This is Java, I would appreciate an answer in Java or a link on how to do so with Java SDK.

If you instead pass in the subscription_variation_id as the subscription_id it will work. We are working to update the model. :slightly_smiling_face:

How should I obtain subscription_variation_id since it is null for me. I tried getting subscriptionPlan.getSubscriptionPlanVariationData() and also subscriptionPlan.getItemVariationData() and they are both null. Is there a reason as to why they would be null? Or am I getting the wrong ID?

What’s your application ID? :slightly_smiling_face:

I am sorry I might come back to this later. At the moment there doesn’t seem to be a decent example or solution or documentation on how I can create a subscription for the user. Due to that I am going to explore other options. As much as I absolutely love square and have used it for over two years, and you guys are the best in industry when it comes to POS. I really am struggling to figure out how to do a basic action such as allow users to subscribe to a service. And it is possible that maybe I am just a terrible programmer and my 16 years in industry dulled me to and made me unable to code as well as I should. But just out of curiosity I am going to try to see if it is me or you by trying something else. I will hopefully brb.