question

nathaniel-hamilton avatar image
nathaniel-hamilton asked nathaniel-hamilton commented

PHP cURL call to delete an order not working through REST API

We're trying to delete an open order through clover's REST API when a payment fails in the E-commerce API. We call the REST API several times; to create the order, add a customer, and add a line item, and all of the calls are successful except the delete order call. We're not getting any error messages from the cURL or from clover, but the orders are created and left open when they should be deleted. Below is the PHP cURL code we are using to try to delete the order:



$url = "https://sandbox.dev.clover.com/v3/merchants/$Merchant_ID/orders/$order_id?access_token=$Oauth_Token";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5000);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPGET, false);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");

        $contents = curl_exec($ch);
        if (curl_errno($ch)) {
            echo curl_error($ch);
            echo "<br><br />";
            $contents = '';
        } else {

            json_decode($contents, true);
            if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
                echo "Error: " . $contents["message"] . "<br>";
            }

            curl_close($ch);
        }

        echo "Error: card declined; failed to pay for order<br>";


OrdersREST API
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered nathaniel-hamilton commented

This is possibly a sync issue. You are deleting the order immediately after the payment was rejected. The theory is that when the payment syncs from our authorization server it is essentially overwriting the delete. Can you inject a delay before you make the delete call to prove this?

3 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

nathaniel-hamilton avatar image nathaniel-hamilton commented ·

We tested it after a short delay and it deletes the order properly, thank you. we were attempting to delete the order directly after the payment so I think it was really a sync issue. For now, I guess we have to have an external script that runs periodically to delete the orders that were declined so as to not leave open orders on a merchant's report.

0 Likes 0 ·
David Marginian avatar image David Marginian ♦♦ nathaniel-hamilton commented ·

I have created an internal issue on our end as well. It doesn't seem like a sync should overwrite the deleted order.

0 Likes 0 ·
nathaniel-hamilton avatar image nathaniel-hamilton David Marginian ♦♦ commented ·

If it helps the developers, we were also creating the order milliseconds before we were trying to delete it. Basically, we get the card token from the clover e-commerce iframe, create and order, add the line items and customer to the order, attempt to pay for the order using the card token, and if the payment fails, we immediately tried to delete the order we created. it ends up being 6 different cURL calls in a span of a few milliseconds so a sync issue makes sense.

0 Likes 0 ·
nathaniel-hamilton avatar image
nathaniel-hamilton answered David Marginian Deactivated converted comment to answer

When calling the REST API we're getting a http response of 200.

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image David Marginian ♦♦ commented ·

In a private (moderators only) post please include the order id.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community