Merge branch '801-handle-failed-paymongo-payments' into 'master'

Attempt to re-enable paymongo webhook if found disabled #801

Closes #801

See merge request jankstudio/resq!916
This commit is contained in:
Ramon Gutierrez 2024-06-05 21:51:18 +00:00
commit cec648f894
2 changed files with 19 additions and 2 deletions

View file

@ -55,9 +55,21 @@ class ProcessLatePaymongoTransactionsCommand extends Command
return 0;
} else {
$output->writeln('<comment>Webhook is disabled! Logging event and proceeding...</comment>');
$output->writeln('<comment>Webhook is disabled! Logging event and attempting to re-enable...</comment>');
$this->paymongo->log('WEBHOOK', "[]", json_encode($webhook['response'], JSON_PRETTY_PRINT), 'webhook');
// attempt re-enabling of webhook
$result = $this->paymongo->enableWebhook($this->webhook_id);
if ($result['success'] && $result['response']['data']['attributes']['status'] ?? null === 'enabled') {
$output->writeln('<info>Webhook ' . $this->webhook_id . ' re-enabled!</info>');
// log event
$this->paymongo->log('WEBHOOK RE-ENABLED', "[]", json_encode($result['response'], JSON_PRETTY_PRINT), 'webhook');
} else {
$output->writeln('<comment>Webhook ' . $this->webhook_id . ' could not be re-enabled.</comment>');
// log event
$this->paymongo->log('WEBHOOK FAILURE', "[]", json_encode($result['response'], JSON_PRETTY_PRINT), 'webhook');
}
}
}

View file

@ -79,6 +79,11 @@ class PayMongoConnector
return $this->doRequest('/v1/webhooks/'. $id, 'GET');
}
public function enableWebhook($id)
{
return $this->doRequest('/v1/webhooks/' . $id . '/enable', 'POST');
}
protected function generateHash()
{
return base64_encode($this->secret_key);