简体   繁体   中英

Fatal error: Uncaught Error: Call to undefined method Mollie\Api\Endpoints\SubscriptionEndpoint::update() in Wordpress plugin for WebhookUrl update

I'm trying to update the webhookUrl in mollie for a subscription. The old webhookUrl is outdated and the programmer who made it is no longer with us.

This is the link of mollie that I'm trying to use. After checking the new version on github I saw that the method to update a subscription is a little different. Even though the differences, I still get an error:

Fatal error: Uncaught Error: Call to undefined method Mollie\Api\Endpoints\SubscriptionEndpoint::update()

This is the code I made to make a form out of it. I am attempting to change the webhookUrl to connect to Easy digital Downloads so that the subscriptions and licenses don't expire because the payment can't be checked.

Form(admin__update_subscription.php):

<form id="wmcs-form" method="post">
    <div class="wmcs_admin_card">
        <div class="wmcs_admin_body">
            <fieldset class="choose-theme-wrap radio-boxes dp-tabular">
                <ul>
                    <li>
                        <label>Customer id</label>
                        <input type="text" id="customer_id" name="customer_id" value="" required>
                    </li>
                    <li>
                        <label>Subscription id</label>
                        <input type="text" id="subscription_id" name="subscription_id" value="" required>
                    </li>
                    <li>
                        <label>Webhook URL</label>
                        <input type="text" id="webhook_url" name="webhook_url" value="" required>
                    </li>
                    <li>
                        <button type="submit" class="button-primary" name="mollie_update_subscription">Change</button>
                    </li>
                </ul>
            </fieldset><!-- End of choose-theme-wrap -->    
        </div><!-- End of wmcs_admin_body -->
    </div><!-- End of wmcs_admin_card -->
</form>

Form handler:

public function change_subscription(){ ?>
        <div class="wrap">
        <?php
            if(isset($_POST['mollie_update_subscription'])){
                if(!empty($_POST['customer_id']) && !empty($_POST['subscription_id'])){
                    $customer_id = sanitize_text_field($_POST['customer_id']);
                    $subscription_id = sanitize_text_field($_POST['subscription_id']);
                    $webhook_url = sanitize_text_field($_POST['webhook_url']);
                    // $orderID = sanitize_text_field($_POST['order_id']);
                    // $orderKey = sanitize_text_field($_POST['order_key']);

                    echo $this->mollie_update_subscription($customer_id, $subscription_id, $webhook_url);
                }
            }
        ?>
        <h2><?php _e('Change Subscription URL'); ?></h2>
        <div id="Features" class="wmcs-tabs">
            <?php
                require_once('admin__update_subscription.php');
            ?>
        </div> <!-- End of Settings -->
        <?php
    }

Mollie update request:

public function mollie_update_subscription($customer_id, $subscription_id, $webhook_url){
        $mollie = new \Mollie\Api\MollieApiClient();
        $mollie->setApiKey(MOLLIE_KEY);(defined elsewhere)

        $message = "";
        try {
            $customer = $mollie->customers->get($customer_id);
            $subscription = $customer->getSubscription($subscription_id);

            $subscription->webhookUrl = $webhook_url;
            $subscription->description = 'subscription update success';
            
            $mollie->subscriptions->update();

            $message = "<p>Subscription updated: " . $subscription->id . "</p>";
        } catch (\Mollie\Api\Exceptions\ApiException $e) {
            $message = "<div class='alert alert-danger' role='alert'>API call failed: " . htmlspecialchars($e->getMessage()).'</div>';
        }
        return $message;
    }

Any idea's what I'm missing? I was hoping this will update the webhookUrl so that payments will be automatically connected to the subscription on the website.

Found the solution. I needed to change this part:

$mollie->subscriptions->update();

to

$subscription->update();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM