update billing_context to use hashed_ids

This commit is contained in:
David Bomba 2023-01-18 16:52:32 +11:00
parent a746384976
commit 0d767f7d98
12 changed files with 33 additions and 25 deletions

View File

@ -26,7 +26,7 @@ function isActive($page, bool $boolean = false)
$current_page = Route::currentRouteName();
$action = Route::currentRouteAction(); // string
$show = str_replace(['.show','payment_methodss','documentss','subscriptionss'],['s.index','payment_methods','documents','subscriptions'], $current_page);
$show = str_replace(['.show','payment_methodss','documentss','subscriptionss','paymentss'],['s.index','payment_methods','documents','subscriptions','payments'], $current_page);
if ($page == $current_page && $boolean) {
return true;

View File

@ -160,7 +160,7 @@ class PaymentController extends Controller
}
if (property_exists($payment_hash->data, 'billing_context')) {
$billing_subscription = \App\Models\Subscription::find($payment_hash->data->billing_context->subscription_id);
$billing_subscription = \App\Models\Subscription::find($this->decodePrimaryKey($payment_hash->data->billing_context->subscription_id));
return (new SubscriptionService($billing_subscription))->completePurchase($payment_hash);
}

View File

@ -403,10 +403,10 @@ class BillingPortalPurchase extends Component
->save();
Cache::put($this->hash, [
'subscription_id' => $this->subscription->id,
'subscription_id' => $this->subscription->hashed_id,
'email' => $this->email ?? $this->contact->email,
'client_id' => $this->contact->client->id,
'invoice_id' => $this->invoice->id,
'client_id' => $this->contact->client->hashed_id,
'invoice_id' => $this->invoice->hashed_id,
'context' => 'purchase',
'campaign' => $this->campaign,
], now()->addMinutes(60));

View File

@ -526,7 +526,7 @@ class BillingPortalPurchasev2 extends Component
}
$data = [
'client_id' => $this->contact->client->id,
'client_id' => $this->contact->client->hashed_id,
'date' => now()->format('Y-m-d'),
'invitations' => [[
'key' => '',
@ -547,10 +547,10 @@ class BillingPortalPurchasev2 extends Component
->save();
Cache::put($this->hash, [
'subscription_id' => $this->subscription->id,
'subscription_id' => $this->subscription->hashed_id,
'email' => $this->email ?? $this->contact->email,
'client_id' => $this->contact->client->id,
'invoice_id' => $this->invoice->id,
'client_id' => $this->contact->client->hashed_id,
'invoice_id' => $this->invoice->hashed_id,
'context' => 'purchase',
'campaign' => $this->campaign,
'bundle' => $this->bundle,
@ -567,8 +567,8 @@ class BillingPortalPurchasev2 extends Component
return $this->subscription->service()->startTrial([
'email' => $this->email ?? $this->contact->email,
'quantity' => $this->quantity,
'contact_id' => $this->contact->id,
'client_id' => $this->contact->client->id,
'contact_id' => $this->contact->hashed_id,
'client_id' => $this->contact->client->hashed_id,
'bundle' => $this->bundle,
]);
}

View File

@ -106,11 +106,11 @@ class SubscriptionPlanSwitch extends Component
]);
Cache::put($this->hash, [
'subscription_id' => $this->target->id,
'target_id' => $this->target->id,
'recurring_invoice' => $this->recurring_invoice->id,
'client_id' => $this->recurring_invoice->client->id,
'invoice_id' => $this->state['invoice']->id,
'subscription_id' => $this->target->hashed_id,
'target_id' => $this->target->hashed_id,
'recurring_invoice' => $this->recurring_invoice->hashed_id,
'client_id' => $this->recurring_invoice->client->hashed_id,
'invoice_id' => $this->state['invoice']->hashed_id,
'context' => 'change_plan',
now()->addMinutes(60), ]
);

View File

@ -319,7 +319,7 @@ class MatchBankTransactions implements ShouldQueue
});
}, 1);
}, 2);
if(!$this->invoice)
return;

View File

@ -289,7 +289,7 @@ class BaseDriver extends AbstractPaymentDriver
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
if (property_exists($this->payment_hash->data, 'billing_context') && $status == Payment::STATUS_COMPLETED) {
$billing_subscription = \App\Models\Subscription::find($this->payment_hash->data->billing_context->subscription_id);
$billing_subscription = \App\Models\Subscription::find($this->decodePrimaryKey($this->payment_hash->data->billing_context->subscription_id));
// To access campaign hash => $this->payment_hash->data->billing_context->campaign;
// To access campaign data => Cache::get(CAMPAIGN_HASH)

View File

@ -42,7 +42,7 @@ class ClientService
$this->client->balance += $amount;
$this->client->save();
}, 1);
}, 2);
}
catch (\Throwable $throwable) {
nlog("DB ERROR " . $throwable->getMessage());
@ -63,7 +63,7 @@ class ClientService
$this->client->paid_to_date += $paid_to_date;
$this->client->save();
}, 1);
}, 2);
}
catch (\Throwable $throwable) {
nlog("DB ERROR " . $throwable->getMessage());
@ -82,7 +82,7 @@ class ClientService
$this->client->paid_to_date += $amount;
$this->client->save();
}, 1);
}, 2);
return $this;

View File

@ -230,6 +230,14 @@ class InstantPayment
elseif($this->request->hash){
$hash_data['billing_context'] = Cache::get($this->request->hash);
}
elseif($old_hash = PaymentHash::where('fee_invoice_id', $first_invoice->id)->whereNull('payment_id')->first()) {
if(isset($old_hash->data->billing_context))
{
$hash_data['billing_context'] = $old_hash->data->billing_context;
}
}
$payment_hash = new PaymentHash;
$payment_hash->hash = Str::random(32);

View File

@ -51,7 +51,7 @@ class DeletePayment
}
}, 1);
}, 2);
return $this->payment;

View File

@ -167,7 +167,7 @@ class SubscriptionService
public function startTrial(array $data)
{
// Redirects from here work just fine. Livewire will respect it.
$client_contact = ClientContact::find($data['contact_id']);
$client_contact = ClientContact::find($this->decodePrimaryKey($data['contact_id']));
if(!$this->subscription->trial_enabled)
return new \Exception("Trials are disabled for this product");
@ -734,7 +734,7 @@ class SubscriptionService
{
nlog("handle plan change");
$old_recurring_invoice = RecurringInvoice::find($payment_hash->data->billing_context->recurring_invoice);
$old_recurring_invoice = RecurringInvoice::find($this->decodePrimaryKey($payment_hash->data->billing_context->recurring_invoice));
if(!$old_recurring_invoice)
return $this->handleRedirect('/client/recurring_invoices/');

View File

@ -28,7 +28,7 @@ trait SubscriptionHooker
];
if(!isset($subscription->webhook_configuration['post_purchase_url']) && !isset($subscription->webhook_configuration['post_purchase_rest_method']))
return;
return [];
if (count($subscription->webhook_configuration['post_purchase_headers']) >= 1) {
$headers = array_merge($headers, $subscription->webhook_configuration['post_purchase_headers']);