Magento 2 REST API For Place Order gives "transaction declined" error after successful Payment For Payfort Payment Gateway

I am using Payfort extension to process credit Card Payments online for Payfort Payment Gateway. For Website it’s working Fine and Placing an order after successful payment.

But when I am trying to place an order via API after successful payment via it’s iOs/Android SDK.
It’s giving me this Error.

Transaction has been declined. Please try again later.

This is How I am passing each information I received from Payfort after Successful Payment in this API.




"billingAddress": {
"city": "Dubai",
"countryId": "AE",
"customerAddressId": "2885",
"customerId": "3438",
"fax": "+971521231234",
"firstname": "Test",
"lastname": "User",
"postcode": "1111",
"region": "Dubai",
"regionCode": "DXB",
"regionId": "597",
"street": [
"Street 44, Oud Maitha"
"telephone": "+971521231234"
"cartId": "24361",
"paymentMethod": {
"additional_data": {
"amount": "29995",
"authorization_code": "614835",
"card_number": "411111******1111",
"card_holder_name": "Test User ",
"customer_email": "[email protected]",
"customer_ip": "",
"expiry_date": "2102",
"fort_id": "169996200000452654",
"is_active_payment_token_enabler": false,
"merchant_reference": "XXXXXXXX",
"payment_option": "VISA",
"sdk_token": "c85bf903408b45a19a194710a941607a",
"token_name": "82f62b316c3246908ba29c8f2e683f45"
"method": "md_payfort"

I am getting "True" in the response of this API call.

Then, I am using Create Order API of Magento to Place an Order.




"paymentMethod": {
"method": "md_payfort"
"shippingMethod": {
"additionalProperties": {},
"carrier_code": "freeshipping",
"method_code": "freeshipping"

After debug, I found that this error is coming from this file.


And it’s because the "execute" method in this class is sending the Payment request again to Payfort and they receive the "Signature mismatch" error from Payfort because of the unauthorized request. It should not send the Payment request again to Payfort.
I am not able to figure out how to prevent Magento to make this Payment request and just Place the Order.

If anyone can help me out to solve this problem and place an order successfully would be really appreciated.

Magento Asked by Shahzad H. on February 17, 2021

1 Answers

One Answer

Even thought I have done lots of work on the checkout API have never used the endpoint /V1/carts/mine/order.

The normal way to place an order in my experience is to make a POST to /V1/carts/mine/payment-information (or for guest carts /V1/guest-carts/:cartId/payment-information). Both of these map to the method savePaymentInformationAndPlaceOrder which additionally removes the need for a 2nd API call after saving the payment data.

Take a look here which gives a great breakdown of the entire process.

I hope this helps.

Answered by Craig on February 17, 2021

Add your own answers!

Related Questions

magento 2 javascript certification exam (dump)

1  Asked on October 1, 2021 by the-light


How to change new subscriber pop-up message?

1  Asked on October 1, 2021 by dylan-heathcote


Edit creditmemo template pdf

2  Asked on October 1, 2021 by fdasfa


Less CSS inlining error

1  Asked on October 1, 2021 by ishaq


Customer connect to magento2 from cakephp

0  Asked on October 1, 2021 by anis-agrebi


Ask a Question

Get help from others!

© 2021 All rights reserved.