Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Allow 'paid_out' as a valid status for 'payment_confirmed' webhooks -…
Browse files Browse the repository at this point in the history
… allows old webhooks to be retried, which is useful sometimes.
  • Loading branch information
Rich Lott committed Nov 3, 2017
1 parent 75cad93 commit 0706bd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions CRM/GoCardless/Page/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function parseWebhookRequest($headers, $raw_payload) {
* instead of adding another.
*/
public function doPaymentsConfirmed($event) {
$payment = $this->getAndCheckGoCardlessPayment($event, 'confirmed');
$payment = $this->getAndCheckGoCardlessPayment($event, ['confirmed', 'paid_out']);
$recur = $this->getContributionRecurFromSubscriptionId($payment->links->subscription);

// Ensure that the recurring contribution record is set to In Progress.
Expand Down Expand Up @@ -204,7 +204,7 @@ public function doPaymentsConfirmed($event) {
* Process webhook for 'payments' resource type, action 'failed'.
*/
public function doPaymentsFailed($event) {
$payment = $this->getAndCheckGoCardlessPayment($event, 'confirmed');
$payment = $this->getAndCheckGoCardlessPayment($event, ['confirmed']);
$recur = $this->getContributionRecurFromSubscriptionId($payment->links->subscription);

// Ensure that the recurring contribution record is set to In Progress.
Expand Down Expand Up @@ -280,20 +280,22 @@ public function doSubscriptionsCancelled($event) {
*
* @throws CRM_GoCardless_WebhookEventIgnoredException
* @param array $event
* @param string $expected_status
* @param array $expected_status array of acceptable stati
* @return NULL|\GoCardless\Resources\Payment
*/
public function getAndCheckGoCardlessPayment($event, $expected_status) {
$gc_api = CRM_GoCardlessUtils::getApi($this->test_mode);
// According to GoCardless we need to check that the status of the object
// has not changed since the webhook was fired, so we re-load it and test.
$payment = $gc_api->payments()->get($event->links->payment);
if ($payment->status != $expected_status) {
if (!in_array($payment->status, $expected_status)) {
// Payment status is no longer confirmed, ignore this webhook.
throw new CRM_GoCardless_WebhookEventIgnoredException("Webhook out of date, expected status '$expected_status', got '{$payment->status}'");
throw new CRM_GoCardless_WebhookEventIgnoredException("Webhook out of date, expected status "
. implode("' or '", $expected_status)
. ", got '{$payment->status}'");
}

// We expect a subscription link, but not payments have this.
// We expect a subscription link, but not all payments have this.
if (empty($payment->links->subscription)) {
// This payment is not part of a subscription. Assume it's not of interest to us.
throw new CRM_GoCardless_WebhookEventIgnoredException("Ignored payment that does not belong to a subscription.");
Expand Down
2 changes: 1 addition & 1 deletion info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2017-01-16</releaseDate>
<version>1.2-beta</version>
<version>1.3-beta</version>
<develStage>beta</develStage>
<compatibility>
<ver>4.7</ver>
Expand Down

0 comments on commit 0706bd2

Please sign in to comment.