Remove fullfilled listener from gocardless webhook

This commit is contained in:
David Bomba 2024-12-05 20:12:00 +11:00
parent a1278e783d
commit 98450f434d
1 changed files with 37 additions and 37 deletions

View File

@ -323,53 +323,53 @@ class GoCardlessPaymentDriver extends BaseDriver
//after i resolve the payment hash, ensure the invoice has not been marked as paid and the payment does not already exist.
//if it does exist, ensure it is completed and not pending.
if ($event['action'] == 'fulfilled' && array_key_exists('billing_request', $event['links'])) {
$hash = PaymentHash::whereJsonContains('data->billing_request', $event['links']['billing_request'])->first();
// if ($event['action'] == 'fulfilled' && array_key_exists('billing_request', $event['links'])) {
// $hash = PaymentHash::whereJsonContains('data->billing_request', $event['links']['billing_request'])->first();
if (!$hash) {
nlog("GoCardless: couldn't find a hash, need to abort => Billing Request => " . $event['links']['billing_request']);
return response()->json([], 200);
}
// if (!$hash) {
// nlog("GoCardless: couldn't find a hash, need to abort => Billing Request => " . $event['links']['billing_request']);
// return response()->json([], 200);
// }
$this->setPaymentHash($hash);
// $this->setPaymentHash($hash);
$billing_request = $this->gateway->billingRequests()->get(
$event['links']['billing_request']
);
// $billing_request = $this->gateway->billingRequests()->get(
// $event['links']['billing_request']
// );
$payment = $this->gateway->payments()->get(
$billing_request->payment_request->links->payment
);
// $payment = $this->gateway->payments()->get(
// $billing_request->payment_request->links->payment
// );
if ($billing_request->status === 'fulfilled') {
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($hash->invoices(), 'invoice_id')))->withTrashed()->get();
// if ($billing_request->status === 'fulfilled') {
// $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($hash->invoices(), 'invoice_id')))->withTrashed()->get();
$this->client = $invoices->first()->client;
// $this->client = $invoices->first()->client;
$invoices->each(function ($invoice) {
//if payments exist already, they just need to be confirmed.
if ($invoice->payments()->exists()) {
$invoice->payments()->where('status_id', 1)->cursor()->each(function ($payment) {
$payment->status_id = 4;
$payment->save();
});
}
});
// $invoices->each(function ($invoice) {
// //if payments exist already, they just need to be confirmed.
// if ($invoice->payments()->exists()) {
// $invoice->payments()->where('status_id', 1)->cursor()->each(function ($payment) {
// $payment->status_id = 4;
// $payment->save();
// });
// }
// });
// remove all paid invoices
$invoices->filter(function ($invoice) {
return $invoice->isPayable();
});
// // remove all paid invoices
// $invoices->filter(function ($invoice) {
// return $invoice->isPayable();
// });
//return early if nothing to do
if ($invoices->count() == 0) {
nlog("GoCardless: Could not harvest any invoices - probably all paid!!");
return response()->json([], 200);
}
// //return early if nothing to do
// if ($invoices->count() == 0) {
// nlog("GoCardless: Could not harvest any invoices - probably all paid!!");
// return response()->json([], 200);
// }
$this->processSuccessfulPayment($payment);
}
}
// $this->processSuccessfulPayment($payment);
// }
// }
}
return response()->json([], 200);