Re: Pre-authorization use case

7640
New Contributor

Pre-authorization use case

Hi,

 

We are developing a product for hotel online check-in and checkout. After checkout, sometimes we need to charge more fee for broken item.

Do you have any API related to the pre-authorization of a payment when the final amount is unknown?

 

Thank you,

Hao Vo

 

1 REPLY 1
API_Products
Visa Developer Support Specialist

Re: Pre-authorization use case

Hey @7640,

 

Yes, the Visa Developer Platform provides APIs that can handle pre-authorization use cases, such as the scenario you described for hotel online check-in and checkout. The Visa Direct and Visa Payment Control APIs can be used for such purposes where the final amount may be unknown at the time of pre-authorization.

 

Here's a general approach you can take:

Steps for Pre-authorization

1. Initiate a Pre-authorization: You can use the `pre-authorization` feature to place a hold on a certain amount on the card.

2. Capture the Final Amount: Once the final amount is known (e.g., after checkout when additional charges are determined), you can capture the final amount.

3. Release the Hold: If the final charge is less than the pre-authorized amount, the remaining hold can be released.

 

Visa Direct API Overview

Visa Direct APIs can be used for funds transfers and managing pre-authorizations. Below is an example of how you might initiate a pre-authorization using Visa Direct:

```csharp
// START 
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

public class VisaPreAuthorization
{
private static readonly HttpClient client = new HttpClient();

public static async Task Main(string[] args)
{
var baseUrl = "https://sandbox.api.visa.com/visadirect/preauthorize/v1/preauth";
var apiKey = "YOUR_API_KEY";
var sharedSecret = "YOUR_SHARED_SECRET";

var requestBody = new
{
amount = "50.00", // Pre-authorized amount
currency = "USD",
cardNumber = "4111111111111111",
expiryMonth = "12",
expiryYear = "2023",
cvv2 = "123",
cardHolderName = "John Doe",
merchantCategoryCode = "3501", // Hotel/Motel
merchantReference = "REF123456789"
};

var jsonString = JsonConvert.SerializeObject(requestBody);
var content = new StringContent(jsonString, Encoding.UTF8, "application/json");

client.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes($"{apiKey}:{sharedSecret}")));

var response = await client.PostAsync(baseUrl, content);
var responseString = await response.Content.ReadAsStringAsync();

Console.WriteLine(responseString);
}
}
// END 
```

 

Steps to Follow:

1. Replace `YOUR_API_KEY` and `YOUR_SHARED_SECRET` with your actual API Key and Shared Secret.

2. Pre-authorization Amount: Set an appropriate pre-authorization amount that you expect to cover potential charges.

3. Endpoint URL: Ensure the `baseUrl` points to the correct Visa Direct pre-authorization endpoint.

 

Capturing the Final Amount

Once the final amount is determined, you can capture the pre-authorized amount using the `capture` endpoint provided by Visa.

 

Releasing the Hold

If the final charge is less than the pre-authorized amount, you can use the `reverse` endpoint to release the remaining hold.

 

For more detailed guidance and specific API endpoints, refer to the Visa Developer Portal at https://developer.visa.com/. Additionally, consult the Visa Developer documentation for more comprehensive information on handling pre-authorizations, captures, and reversals. 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.