I’m integrating PayPal payments into my Go application and facing a TRANSACTION_REFUSED error when trying to capture a payment after the order is approved. The flow I’m using is:
- Create an order and get the approval URL.
- Redirect the user to PayPal for payment approval.
- Capture the payment after the user is redirected back to my application.
The order creation and approval process works fine, but capturing the payment fails with a TRANSACTION_REFUSED error. This issue persists even when using the official PayPal Postman collections.
Here is the error Message:
{“name”:”UNPROCESSABLE_ENTITY”,”details”:[{“issue”:”TRANSACTION_REFUSED”,”description”:”The
request was refused”}],”message”:”The requested action could not be
performed, semantically incorrect, or failed business
validation.”,”debug_id”:”ad4544e57e520″}
Steps Taken:
- Verified the capture URL is correct.
- Checked that the server can reach external APIs, as the order creation API call succeeds.
- Ensured the access token is valid and not expired.
- Attempted the API call using Postman to isolate the issue from my application code.
Here is my code for capturing the order (if its needed)
func (pp *PaypalPayment) CaptureOrder() (bool, error) {
client := &http.Client{}
paypalOrderId := pp.OrderToken
captureOrderUrl := strings.Replace(PAYPAL_CAPTURE_ORDER_URL, ":order_id", paypalOrderId, -1)
log.Println("CAPTURE ORDER URL: ", captureOrderUrl)
var requestBody *strings.Reader
requestBody = strings.NewReader("")
BearerToken := "Bearer " + pp.AccessToken
req, err := http.NewRequest("POST", captureOrderUrl, requestBody)
if err != nil {
log.Println("ERROR CREATING THE REQUEST - ", err)
return false, err
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", BearerToken)
req.Header.Add("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
log.Println("ERROR SENDING THE REQUEST - ", err)
return false, err
}
defer resp.Body.Close()
// Additional code to handle the response
}