WebhookUrl update in WordPress plugin results in fatal error: Uncaught Error: Call to undefined method Mollie\Api\Endpoints\SubscriptionEndpoint::update()
<p>I'm trying to update the webhookUrl in mollie for subscription. The old webhookUrl is obsolete and the programmers who made it are no longer with us. </p>
<p>Here is a link to the mollie I'm trying to use. After checking the new version on github, I found that the method of updating subscriptions is a little different. Despite the differences, I still get the error: </p>
<p>Fatal error: Uncaught error: Call to undefined method Mollie\Api\Endpoints\SubscriptionEndpoint::update()</p>
<p>This is the code I used to make the form. I'm trying to change the webhookUrl to connect to Easy digital Downloads so that the subscription and license don't expire because I can't check the payment. </p>
<p>Form (admin__update_subscription.php): </p>
<pre class="brush:php;toolbar:false;"><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></pre>
<p>表单处理程序:</p>
<pre class="brush:php;toolbar:false;">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
}</pre>
<p>莫莉更新请求:</p>
<pre class="brush:php;toolbar:false;">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;
}</pre>
<p>知道我缺少什么吗?我希望这会更新 webhookUrl,以便付款将自动连接到网站上的订阅。</p>