| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\PaymentMethods\PayPalGateway\API; |
| 4 |
|
| 5 |
use FluentCart\App\Helpers\Helper; |
| 6 |
use FluentCart\App\Services\FrontendView; |
| 7 |
use FluentCart\App\Vite; |
| 8 |
use FluentCart\Framework\Foundation\App; |
| 9 |
use FluentCart\Framework\Support\Arr; |
| 10 |
|
| 11 |
class PayPalPartnerRenderer |
| 12 |
{ |
| 13 |
|
| 14 |
protected $mode; |
| 15 |
|
| 16 |
public function __construct($mode) |
| 17 |
{ |
| 18 |
if (!$mode) { |
| 19 |
echo '<div class="fct_message fct_message_error">' . esc_html__('Invalid PayPal payment mode. Please try configuring paypal payment gateway again expected mode test or live !', 'fluent-cart') . '</div>'; |
| 20 |
die(); |
| 21 |
} |
| 22 |
|
| 23 |
$this->mode = $mode; |
| 24 |
} |
| 25 |
|
| 26 |
public function render($data) |
| 27 |
{ |
| 28 |
$this->template($data); |
| 29 |
die(); |
| 30 |
} |
| 31 |
|
| 32 |
public function getMode() |
| 33 |
{ |
| 34 |
return $this->mode; |
| 35 |
} |
| 36 |
|
| 37 |
public function scriptJs(): string |
| 38 |
{ |
| 39 |
if ($this->mode == 'test') { |
| 40 |
return 'https://www.sandbox.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js'; |
| 41 |
} |
| 42 |
return 'https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js'; |
| 43 |
} |
| 44 |
|
| 45 |
public function template($data) |
| 46 |
{ |
| 47 |
$mode = Arr::get($data, 'mode', false); |
| 48 |
if (!$mode) { |
| 49 |
return; |
| 50 |
} |
| 51 |
$paypalPartner = new PayPalPartner($mode); |
| 52 |
|
| 53 |
|
| 54 |
try { |
| 55 |
$redirectUrl = $paypalPartner->sellerOnboarding(); |
| 56 |
|
| 57 |
if (is_wp_error($redirectUrl)) { |
| 58 |
FrontendView::renderNotFoundPage( |
| 59 |
__('Error', 'fluent-cart'), |
| 60 |
__('Error', 'fluent-cart'), |
| 61 |
__('Please setup your store country and currency first. ', 'fluent-cart') . '<a href="' . admin_url('admin.php?page=fluent-cart#/settings/store-settings/') . '">' . __('Settings', 'fluent-cart') . '</a>', |
| 62 |
|
| 63 |
__('Go Back to the Store', 'fluent-cart'), |
| 64 |
null, |
| 65 |
admin_url('admin.php?page=fluent-cart#/settings/payments') |
| 66 |
); |
| 67 |
die(); |
| 68 |
} |
| 69 |
|
| 70 |
} catch (\Exception $exception) { |
| 71 |
FrontendView::renderNotFoundPage( |
| 72 |
__('Unable To connect with PayPal.', 'fluent-cart'), |
| 73 |
__('Please try again in a moment.', 'fluent-cart'), '', |
| 74 |
__('Go Back to the Store', 'fluent-cart'), |
| 75 |
null, |
| 76 |
admin_url('admin.php?page=fluent-cart#/settings/payments') |
| 77 |
); |
| 78 |
die(); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
$logo = Vite::getAssetUrl('images/logo/logo-full-dark.svg'); |
| 83 |
$baseUrl = admin_url('admin.php?page=fluent-cart#/'); |
| 84 |
|
| 85 |
|
| 86 |
App::make('view')->render('paypal.authenticate', [ |
| 87 |
'url' => $redirectUrl, |
| 88 |
'scriptJs' => $this->scriptJs(), |
| 89 |
'mode' => $mode, |
| 90 |
'rest' => Helper::getRestInfo(), |
| 91 |
'logo' => $logo, |
| 92 |
'admin_url' => $baseUrl |
| 93 |
]); |
| 94 |
} |
| 95 |
} |
| 96 |
|