mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Updates for paypal flow
This commit is contained in:
parent
0f8737bdf7
commit
850c5e8f94
@ -188,6 +188,10 @@ class BillingPortalPurchase extends Component
|
|||||||
|
|
||||||
public ?string $contact_email;
|
public ?string $contact_email;
|
||||||
|
|
||||||
|
public ?string $client_city;
|
||||||
|
|
||||||
|
public ?string $client_postal_code;
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
MultiDB::setDb($this->db);
|
MultiDB::setDb($this->db);
|
||||||
@ -203,7 +207,7 @@ class BillingPortalPurchase extends Component
|
|||||||
if (request()->query('coupon')) {
|
if (request()->query('coupon')) {
|
||||||
$this->coupon = request()->query('coupon');
|
$this->coupon = request()->query('coupon');
|
||||||
$this->handleCoupon();
|
$this->handleCoupon();
|
||||||
} elseif (strlen($this->subscription->promo_code) == 0 && $this->subscription->promo_discount > 0) {
|
} elseif (strlen($this->subscription->promo_code ?? '') == 0 && $this->subscription->promo_discount > 0) {
|
||||||
$this->price = $this->subscription->promo_price;
|
$this->price = $this->subscription->promo_price;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,10 +339,6 @@ class BillingPortalPurchase extends Component
|
|||||||
{
|
{
|
||||||
$this->contact = $contact;
|
$this->contact = $contact;
|
||||||
|
|
||||||
if ($contact->showRff()) {
|
|
||||||
return $this->rff();
|
|
||||||
}
|
|
||||||
|
|
||||||
Auth::guard('contact')->loginUsingId($contact->id, true);
|
Auth::guard('contact')->loginUsingId($contact->id, true);
|
||||||
|
|
||||||
if ($this->subscription->trial_enabled) {
|
if ($this->subscription->trial_enabled) {
|
||||||
@ -351,11 +351,20 @@ class BillingPortalPurchase extends Component
|
|||||||
if ((int)$this->price == 0) {
|
if ((int)$this->price == 0) {
|
||||||
$this->steps['payment_required'] = false;
|
$this->steps['payment_required'] = false;
|
||||||
} else {
|
} else {
|
||||||
$this->steps['fetched_payment_methods'] = true;
|
// $this->steps['fetched_payment_methods'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->methods = $contact->client->service()->getPaymentMethods($this->price);
|
$this->methods = $contact->client->service()->getPaymentMethods($this->price);
|
||||||
|
|
||||||
|
foreach($this->methods as $method){
|
||||||
|
|
||||||
|
if($method['is_paypal'] == '1' && !$this->steps['check_rff']){
|
||||||
|
$this->rff();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$this->heading_text = ctrans('texts.payment_methods');
|
$this->heading_text = ctrans('texts.payment_methods');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -366,6 +375,8 @@ class BillingPortalPurchase extends Component
|
|||||||
$this->contact_first_name = $this->contact->first_name;
|
$this->contact_first_name = $this->contact->first_name;
|
||||||
$this->contact_last_name = $this->contact->last_name;
|
$this->contact_last_name = $this->contact->last_name;
|
||||||
$this->contact_email = $this->contact->email;
|
$this->contact_email = $this->contact->email;
|
||||||
|
$this->client_city = $this->contact->client->city;
|
||||||
|
$this->client_postal_code = $this->contact->client->postal_code;
|
||||||
|
|
||||||
$this->steps['check_rff'] = true;
|
$this->steps['check_rff'] = true;
|
||||||
|
|
||||||
@ -377,13 +388,20 @@ class BillingPortalPurchase extends Component
|
|||||||
$validated = $this->validate([
|
$validated = $this->validate([
|
||||||
'contact_first_name' => ['required'],
|
'contact_first_name' => ['required'],
|
||||||
'contact_last_name' => ['required'],
|
'contact_last_name' => ['required'],
|
||||||
|
'client_city' => ['required'],
|
||||||
|
'client_postal_code' => ['required'],
|
||||||
'contact_email' => ['required', 'email'],
|
'contact_email' => ['required', 'email'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->contact->first_name = $validated['contact_first_name'];
|
$this->contact->first_name = $validated['contact_first_name'];
|
||||||
$this->contact->last_name = $validated['contact_last_name'];
|
$this->contact->last_name = $validated['contact_last_name'];
|
||||||
$this->contact->email = $validated['contact_email'];
|
$this->contact->email = $validated['contact_email'];
|
||||||
$this->contact->save();
|
$this->contact->client->postal_code = $validated['client_postal_code'];
|
||||||
|
$this->contact->client->city = $validated['client_city'];
|
||||||
|
|
||||||
|
$this->contact->pushQuietly();
|
||||||
|
|
||||||
|
$this->steps['fetched_payment_methods'] = true;
|
||||||
|
|
||||||
return $this->getPaymentMethods($this->contact);
|
return $this->getPaymentMethods($this->contact);
|
||||||
}
|
}
|
||||||
@ -395,7 +413,7 @@ class BillingPortalPurchase extends Component
|
|||||||
* @param $company_gateway_id
|
* @param $company_gateway_id
|
||||||
* @param $gateway_type_id
|
* @param $gateway_type_id
|
||||||
*/
|
*/
|
||||||
public function handleMethodSelectingEvent($company_gateway_id, $gateway_type_id)
|
public function handleMethodSelectingEvent($company_gateway_id, $gateway_type_id, $is_paypal = false)
|
||||||
{
|
{
|
||||||
$this->company_gateway_id = $company_gateway_id;
|
$this->company_gateway_id = $company_gateway_id;
|
||||||
$this->payment_method_id = $gateway_type_id;
|
$this->payment_method_id = $gateway_type_id;
|
||||||
|
@ -251,11 +251,11 @@ class PayPalBasePaymentDriver extends BaseDriver
|
|||||||
[
|
[
|
||||||
"address" =>
|
"address" =>
|
||||||
[
|
[
|
||||||
"address_line_1" => strlen($this->client->shipping_address1) > 1 ? $this->client->shipping_address1 : $this->client->address1,
|
"address_line_1" => strlen($this->client->shipping_address1 ?? '') > 1 ? $this->client->shipping_address1 : $this->client->address1,
|
||||||
"address_line_2" => $this->client->shipping_address2,
|
"address_line_2" => $this->client->shipping_address2,
|
||||||
"admin_area_2" => strlen($this->client->shipping_city) > 1 ? $this->client->shipping_city : $this->client->city,
|
"admin_area_2" => strlen($this->client->shipping_city ?? '') > 1 ? $this->client->shipping_city : $this->client->city,
|
||||||
"admin_area_1" => strlen($this->client->shipping_state) > 1 ? $this->client->shipping_state : $this->client->state,
|
"admin_area_1" => strlen($this->client->shipping_state ?? '') > 1 ? $this->client->shipping_state : $this->client->state,
|
||||||
"postal_code" => strlen($this->client->shipping_postal_code) > 1 ? $this->client->shipping_postal_code : $this->client->postal_code,
|
"postal_code" => strlen($this->client->shipping_postal_code ?? '') > 1 ? $this->client->shipping_postal_code : $this->client->postal_code,
|
||||||
"country_code" => $this->client->present()->shipping_country_code(),
|
"country_code" => $this->client->present()->shipping_country_code(),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
@ -88,7 +88,7 @@ class SubscriptionService
|
|||||||
|
|
||||||
|
|
||||||
// if we have a recurring product - then generate a recurring invoice
|
// if we have a recurring product - then generate a recurring invoice
|
||||||
if (strlen($this->subscription->recurring_product_ids) >= 1) {
|
if (strlen($this->subscription->recurring_product_ids ?? '') >= 1) {
|
||||||
if (isset($payment_hash->data->billing_context->bundle)) {
|
if (isset($payment_hash->data->billing_context->bundle)) {
|
||||||
$recurring_invoice = $this->convertInvoiceToRecurringBundle($payment_hash->payment->client_id, $payment_hash->data->billing_context->bundle);
|
$recurring_invoice = $this->convertInvoiceToRecurringBundle($payment_hash->payment->client_id, $payment_hash->data->billing_context->bundle);
|
||||||
} else {
|
} else {
|
||||||
@ -1024,10 +1024,10 @@ class SubscriptionService
|
|||||||
$invoice->subscription_id = $this->subscription->id;
|
$invoice->subscription_id = $this->subscription->id;
|
||||||
$invoice->is_proforma = true;
|
$invoice->is_proforma = true;
|
||||||
|
|
||||||
if (strlen($data['coupon']) >= 1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0) {
|
if (strlen($data['coupon'] ?? '') >= 1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0) {
|
||||||
$invoice->discount = $this->subscription->promo_discount;
|
$invoice->discount = $this->subscription->promo_discount;
|
||||||
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
|
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
|
||||||
} elseif (strlen($this->subscription->promo_code) == 0 && $this->subscription->promo_discount > 0) {
|
} elseif (strlen($this->subscription->promo_code ?? '') == 0 && $this->subscription->promo_discount > 0) {
|
||||||
$invoice->discount = $this->subscription->promo_discount;
|
$invoice->discount = $this->subscription->promo_discount;
|
||||||
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
|
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
|
||||||
}
|
}
|
||||||
@ -1118,7 +1118,7 @@ class SubscriptionService
|
|||||||
*/
|
*/
|
||||||
public function triggerWebhook($context)
|
public function triggerWebhook($context)
|
||||||
{
|
{
|
||||||
if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url']) < 1) { //@phpstan-ignore-line
|
if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url'] ?? '') < 1) { //@phpstan-ignore-line
|
||||||
return ["message" => "Success", "status_code" => 200];
|
return ["message" => "Success", "status_code" => 200];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1436,7 +1436,7 @@ class SubscriptionService
|
|||||||
*/
|
*/
|
||||||
public function handleNoPaymentFlow(Invoice $invoice, $bundle, ClientContact $contact)
|
public function handleNoPaymentFlow(Invoice $invoice, $bundle, ClientContact $contact)
|
||||||
{
|
{
|
||||||
if (strlen($this->subscription->recurring_product_ids) >= 1) {
|
if (strlen($this->subscription->recurring_product_ids ?? '') >= 1) {
|
||||||
$recurring_invoice = $this->convertInvoiceToRecurringBundle($contact->client_id, collect($bundle)->map(function ($bund) {
|
$recurring_invoice = $this->convertInvoiceToRecurringBundle($contact->client_id, collect($bundle)->map(function ($bund) {
|
||||||
return (object) $bund;
|
return (object) $bund;
|
||||||
}));
|
}));
|
||||||
@ -1492,7 +1492,7 @@ class SubscriptionService
|
|||||||
*/
|
*/
|
||||||
private function handleRedirect($default_redirect)
|
private function handleRedirect($default_redirect)
|
||||||
{
|
{
|
||||||
if (array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url']) >= 1) {
|
if (array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url'] ?? '') >= 1) {
|
||||||
return method_exists(redirect(), "send") ? redirect($this->subscription->webhook_configuration['return_url'])->send() : redirect($this->subscription->webhook_configuration['return_url']);
|
return method_exists(redirect(), "send") ? redirect($this->subscription->webhook_configuration['return_url'])->send() : redirect($this->subscription->webhook_configuration['return_url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,12 +141,15 @@
|
|||||||
<input type="hidden" name="contact_first_name" value="{{ $contact->first_name }}">
|
<input type="hidden" name="contact_first_name" value="{{ $contact->first_name }}">
|
||||||
<input type="hidden" name="contact_last_name" value="{{ $contact->last_name }}">
|
<input type="hidden" name="contact_last_name" value="{{ $contact->last_name }}">
|
||||||
<input type="hidden" name="contact_email" value="{{ $contact->email }}">
|
<input type="hidden" name="contact_email" value="{{ $contact->email }}">
|
||||||
|
<input type="hidden" name="client_city" value="{{ $contact->client->city }}">
|
||||||
|
<input type="hidden" name="client_postal_code" value="{{ $contact->client->postal_code }}">
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@if($steps['started_payment'] == false)
|
@if($steps['started_payment'] == false)
|
||||||
@foreach($this->methods as $method)
|
@foreach($this->methods as $method)
|
||||||
<button
|
<button
|
||||||
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}'); $wire.$refresh(); "
|
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}', '{{ $method['is_paypal'] }}'); $wire.$refresh(); "
|
||||||
class="px-3 py-2 border rounded mr-4 hover:border-blue-600">
|
class="px-3 py-2 border rounded mr-4 hover:border-blue-600">
|
||||||
{{ $method['label'] }}
|
{{ $method['label'] }}
|
||||||
</button>
|
</button>
|
||||||
@ -189,27 +192,41 @@
|
|||||||
<form wire:submit="handleRff">
|
<form wire:submit="handleRff">
|
||||||
@csrf
|
@csrf
|
||||||
|
|
||||||
@if(strlen($contact->first_name) === 0)
|
@if(strlen($contact->first_name ?? '') === 0)
|
||||||
<div class="col-auto mt-3">
|
<div class="col-auto mt-3">
|
||||||
<label for="first_name" class="input-label">{{ ctrans('texts.first_name') }}</label>
|
<label for="first_name" class="input-label">{{ ctrans('texts.first_name') }}</label>
|
||||||
<input id="first_name" class="input w-full" wire:model="contact_first_name" />
|
<input id="first_name" class="input w-full" wire:model="contact_first_name" />
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(strlen($contact->last_name) === 0)
|
@if(strlen($contact->last_name ?? '') === 0)
|
||||||
<div class="col-auto mt-3 @if($contact->last_name) !== 0) hidden @endif">
|
<div class="col-auto mt-3 @if($contact->last_name) !== 0) hidden @endif">
|
||||||
<label for="last_name" class="input-label">{{ ctrans('texts.last_name') }}</label>
|
<label for="last_name" class="input-label">{{ ctrans('texts.last_name') }}</label>
|
||||||
<input id="last_name" class="input w-full" wire:model="contact_last_name" />
|
<input id="last_name" class="input w-full" wire:model="contact_last_name" />
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(strlen($contact->email) === 0)
|
@if(strlen($contact->email ?? '') === 0)
|
||||||
<div class="col-auto mt-3 @if($contact->email) !== 0) hidden @endif">
|
<div class="col-auto mt-3 @if($contact->email) !== 0) hidden @endif">
|
||||||
<label for="email" class="input-label">{{ ctrans('texts.email') }}</label>
|
<label for="email" class="input-label">{{ ctrans('texts.email') }}</label>
|
||||||
<input id="email" class="input w-full" wire:model="contact_email" />
|
<input id="email" class="input w-full" wire:model="contact_email" />
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if(strlen($client_postal_code ?? '') === 0)
|
||||||
|
<div class="col-auto mt-3 @if($client_postal_code) !== 0) hidden @endif">
|
||||||
|
<label for="postal_code" class="input-label">{{ ctrans('texts.postal_code') }}</label>
|
||||||
|
<input id="postal_code" class="input w-full" wire:model="client_postal_code" />
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if(strlen($client_city ?? '') === 0)
|
||||||
|
<div class="col-auto mt-3 @if($client_city) !== 0) hidden @endif">
|
||||||
|
<label for="city" class="input-label">{{ ctrans('texts.city') }}</label>
|
||||||
|
<input id="city" class="input w-full" wire:model="client_city" />
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="button button-block bg-primary text-white mt-4">
|
class="button button-block bg-primary text-white mt-4">
|
||||||
|
@ -318,7 +318,7 @@
|
|||||||
@foreach($methods as $method)
|
@foreach($methods as $method)
|
||||||
<button
|
<button
|
||||||
x-on:click="buttonDisabled = true" x-bind:disabled="buttonDisabled"
|
x-on:click="buttonDisabled = true" x-bind:disabled="buttonDisabled"
|
||||||
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}')"
|
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}', '{{ $method['is_paypal'] }}')"
|
||||||
class="relative -ml-px inline-flex items-center space-x-2 rounded border border-gray-300 bg-gray-50 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-100 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500">
|
class="relative -ml-px inline-flex items-center space-x-2 rounded border border-gray-300 bg-gray-50 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-100 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500">
|
||||||
{{ $method['label'] }}
|
{{ $method['label'] }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
@if(!$state['payment_initialised'])
|
@if(!$state['payment_initialised'])
|
||||||
@foreach($this->methods as $method)
|
@foreach($this->methods as $method)
|
||||||
<button
|
<button
|
||||||
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}'); $wire.$refresh();"
|
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}', '{{ $method['is_paypal'] }}'); $wire.$refresh();"
|
||||||
class="px-3 py-2 border bg-white rounded mr-4 hover:border-blue-600">
|
class="px-3 py-2 border bg-white rounded mr-4 hover:border-blue-600">
|
||||||
{{ $method['label'] }}
|
{{ $method['label'] }}
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user