| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Payments\PaymentMethods\Stripe\Components; |
| 4 |
|
| 5 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 6 |
use FluentForm\App\Services\FormBuilder\BaseFieldManager; |
| 7 |
use FluentForm\App\Modules\Payments\PaymentMethods\Stripe\StripeSettings; |
| 8 |
|
| 9 |
if (!defined('ABSPATH')) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
class StripeInline extends BaseFieldManager |
| 14 |
{ |
| 15 |
/** |
| 16 |
* This is not a standalone editor components |
| 17 |
* rather just a frontend rendering. |
| 18 |
*/ |
| 19 |
public function __construct() |
| 20 |
{ |
| 21 |
parent::__construct( |
| 22 |
'stripe_inline', |
| 23 |
'Inline Stripe Payment Method', |
| 24 |
['payment methods', 'payment', 'methods', 'stripe', 'stripe inline'], |
| 25 |
'payments' |
| 26 |
); |
| 27 |
|
| 28 |
add_filter('fluentform/payment_method_contents_stripe', array($this, 'maybePushPaymentInputs'), 10, 4); |
| 29 |
} |
| 30 |
|
| 31 |
public function maybePushPaymentInputs($inlineContents, $method, $data, $form) |
| 32 |
{ |
| 33 |
if (ArrayHelper::get($method, 'settings.embedded_checkout.value') !== 'yes') { |
| 34 |
return $inlineContents; |
| 35 |
} |
| 36 |
|
| 37 |
add_filter('fluentform/form_class', function ($classes, $targetForm) use ($form) { |
| 38 |
if ($form->instance_index == $targetForm->instance_index) { |
| 39 |
$classes .= ' ff_has_stripe_inline'; |
| 40 |
} |
| 41 |
|
| 42 |
return $classes; |
| 43 |
}, 10, 2); |
| 44 |
|
| 45 |
$elementId = $data['attributes']['name'] . '_' . $form->id . '_' . $form->instance_index . '_stripe_inline'; |
| 46 |
$label = ArrayHelper::get($method, 'settings.option_label.value', __('Pay with Stripe', 'fluentform')); |
| 47 |
$display = $method['is_default'] ? 'block' : 'none'; |
| 48 |
|
| 49 |
$markup = '<div class="stripe-inline-wrapper ff_pay_inline ff_pay_inline_stripe" style="display: ' . $display . '">'; |
| 50 |
$markup .= '<div class="ff-el-input--label">'; |
| 51 |
$markup .= '<label for="' . $elementId . '">' . $label . '</label>'; |
| 52 |
$markup .= '</div>'; |
| 53 |
|
| 54 |
$attributes = [ |
| 55 |
'name' => 'stripe_card_element', |
| 56 |
'class' => 'ff_stripe_card_element ff-el-form-control', |
| 57 |
'data-wpf_payment_method' => 'stripe', |
| 58 |
'id' => $elementId, |
| 59 |
'data-checkout_style' => 'embedded_form', |
| 60 |
'data-verify_zip' => ArrayHelper::get($method, 'settings.verify_zip.value') === 'yes' |
| 61 |
]; |
| 62 |
|
| 63 |
$markup .= '<div ' . $this->buildAttributes($attributes) . '></div>'; |
| 64 |
$markup .= '<div class="ff_card-errors text-danger" role="alert"></div>'; |
| 65 |
|
| 66 |
if (!StripeSettings::isLive($form->id)) { |
| 67 |
$stripeTestModeMessage = __('Stripe test mode activated', 'fluentform'); |
| 68 |
$markup .= '<span style="margin-top: 5px;padding: 0;font-style: italic;font-size: 12px">' . $stripeTestModeMessage . '</span>'; |
| 69 |
} |
| 70 |
|
| 71 |
$markup .= '</div>'; |
| 72 |
|
| 73 |
return $inlineContents . $markup; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* We don't need to return anything from here |
| 79 |
*/ |
| 80 |
function getComponent() |
| 81 |
{ |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* We don't need to return anything from here |
| 86 |
*/ |
| 87 |
function render($element, $form) |
| 88 |
{ |
| 89 |
} |
| 90 |
} |
| 91 |
|