mollie-api-php icon indicating copy to clipboard operation
mollie-api-php copied to clipboard

Non-existent query parameter "testmode" for this API call

Open bobbybouwmann opened this issue 5 years ago • 17 comments

Specifications

  • API Version: 2.12.1

Describe the issue

I'm trying to revoke an existing mandate using the revoke method on the mandate resource I get back from the API. According to the documentation, the testmode parameter should be send along: https://docs.mollie.com/reference/v2/mandates-api/revoke-mandate#parameters

However, I get the following error back

"Error executing API call (422: Unprocessable Entity): Non-existent query parameter "testmode" for this API call.. Field: testmode. Documentation: https://docs.mollie.com/guides/handling-errors"

My code looks like this.

$mandates = $this->mollieApiClient->mandates->listForId($customerId, null, null, [
    'testmode' => $this->testmode,
]);

foreach ($mandates as $mandate) {
    $mandate->revoke();
}

Fetching the mandates works as expected. As you can see I call the invoke method on the Mandate resource. This method looks like this:

public function revoke()
{
    if (!isset($this->_links->self->href)) {
        return $this;
    }

    $body = null;
    if($this->client->L()) {
        $body = json_encode([
            "testmode" => $this->mode === "test" ? true : false
        ]);
    }

    $result = $this->client->performHttpCallToFullUrl(
        MollieApiClient::HTTP_DELETE,
        $this->_links->self->href,
        $body
    );

    return $result;
}

Should all be good, but I still get above mentioned error.

Any clues of what's going on?

bobbybouwmann avatar Jan 21 '20 11:01 bobbybouwmann

Can you dump the mandate contents here?

sandervanhooft avatar Jan 21 '20 11:01 sandervanhooft

Right now my best guess is the testmode parameter should not be set on the request body (bug in revoke method). Also, it should already be included on the self link in the mandate response.

sandervanhooft avatar Jan 21 '20 11:01 sandervanhooft

So the problem is that this is a DELETE route. Because of that, we need to post the testmode in the body. Like you said, the ?testmode=true is appended to the URL, which is not allowed according to the error message for this endpoint.

Right now we have a URL that looks like this

https://api.mollie.com/v2/customers/cst_R9r23aF7Ku/mandates/mdt_Av5nsfq23G?testmode=true

And then with the revoke method, we DELETE the resource also appending the testmode stuff.

So now, we need to strip the testmode=true from the URL ourselves. I can't imagine that we are the only one doing this and that there are no tests for this 🤔

Possible solutions are accepting the testmode in the URL or the library should strip of this testmode=true for this specific endpoint.

bobbybouwmann avatar Jan 21 '20 13:01 bobbybouwmann

@willemstuursma can you weigh in on this?

sandervanhooft avatar Jan 21 '20 13:01 sandervanhooft

@sandervanhooft Thanks for the quick reply! Really appreciated

bobbybouwmann avatar Jan 21 '20 19:01 bobbybouwmann

Same thing with the update method on the Payment resource.

I want to update a description of the payment, but the following code fails with the exact same error:

$payment = $this->client->payments->get('some-payment-id', [
    'testmode' => true,
]);

// payment is found...

$payment->description = 'updated description';
$payment->update(); // this fails...

crnkovic avatar Jan 22 '20 08:01 crnkovic

Mollie is investigating it on their end.

sandervanhooft avatar Jan 22 '20 10:01 sandervanhooft

Possible solutions are accepting the testmode in the URL or the library should strip of this testmode=true for this specific endpoint.

Discussed it with @willemstuursma , primary part of the solution will be Mollie accepting testmode on these urls.

sandervanhooft avatar Jan 31 '20 15:01 sandervanhooft

Looking into it, writing a whole new set of integration tests for this.

@bobbybouwmann consider using this for now (confirmed to work):

$customer->revokeMandate($mandate->id);

sandervanhooft avatar Feb 02 '20 09:02 sandervanhooft

@sandervanhooft Awesome! Thanks for all the work you put into this!

bobbybouwmann avatar Feb 02 '20 10:02 bobbybouwmann

Integration tested all(!) endpoints with OAuth (Organization Access Token) today. 😅

The goal was to find out what calls are breaking with OAuth, or could do without having to pass in the testmode setting manually.

Working on a PR here: #443 .

The client still breaks using some endpoints in test mode because the _links.self includes the test mode query parameter. These are:

  • Customer PATCH
  • Customer Mandate DELETE
  • Order PATCH
  • Order Line PATCH
  • Order Line DELETE
  • Order Shipment PATCH
  • Payment PATCH
  • Refund PATCH

sandervanhooft avatar Feb 03 '20 17:02 sandervanhooft

☝️ @willemstuursma I'll release the PR tomorrow. Let me know if you need my help on the above.

sandervanhooft avatar Feb 03 '20 17:02 sandervanhooft

Additionally, Order Line PATCH will require some API changes as well:

  • include self link on OrderLine Resource
  • include mode on OrderLine Resource

sandervanhooft avatar Feb 04 '20 10:02 sandervanhooft

I see that the PR has already been merged, but the same problem seems to occur when calling cancel on a subscription that was created with testmode set to true.

$subscription = $mollie->subscriptions->getForId($mollieCustomerId, $mollieSubscriptionId, ['testmode' => $mollieSettings->isTestMode()]);
$cancelledSubscription = $subscription->cancel();

The code above also results in an Error executing API call (422: Unprocessable Entity): Non-existent query parameter "testmode" for this API call.. Field: testmode. exception.

ronaldtb avatar Mar 17 '21 13:03 ronaldtb

When operating in the testmode using OAuth, remember to setAccessToken() before issuing other commands.

boryn avatar Mar 23 '21 09:03 boryn

Error executing API call (422: Unprocessable Entity): The payment cannot be cancelled. Documentation: https://docs.mollie.com/guides/handling-errors

I get this error when I try to delete a payment (a payment that is cancelable):

        if ($payment && $payment->isCancelable)
        {
            $api->payments->cancel($paymentId, ['testmode' => !runningAppInProduction()]);
        }

The weird thing is, the payment is actually cancelled, so there shouldn't be any exception.

I'm using v2.31.1

Loots-it avatar May 14 '21 14:05 Loots-it

@Loots-it that's a different topic.

Please open a separate ticket in this repository or contact Mollie support with a description of the issue, your account id, profile id and the payment id being used.

sandervanhooft avatar May 14 '21 14:05 sandervanhooft