Subscription Module Update

Payment codes changes and fix paypal payment failed
This commit is contained in:
Leonard Biano
2024-08-29 23:48:19 +08:00
parent 3116110c44
commit 9dc58d6fc6
13 changed files with 143 additions and 61 deletions
@@ -307,11 +307,11 @@ class PaypalWebhookController extends Controller
$subscription = CustomerSubscription::with('planPrice')->where('txn_id',$webhookData['resource']['id'])->first();
if($subscription){
if($subscription->planPrice->billing_type == 'Recurring' && isset($webhookData['billing_info']['next_billing_time'])) {
if($subscription->planPrice->billing_type == 'Recurring' && isset($webhookData['resource']['billing_info']['next_billing_time'])) {
$period_end = $webhookData['billing_info']['next_billing_time'];
$subscription->expired_at = Carbon::parse($period_end)->toDateTimeString();
$subscription->next_payment_at = Carbon::parse($period_end)->toDateTimeString();
$subscription->last_payment_date = isset($webhookData['billing_info']['last_payment']['time']) ? Carbon::parse($webhookData['billing_info']['last_payment']['time'])->format('Y-m-d') : null;
$subscription->last_payment_date = isset($webhookData['resource']['billing_info']['last_payment']['time']) ? Carbon::parse($webhookData['resource']['billing_info']['last_payment']['time'])->format('Y-m-d') : null;
$subscription->save();
}
@@ -328,7 +328,7 @@ class PaypalWebhookController extends Controller
$subscription->payment_status = 'failed';
$this->sendPaymentFailed($subscription->user->email, null, null);
$this->sendPaymentFailedForSales($subscription->user->email, null, null, $response['amount_due']);
$this->sendPaymentFailedForSales($subscription->user->email, null, null, isset($webhookData['resource']['billing_info']['last_failed_payment']['amount']['value']) ? $webhookData['resource']['billing_info']['last_failed_payment']['amount']['value'] : $subscription->planPrice->price);
} else if($event == 'BILLING.SUBSCRIPTION.CANCELLED'){