[#1180] How do you process payment using api

Migrated from Redmine #1180 | Author: Olaf Siebert
Status: Feedback | Priority: Low, I can wait | Created: 2024-02-22


I was able to create a booking for a services and I have setup the payment processor (stripe) but how do you process the payment in my app?

Dmytro Bondarev wrote:

Hi,
You can make payment link and redirect customer to payment.
Or yon can accept payment your side and then call API documentation | SimplyBook.me Online Scheduling

Olaf Siebert wrote:

I am in the process of integrating SBPay with Stripe to offer a seamless payment experience on my website. My client prefers managing all aspects of the payment process through your platform, especially since the services provided require upfront payment. In this context, I seek your guidance on the best approach to achieve a smooth integration that allows for a fully customized user experience on our site while leveraging the majority of your platform’s capabilities.

Additionally, I find myself somewhat perplexed by the differences between your API and REST API authentication mechanisms. My understanding is that to authenticate with the REST API, one must use the username and password associated with their actual account, as opposed to utilizing the API key. Could you please confirm if this understanding is correct?

Furthermore, if I were to set up my own Stripe gateway for processing payments, and subsequently call the confirmBookingPayment($id, $paymentProcessor, $sign) function after receiving confirmation from Stripe’s webhook that the payment has been successfully processed, would your system still generate an invoice and manage the post-payment process as usual?

Please could you advise on the optimal payment processing method that not only ensures a high degree of customization on our website but also allows my customers to utilize the vast majority of your platform’s features?

I appreciate your time and assistance in this matter and look forward to your expert recommendations.

Dmytro Bondarev wrote:

My client prefers managing all aspects of the payment process through your platform

The only way to do it is to generate payment link and redirect customer. Customer will be able to see order, select payment processor, etc. payment, validation, etc., will be processed on our side.

Additionally, I find myself somewhat perplexed by the differences between your API and REST API authentication mechanisms. My understanding is that to authenticate with the REST API, one must use the username and password associated with their actual account, as opposed to utilizing the API key. Could you please confirm if this understanding is correct?

We have public API (JSON RPC only at the moment) and admin API (JSON RPC and REST). For public API you should use API keys, for admin you should use login/password/2fa.

Furthermore, if I were to set up my own Stripe gateway for processing payments, and subsequently call the confirmBookingPayment($id, $paymentProcessor, $sign) function after receiving confirmation from Stripe's webhook that the payment has been successfully processed, would your system still generate an invoice and manage the post-payment process as usual?

confirmBookingPayment is deprecated function. If you process payment on your side, please use API documentation | SimplyBook.me Online Scheduling to accept payment. System will generate an invoice and manage the post-payment process as usual.

Olaf Siebert wrote:

Thanks,

You saying login/password/2fa, how can i do 2fa on my backend?

Cheers
Olaf

Dmytro Bondarev wrote:

After first step you will receive API documentation | SimplyBook.me Online Scheduling object with auth_session_id.
Then on server you can generate code based on Google Authenticator secret and pass to API documentation | SimplyBook.me Online Scheduling . (with auth session id)

Olaf Siebert wrote:

Thanks,

2fa is not yet activated on the account. So I was able to get the token and use the api. However, I am using serverless function. I notice I get logged out after a while and even using the refresh token, it tells me too many attempts. Is just very strange you have to login with your user credential, I usually would expect a api public key to access an api. So any suggestion how to get around this login error to make this work for our website.

o

Dmytro Bondarev wrote:

Hi, as it is admin API credentials are required.
You should use credentials only once and then use refresh token when token is expired to issue new access token.

Olaf Siebert wrote:

ok, thanks, not quite figured out how i so this on serverless function. Anyway,I am getting bad request on the bookings endpoint when sending this data:

data: `{“count”:1,“service_id”:2,“client_id”:36,“provider_id”:2,“start_datetime”:“2024-02-26 09:00:00”,“accept_payment”:true,“payment_processor”:“stripe”,“additional_fields”…

What do i miss?

o

Dmytro Bondarev wrote:

Yo are getting this error because your request is not valid.
It is hard to check what exactly wrong, because do not see full request.
Please provide raw HTTP request and response for investigation.
Usually when you are getting Bad Request, there is more explanation why, including not valid fields, etc.

Olaf Siebert wrote:

Seems additional fields caused an error. How do you add more fields for booking as i do need store users birthday and location.

Also I notice, when you do a booking, it does not return a payment link. Instead it says the payment_recieved true. Do i need to set accept_payement to false and then call get payment link?

Dmytro Bondarev wrote:

Hi,
If you need additional fields you can use intake forms and pass data via API.
If you use REST API, please pass payment_processor as null and then call API documentation | SimplyBook.me Online Scheduling to receive payment link.

Olaf Siebert wrote:

Hi Dmytro,

Thanks for the info. The Rest API seems to have everything I need for now, but I’m hitting a snag with authentication since I’m running the app in a stateless environment. Your public API looks like it could be a better fit for a stateless setup, but it doesn’t seem to have all the same features. Do you have any suggestions on how to handle the flow—like a user picking servers, adding info, getting the next available slot, confirming their booking, and paying online—without resorting to using a database for token management? If your public API can handle this, or if sticking with the Rest API is smarter, I’d really appreciate your advice. My client is ready to move forward with your solution; I just need to figure out the best way to integrate it into her website.

Thanks a bunch!

Olaf Siebert wrote:

I just notice, your endpoints are different for the RESTapi. Do I look at the wrong documentation?

https://user-api-v2.simplybook.me/admin/

vs

Olaf Siebert wrote:

Ignore

(Short original content)

Olaf Siebert wrote:

Ok, getting a payment link does not work. Setting accept_payment false and payment_link to null, returns the following data:

bookings: [
{
id: 42,
code: ‘1sky15a7v’,
start_datetime: ‘2024-02-27 14:00:00’,
end_datetime: ‘2024-02-27 15:00:00’,
location_id: null,
category_id: null,
service_id: 2,
provider_id: 2,
client_id: 36,
duration: null
}
],
batch: null,
invoice: null,
id: null

No order number and using the booking id is not working either. Accept_payment true, requires payment_processor.

Olaf Siebert wrote:

Olaf Siebert wrote:

Ok, getting a payment link does not work. Setting accept_payment false and payment_link to null, returns the following data:

bookings: [
{
id: 42,
code: ‘1sky15a7v’,
start_datetime: ‘2024-02-27 14:00:00’,
end_datetime: ‘2024-02-27 15:00:00’,
location_id: null,
category_id: null,
service_id: 2,
provider_id: 2,
client_id: 36,
duration: null
}
],
batch: null,
invoice: null,
id: null

No order number and using the booking id is not working either. Accept_payment true, requires payment_processor.

Error making booking undefined {
code: 400,
message: ‘’,
data: { payment_processor: [ “Value is required and can’t be empty” ] },
message_data:
}

Olaf Siebert wrote:

Ok, getting a payment link does not work. Setting accept_payment false and payment_link to null, returns the following data:

bookings: [
{
id: 42,
code: ‘1sky15a7v’,
start_datetime: ‘2024-02-27 14:00:00’,
end_datetime: ‘2024-02-27 15:00:00’,
location_id: null,
category_id: null,
service_id: 2,
provider_id: 2,
client_id: 36,
duration: null
}
],
batch: null,
invoice: null,
id: null

No order number and using the booking id is not working either. Accept_payment true, requires payment_processor.

Olaf Siebert wrote:

Please can you let me know why this is not working!!!