Reputation: 9
I have implemented Square Up to create payments and refunds through the API. Both implementations look good but the refunds come as "Pending".
I'm trying to implement a webhook to update the payment on my end but I can't find a good example on how the workflow should work.
Also, is there a way to query for a particular refund by ID every X minutes to find the refund status instead of implementing the hook?
Thanks
Upvotes: 0
Views: 427
Reputation: 127
Please check it. I suggest streamdata instead of webhook.
//Create refunds
var client = new RestClient("https://connect.squareup.com/v2/locations/{{location_id}}/transactions/{{transaction_id}}/refund");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer {{access_token}}");
request.AddParameter("application/json", "{\n \"idempotency_key\": \"YOUR_IDEMPOTENCY_KEY\",\n \"tender_id\": \"TENDER_ID\",\n \"reason\": \"a reason\",\n \"amount_money\": {\n \"amount\": 100,\n \"currency\": \"USD\"\n }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
//List refunds
var client = new RestClient("https://connect.squareup.com/v2/locations/{{location_id}}/refunds");
var request = new RestRequest(Method.GET);
request.AddHeader("postman-token", "");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("authorization", "Bearer {{access_token}}");
IRestResponse response = client.Execute(request);
Upvotes: 1
Reputation: 36
The webhooks API only posts refunds that are completed, not pending. You can poll for the state of a refund using the retrieve transactions endpoint. This response of this endpoint includes all refunds for the given transaction.
Upvotes: 2