5.8: Create a Payment for an Order

In this section, we will guide you through the process of initiating a payment for an existing order using the Golfdigg OTA API. This will return a payment URL that you can redirect your customer to in order to complete the payment.

5.8.1: Endpoint

To create a payment, you will use the following endpoint:

  • Endpoint: /api/v1/ext/order/payment
  • Method: POST

5.8.2: Request Parameters

In your API request, include the following:

  • Authorization (Header): Use Basic Authentication with your API credentials.
  • Content-Type (Header): application/json

Request Body:

FieldTypeRequiredDescription
orderIdstringYesThe unique identifier of the order to be paid.
platformstringYesThe platform initiating the payment. Currently only WEBSITE is supported.
sourceTypestringYesThe payment source type. Currently only CARD is supported.
cardNostringNoThe card number. Pass an empty string if not applicable.
returnUrlstringYesThe URL to redirect the customer to after the payment process is completed.

5.8.3: Response Format

This API returns a payment URL object containing the information needed to redirect the customer to complete payment.

interface PaymentUrl {
  webURL: string;           // The web URL to redirect the customer to
  webMethod: string;        // HTTP method to use when redirecting
  appURL: string;           // Deep link URL for mobile app redirection
  webParams: string | null; // Additional parameters for web redirection, if any
}
FieldTypeDescription
webURLstringThe web URL to redirect the customer to for payment completion.
webMethodstringThe HTTP method to use for the redirect. May be empty.
appURLstringA deep link URL for mobile app redirection. May be empty.
webParamsstring / nullAdditional encoded parameters for the web redirect, if required.

5.8.4: Request Example

Here's an example of how to structure your API request to create a payment:

POST /api/v1/ext/order/payment
Host: ota-api.golfdigg.com
Authorization: Basic base64_encoded(apiKey)
Content-Type: application/json

{
  "orderId": "6a201150faa1002654967b93",
  "platform": "WEBSITE",
  "sourceType": "CARD",
  "cardNo": "",
  "returnUrl": "https://your-platform.com/payment/callback"
}

5.8.5: Response Example

The API will respond with a payment URL object. Here's a sample response:

{
  "webURL": "https://stg-newpayweb.ais.co.th:8443/template_whitelabel/#/init?token=0e768a48ca884b7a9407b8f23eaa0c9f&channelName=SuperDuperCWDC",
  "webMethod": "",
  "appURL": "",
  "webParams": null
}

5.8.6: Handling the Payment Redirect

Once you receive the response, redirect the customer to the webURL returned in the response. The customer will complete their card payment on the hosted payment page. After the payment is completed or cancelled, they will be redirected back to the returnUrl you provided in the request.

5.8.7: Handling Errors

In case of errors, you may receive an error response with a relevant HTTP status code and an error message. Common error scenarios include:

  • Invalid or already-paid orderId
  • Missing or invalid returnUrl

Handle errors based on the HTTP status code and the error message provided in the response.