Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order status not updating when using ideal #724

Open
willemwg opened this issue Oct 9, 2022 · 3 comments
Open

Order status not updating when using ideal #724

willemwg opened this issue Oct 9, 2022 · 3 comments

Comments

@willemwg
Copy link

willemwg commented Oct 9, 2022

Hi,

I'm pretty new to web development, but I seem to have a problem using the mollie for woocommerce plugin. When placing an order and paying through mollie, woocommerce doesn't update the order status. It remains 'Waiting for payment' (wachtend op betaling). I tried several plugins to automatically update the order status, but couldn't find one that fixes this issue. Here the log for one of the orders I tried:

2022-10-09T08:04:57+00:00 DEBUG ideal: Start process_payment for order 2539
2022-10-09T08:04:58+00:00 DEBUG setUserMollieCustomerId: Stored Mollie customer ID cst_ujzh3Bi4e5 with user 3
2022-10-09T08:04:58+00:00 DEBUG getUserMollieCustomerId: Created a Mollie Customer (cst_ujzh3Bi4e5) for WordPress user with ID 3 (test).
2022-10-09T08:04:58+00:00 DEBUG mollie_wc_gateway_ideal: Create Mollie payment object for order 2539
2022-10-09T08:04:58+00:00 DEBUG Order 2539 returnUrl: https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&order_id=2539&filter_flag=onMollieReturn
2022-10-09T08:04:58+00:00 DEBUG Order 2539 webhookUrl: https://studiodotter.nl/wc-api/mollie_wc_gateway_ideal?order_id=2539&key=wc_order_5PB1LXaCIILj4&filter_flag
2022-10-09T08:04:58+00:00 DEBUG Creating payment object: type Order, first try creating a Mollie Order.
2022-10-09T08:04:58+00:00 DEBUG {"amount":{"currency":"EUR","value":"99.00"},"redirectUrl":"https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&order_id=2539&filter_flag=onMollieReturn","webhookUrl":"https://studiodotter.nl/wc-api/mollie_wc_gateway_ideal?order_id=2539&key=wc_order_5PB1LXaCIILj4&filter_flag","method":"ideal","payment":{"issuer":"ideal_INGBNL2A","customerId":"cst_ujzh3Bi4e5"},"locale":"nl_NL","metadata":{"order_id":2539,"order_number":"2539"},"orderNumber":"2539","lines":[{"sku":"2537","name":"Patroontekenen mouwen","quantity":1,"vatRate":0,"unitPrice":{"currency":"EUR","value":"99.00"},"totalAmount":{"currency":"EUR","value":"99.00"},"vatAmount":{"currency":"EUR","value":"0.00"},"discountAmount":{"currency":"EUR","value":"0.00"},"metadata":{"order_item_id":2}}]}
2022-10-09T08:04:58+00:00 DEBUG {"resource":"order","id":"ord_14iavy","profileId":"pfl_ezqypJdc25","mode":"test","amount":{"value":"99.00","currency":"EUR"},"amountCaptured":null,"amountRefunded":null,"status":"created","billingAddress":{"streetAndNumber":"Teststraat","postalCode":"1234AB","city":"Testerdam","country":"NL","givenName":"Truus","familyName":"test","email":"[email protected]"},"consumerDateOfBirth":null,"orderNumber":"2539","shippingAddress":null,"method":"ideal","locale":"nl_NL","metadata":{"order_id":2539,"order_number":"2539"},"isCancelable":false,"webhookUrl":"https://studiodotter.nl/wc-api/mollie_wc_gateway_ideal?order_id=2539&key=wc_order_5PB1LXaCIILj4&filter_flag","redirectUrl":"https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&order_id=2539&filter_flag=onMollieReturn","createdAt":"2022-10-09T08:04:58+00:00","expiresAt":"2022-11-06T08:04:58+00:00","expiredAt":null,"paidAt":null,"authorizedAt":null,"canceledAt":null,"completedAt":null,"lines":[{"resource":"orderline","id":"odl_2.mwg8vm","orderId":"ord_14iavy","name":"Patroontekenen mouwen","sku":"2537","type":"physical","status":"created","metadata":{"order_it2022-10-09T08:04:57+00:00 DEBUG ideal: Start process_payment for order 2539
2022-10-09T08:04:58+00:00 DEBUG setUserMollieCustomerId: Stored Mollie customer ID cst_ujzh3Bi4e5 with user 3
2022-10-09T08:04:58+00:00 DEBUG getUserMollieCustomerId: Created a Mollie Customer (cst_ujzh3Bi4e5) for WordPress user with ID 3 (test).
2022-10-09T08:04:58+00:00 DEBUG mollie_wc_gateway_ideal: Create Mollie payment object for order 2539
2022-10-09T08:04:58+00:00 DEBUG Order 2539 returnUrl: https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&order_id=2539&filter_flag=onMollieReturn
2022-10-09T08:04:58+00:00 DEBUG Order 2539 webhookUrl: https://studiodotter.nl/wc-api/mollie_wc_gateway_ideal?order_id=2539&key=wc_order_5PB1LXaCIILj4&filter_flag
2022-10-09T08:04:58+00:00 DEBUG Creating payment object: type Order, first try creating a Mollie Order.
2022-10-09T08:04:58+00:00 DEBUG {"amount":{"currency":"EUR","value":"99.00"},"redirectUrl":"https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&order_id=2539&filter_flag=onMollieReturn","webhookUrl":"https://studiodotter.nl/wc-api/mollie_wc_gateway_ideal?order_id=2539&key=wc_order_5PB1LXaCIILj4&filter_flag","method":"ideal","payment":{"issuer":"ideal_INGBNL2A","customerId":"cst_ujzh3Bi4e5"},"locale":"nl_NL","metadata":{"order_id":2539,"order_number":"2539"},"orderNumber":"2539","lines":[{"sku":"2537","name":"Patroontekenen mouwen","quantity":1,"vatRate":0,"unitPrice":{"currency":"EUR","value":"99.00"},"totalAmount":{"currency":"EUR","value":"99.00"},"vatAmount":{"currency":"EUR","value":"0.00"},"discountAmount":{"currency":"EUR","value":"0.00"},"metadata":{"order_item_id":2}}]}
2022-10-09T08:04:58+00:00 DEBUG {"resource":"order","id":"ord_14iavy","profileId":"pfl_ezqypJdc25","mode":"test","amount":{"value":"99.00","currency":"EUR"},"amountCaptured":null,"amountRefunded":null,"status":"created","billingAddress":{"streetAndNumber":"Teststraat","postalCode":"1234AB","city":"Testerdam","country":"NL","givenName":"Truus","familyName":"test","email":"[email protected]"},"consumerDateOfBirth":null,"orderNumber":"2539","shippingAddress":null,"method":"ideal","locale":"nl_NL","metadata":{"order_id":2539,"order_number":"2539"},"isCancelable":false,"webhookUrl":"https://studiodotter.nl/wc-api/mollie_wc_gateway_ideal?order_id=2539&key=wc_order_5PB1LXaCIILj4&filter_flag","redirectUrl":"https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&order_id=2539&filter_flag=onMollieReturn","createdAt":"2022-10-09T08:04:58+00:00","expiresAt":"2022-11-06T08:04:58+00:00","expiredAt":null,"paidAt":null,"authorizedAt":null,"canceledAt":null,"completedAt":null,"lines":[{"resource":"orderline","id":"odl_2.mwg8vm","orderId":"ord_14iavy","name":"Patroontekenen mouwen","sku":"2537","type":"physical","status":"created","metadata":{"order_item_id":2},"isCancelable":false,"quantity":1,"quantityShipped":0,"amountShipped":{"value":"0.00","currency":"EUR"},"quantityRefunded":0,"amountRefunded":{"value":"0.00","currency":"EUR"},"quantityCanceled":0,"amountCanceled":{"value":"0.00","currency":"EUR"},"shippableQuantity":0,"refundableQuantity":0,"cancelableQuantity":0,"unitPrice":{"value":"99.00","currency":"EUR"},"vatRate":"0.00","vatAmount":{"value":"0.00","currency":"EUR"},"totalAmount":{"value":"99.00","currency":"EUR"},"createdAt":"2022-10-09T08:04:58+00:00"}],"_links":{"self":{"href":"https://api.mollie.com/v2/orders/ord_14iavy","type":"application/hal+json"},"dashboard":{"href":"https://my.mollie.com/dashboard/org_3594394/orders/ord_14iavy","type":"text/html"},"checkout":{"href":"https://www.mollie.com/checkout/order/14iavy","type":"text/html"},"documentation":{"href":"https://docs.mollie.com/reference/v2/orders-api/create-order","type":"text/html"}},"_embedded":null,"shopperCountryMustMatchBillingCountry":false}
2022-10-09T08:04:59+00:00 DEBUG setUserMollieCustomerId: Stored Mollie customer ID cst_ujzh3Bi4e5 with user 3
2022-10-09T08:04:59+00:00 DEBUG ideal: Mollie payment object ord_14iavy (test) created for order 2539
2022-10-09T08:04:59+00:00 DEBUG For order 2539 redirect user to Mollie Checkout URL: https://www.mollie.com/checkout/order/14iavy
2022-10-09T08:05:08+00:00 DEBUG Mollie\WooCommerce\Gateway\MolliePaymentGateway::getReturnRedirectUrlForOrder 2539: Determine what the redirect URL in WooCommerce should be.
2022-10-09T08:05:08+00:00 DEBUG Mollie\WooCommerce\Payment\MollieOrderService::orderNeedsPayment mollie_wc_gateway_ideal: Order 2539 orderNeedsPayment check: yes, order not previously processed by Mollie gateway.
2022-10-09T08:05:08+00:00 DEBUG Mollie\WooCommerce\Payment\PaymentModule::onMollieReturn: Redirect url on return order mollie_wc_gateway_ideal, order 2539: https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&utm_nooverride=1em_id":2},"isCancelable":false,"quantity":1,"quantityShipped":0,"amountShipped":{"value":"0.00","currency":"EUR"},"quantityRefunded":0,"amountRefunded":{"value":"0.00","currency":"EUR"},"quantityCanceled":0,"amountCanceled":{"value":"0.00","currency":"EUR"},"shippableQuantity":0,"refundableQuantity":0,"cancelableQuantity":0,"unitPrice":{"value":"99.00","currency":"EUR"},"vatRate":"0.00","vatAmount":{"value":"0.00","currency":"EUR"},"totalAmount":{"value":"99.00","currency":"EUR"},"createdAt":"2022-10-09T08:04:58+00:00"}],"_links":{"self":{"href":"https://api.mollie.com/v2/orders/ord_14iavy","type":"application/hal+json"},"dashboard":{"href":"https://my.mollie.com/dashboard/org_3594394/orders/ord_14iavy","type":"text/html"},"checkout":{"href":"https://www.mollie.com/checkout/order/14iavy","type":"text/html"},"documentation":{"href":"https://docs.mollie.com/reference/v2/orders-api/create-order","type":"text/html"}},"_embedded":null,"shopperCountryMustMatchBillingCountry":false}
2022-10-09T08:04:59+00:00 DEBUG setUserMollieCustomerId: Stored Mollie customer ID cst_ujzh3Bi4e5 with user 3
2022-10-09T08:04:59+00:00 DEBUG ideal: Mollie payment object ord_14iavy (test) created for order 2539
2022-10-09T08:04:59+00:00 DEBUG For order 2539 redirect user to Mollie Checkout URL: https://www.mollie.com/checkout/order/14iavy
2022-10-09T08:05:08+00:00 DEBUG Mollie\WooCommerce\Gateway\MolliePaymentGateway::getReturnRedirectUrlForOrder 2539: Determine what the redirect URL in WooCommerce should be.
2022-10-09T08:05:08+00:00 DEBUG Mollie\WooCommerce\Payment\MollieOrderService::orderNeedsPayment mollie_wc_gateway_ideal: Order 2539 orderNeedsPayment check: yes, order not previously processed by Mollie gateway.
2022-10-09T08:05:08+00:00 DEBUG Mollie\WooCommerce\Payment\PaymentModule::onMollieReturn: Redirect url on return order mollie_wc_gateway_ideal, order 2539: https://studiodotter.nl/afrekenen/order-received/2539/?key=wc_order_5PB1LXaCIILj4&utm_nooverride=1

Thanks in advance for any help you might be able to provide!

@willemwg
Copy link
Author

willemwg commented Oct 9, 2022

After a bit of more research I think the issue might be caused by the fact that the site is not connected to it's final domain just yet. For now I use an edited host file to visit the IP where the site is hosted now. Mollie might not be able to sent it's payment confirmation message?

@InpsydeNiklas
Copy link
Collaborator

Mollie sends the webhook confirmation here:
Order 2539 webhookUrl: https://studiodotter.nl/wc-api/mollie_wc_gateway_ideal?order_id=2539&key=wc_order_5PB1LXaCIILj4&filter_flag
According to the logs, the webhook was not received, so the order remains in "Pending payment" status.
Could you give it a try with the regular site URL? Thanks!

@mvdhoek1
Copy link

mvdhoek1 commented Feb 1, 2023

@willemwg I've had the same problem as you. Maybe this one will help you out:

// Registering the hook
Hook::action('woocommerce_thankyou', 'App\Woocommerce\ThankyouController@handle');
<?php

namespace App\Woocommerce;

class ThankyouController
{
    protected string $mollieAPIKey;
    
    public function __construct()
    {
        $this->mollieAPIKey = env('MOLLIE_API_KEY', '');
    }

    /**
     * After a succesfull payment via iDeal the status of the order should be completed.
     * Unfortunately the status gets stuck on 'pending'.
     * Request the Mollie API and validate if the status is paid.
     * When it is, set status to 'completed'.
     */
    public function handle($orderID): void
    {
        $order = \wc_get_order($orderID);

        if (! $order instanceof \WC_Order || $order->get_status() !== 'pending') {
            return;
        }
        
        $paymentID = \get_post_meta($orderID, '_mollie_payment_id', true);

        if (empty($this->mollieAPIKey) || empty($paymentID)) {
            return;
        }

        $paymentDetails = $this->getPaymentDetails($paymentID);

        if (! $this->iDealPayment($paymentDetails)) {
            return;
        }

        if (! $this->statusIsPaid($paymentDetails)) {
            return;
        }

        $order->set_status('completed');
        $order->save();
    }

    protected function getPaymentDetails(string $paymentID): array
    {
        $url = sprintf('https://api.mollie.com/v2/payments/%s', $paymentID);
        $args = [
            'headers'     => [
                'Authorization' => sprintf('Bearer %s', $this->mollieAPIKey),
            ],
        ];

        $result = \wp_remote_get($url, $args);

        if (\is_wp_error($result)) {
            return [];
        }
        
        $body = json_decode(\wp_remote_retrieve_body($result), true);

        if (\is_wp_error($body)) {
            return [];
        }

        return $body;
    }

    protected function iDealPayment(array $paymentDetails): bool
    {
        $method = $paymentDetails['method'] ?? '';

        if ($method !== 'ideal') {
            return false;
        }

        return true;
    }

    protected function statusIsPaid(array $paymentDetails): bool
    {
        $status = $paymentDetails['status'] ?? '';

        if ($status !== 'paid') {
            return false;
        }

        return true;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants