Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/job-board.corals.io/Corals/modules/Payment/PayPal/Job/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/job-board.corals.io/Corals/modules/Payment/PayPal/Job/HandleInvoicePaymentFailed.php
<?php

namespace Corals\Modules\Payment\PayPal\Job;


use Carbon\Carbon;
use Corals\Modules\Payment\Common\Models\WebhookCall;
use Corals\Modules\Payment\PayPal\Exception\PayPalWebhookFailed;
use Corals\Modules\Subscriptions\Models\Subscription;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class HandleInvoicePaymentFailed implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /**
     * @var \Corals\Modules\Payment\Common\Models\WebhookCall
     */
    public $webhookCall;

    /**
     * HandleInvoiceCreated constructor.
     * @param WebhookCall $webhookCall
     */
    public function __construct(WebhookCall $webhookCall)
    {
        $this->webhookCall = $webhookCall;
    }

    public function handle()
    {
        logger('Invoice Payment Failed');
        if ($this->webhookCall->processed) {
            throw PayPalWebhookFailed::processedCall($this->webhookCall);
        }

        $payload = $this->webhookCall->payload;

        if (is_array($payload) && isset($payload['resource'])) {
            $invoiceObject = $payload['resource'];
            if (isset($invoiceObject['billing_agreement_id']) && $invoiceObject['billing_agreement_id']) {
                $subscription = Subscription::where('subscription_reference', $invoiceObject['billing_agreement_id'])->first();

                if (!$subscription) {
                    throw PayPalWebhookFailed::invalidPayPalSubscription($this->webhookCall);
                }

                $invoiceCode = $invoiceObject['id'];
                $invoice = Invoice::whereCode($invoiceCode)->first();

                if (!$invoice) {
                    $invoice = Invoice::create([
                        'code' => $invoiceObject['id'],
                        'currency' => $invoiceObject['amount']['currency'],
                        'description' => $payload['summary'],
                        'sub_total' => ($invoiceObject['amount']['total']),
                        'total' => ($invoiceObject['amount']['total']),
                        'user_id' => $subscription->user_id,
                        'invoicable_id' => $subscription->id,
                        'invoicable_type' => Subscription::class,
                        'due_date' => Carbon::parse($invoiceObject['create_time']),
                        'invoice_date' => now(),
                    ]);
                }
                $invoice->markAsFailed();

            }
        }


        $this->webhookCall->markAsProcessed();
    }
}

Spamworldpro Mini