Refund a payment
curl --request POST \
--url https://api.primepay.mw/v1/payments/{reference}/refunds \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"amount": 5000,
"reason": "Order cancelled"
}
'import requests
url = "https://api.primepay.mw/v1/payments/{reference}/refunds"
payload = {
"amount": 5000,
"reason": "Order cancelled"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({amount: 5000, reason: 'Order cancelled'})
};
fetch('https://api.primepay.mw/v1/payments/{reference}/refunds', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.primepay.mw/v1/payments/{reference}/refunds",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount' => 5000,
'reason' => 'Order cancelled'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.primepay.mw/v1/payments/{reference}/refunds"
payload := strings.NewReader("{\n \"amount\": 5000,\n \"reason\": \"Order cancelled\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.primepay.mw/v1/payments/{reference}/refunds")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": 5000,\n \"reason\": \"Order cancelled\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.primepay.mw/v1/payments/{reference}/refunds")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": 5000,\n \"reason\": \"Order cancelled\"\n}"
response = http.request(request)
puts response.read_body{
"reference": "RFD-6b1f3c0e9d2a4e7f8c5b1a2d3e4f6a7b",
"payment": "<string>",
"status": "processing",
"amount": 5000,
"currency": "MWK",
"reason": "Order cancelled",
"providerReference": "<string>",
"failureCode": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"completedAt": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "insufficient_funds",
"message": "Not enough available balance for MWK 25,000.00.",
"field": "<string>"
}
}{
"error": {
"code": "insufficient_funds",
"message": "Not enough available balance for MWK 25,000.00.",
"field": "<string>"
}
}{
"error": {
"code": "insufficient_funds",
"message": "Not enough available balance for MWK 25,000.00.",
"field": "<string>"
}
}Refunds
Refund a payment
Sends money back to the number that paid. Leave out amount to refund everything still refundable. Needs a full secret key.
Guide: refunds and refund errors.
POST
/
v1
/
payments
/
{reference}
/
refunds
Refund a payment
curl --request POST \
--url https://api.primepay.mw/v1/payments/{reference}/refunds \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"amount": 5000,
"reason": "Order cancelled"
}
'import requests
url = "https://api.primepay.mw/v1/payments/{reference}/refunds"
payload = {
"amount": 5000,
"reason": "Order cancelled"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({amount: 5000, reason: 'Order cancelled'})
};
fetch('https://api.primepay.mw/v1/payments/{reference}/refunds', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.primepay.mw/v1/payments/{reference}/refunds",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount' => 5000,
'reason' => 'Order cancelled'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.primepay.mw/v1/payments/{reference}/refunds"
payload := strings.NewReader("{\n \"amount\": 5000,\n \"reason\": \"Order cancelled\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.primepay.mw/v1/payments/{reference}/refunds")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": 5000,\n \"reason\": \"Order cancelled\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.primepay.mw/v1/payments/{reference}/refunds")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": 5000,\n \"reason\": \"Order cancelled\"\n}"
response = http.request(request)
puts response.read_body{
"reference": "RFD-6b1f3c0e9d2a4e7f8c5b1a2d3e4f6a7b",
"payment": "<string>",
"status": "processing",
"amount": 5000,
"currency": "MWK",
"reason": "Order cancelled",
"providerReference": "<string>",
"failureCode": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"completedAt": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "insufficient_funds",
"message": "Not enough available balance for MWK 25,000.00.",
"field": "<string>"
}
}{
"error": {
"code": "insufficient_funds",
"message": "Not enough available balance for MWK 25,000.00.",
"field": "<string>"
}
}{
"error": {
"code": "insufficient_funds",
"message": "Not enough available balance for MWK 25,000.00.",
"field": "<string>"
}
}Authorizations
Your API key: sk_live_… / sk_test_… (secret), pk_live_… / pk_test_… (publishable, read-only reference data) or rk_live_… / rk_test_… (payments only).
Headers
A new value for every new request (a UUID is ideal), up to 64 characters. If your request times out, send it again with the same key. The same key for a different request returns 422 idempotency_key_reused.
Maximum string length:
64Example:
"3c9a7e1f2b6d4a8e9f0c1b2a3d4e5f60"
Path Parameters
The payment's reference.
Body
application/json
Response
The refund.
Example:
"RFD-6b1f3c0e9d2a4e7f8c5b1a2d3e4f6a7b"
The refunded payment.
Available options:
processing, success, failed Example:
5000
Example:
"MWK"
Example:
"Order cancelled"
Was this page helpful?

