Merge pull request #5853 from beganovich/v5-2805-tracking-campaign-source

(v5) Passing campaign data into payment flow
This commit is contained in:
Benjamin Beganović 2021-06-01 16:32:34 +02:00 committed by GitHub
commit c61a94f2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 81 deletions

View File

@ -162,6 +162,13 @@ class BillingPortalPurchase extends Component
*/
public $passwordless_login_btn = false;
/**
* Campaign reference.
*
* @var string|null
*/
public $campaign;
public function mount()
{
$this->price = $this->subscription->price;
@ -332,7 +339,7 @@ class BillingPortalPurchase extends Component
$is_eligible = $this->subscription->service()->isEligible($this->contact);
if ($is_eligible['exception']['message'] != 'Success') {
if (is_array($is_eligible) && $is_eligible['exception']['message'] != 'Success') {
$this->steps['not_eligible'] = true;
$this->steps['not_eligible_message'] = $is_eligible['exception']['message'];
$this->steps['show_loading_bar'] = false;
@ -346,8 +353,8 @@ class BillingPortalPurchase extends Component
'client_id' => $this->contact->client->id,
'invoice_id' => $this->invoice->id,
'context' => 'purchase',
now()->addMinutes(60)]
);
'campaign' => $this->campaign,
], now()->addMinutes(60));
$this->emit('beforePaymentEventsCompleted');
}

View File

@ -244,6 +244,10 @@ class BaseDriver extends AbstractPaymentDriver
if (property_exists($this->payment_hash->data, 'billing_context')) {
$billing_subscription = \App\Models\Subscription::find($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)
// To access utm data => session()->get('utm-' . CAMPAIGN_HASH);
(new SubscriptionService($billing_subscription))->completePurchase($this->payment_hash);
}

View File

@ -630,8 +630,7 @@ class SubscriptionService
*/
public function triggerWebhook($context)
{
/* If no webhooks have been set, then just return gracefully */
if(!array_key_exists('post_purchase_url', $this->subscription->webhook_configuration) || !array_key_exists('post_purchase_rest_method', $this->subscription->webhook_configuration)) {
if (empty($this->subscription->webhook_configuration['post_purchase_url']) || empty($this->subscription->webhook_configuration['post_purchase_rest_method'])) {
return true;
}

View File

@ -2,7 +2,7 @@
@section('meta_title', ctrans('texts.purchase'))
@section('body')
@livewire('billing-portal-purchase', ['subscription' => $subscription, 'contact' => auth('contact')->user(), 'hash' => $hash, 'request_data' => $request_data])
@livewire('billing-portal-purchase', ['subscription' => $subscription, 'contact' => auth('contact')->user(), 'hash' => $hash, 'request_data' => $request_data, 'campaign' => request()->query('campaign') ?? null])
@stop
@push('footer')