| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\PaymentGateways\Gateways\Stripe\Traits; |
| 4 |
|
| 5 |
use Give_Notices; |
| 6 |
|
| 7 |
trait CreditCardForm |
| 8 |
{ |
| 9 |
use FormFieldMarkup; |
| 10 |
|
| 11 |
/** |
| 12 |
* @note Stripe uses its own credit card form to tokenize card details. |
| 13 |
* @note Input fields for credit cards should NOT be posted with the donation data. |
| 14 |
* |
| 15 |
* @param int $form_id Donation Form ID. |
| 16 |
* @param array $args Donation Form Arguments. |
| 17 |
* |
| 18 |
* @since 2.19.0 Migrated from the legacy Give_Stripe_Card::addCreditCardForm implementation of the Stripe Gateway. |
| 19 |
* |
| 20 |
* @return string |
| 21 |
*/ |
| 22 |
public function getCreditCardFormHTML( $form_id, $args ) { |
| 23 |
|
| 24 |
ob_start(); |
| 25 |
$idPrefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
| 26 |
|
| 27 |
do_action( 'give_before_cc_fields', $form_id ); ?> |
| 28 |
|
| 29 |
<fieldset id="give_cc_fields" class="give-do-validate"> |
| 30 |
<legend> |
| 31 |
<?php esc_attr_e( 'Credit Card Info', 'give' ); ?> |
| 32 |
</legend> |
| 33 |
|
| 34 |
<?php |
| 35 |
if ( is_ssl() ) { |
| 36 |
?> |
| 37 |
<div id="give_secure_site_wrapper"> |
| 38 |
<span class="give-icon padlock"></span> |
| 39 |
<span> |
| 40 |
<?php esc_attr_e( 'This is a secure SSL encrypted payment.', 'give' ); ?> |
| 41 |
</span> |
| 42 |
</div> |
| 43 |
<?php |
| 44 |
} |
| 45 |
|
| 46 |
if ( $this->canShowFields() ) { |
| 47 |
// Show Credit Card Fields. |
| 48 |
echo \Give\Helpers\Gateways\Stripe::showCreditCardFields( $idPrefix ); |
| 49 |
|
| 50 |
/** |
| 51 |
* This action hook is used to display content after the Credit Card expiration field. |
| 52 |
* |
| 53 |
* Note: Kept this hook as it is. |
| 54 |
* |
| 55 |
* @since 2.5.0 |
| 56 |
* |
| 57 |
* @param int $form_id Donation Form ID. |
| 58 |
* @param array $args List of additional arguments. |
| 59 |
*/ |
| 60 |
do_action( 'give_after_cc_expiration', $form_id, $args ); |
| 61 |
|
| 62 |
/** |
| 63 |
* This action hook is used to display content after the Credit Card expiration field. |
| 64 |
* |
| 65 |
* @since 2.5.0 |
| 66 |
* |
| 67 |
* @param int $form_id Donation Form ID. |
| 68 |
* @param array $args List of additional arguments. |
| 69 |
*/ |
| 70 |
do_action( 'give_stripe_after_cc_expiration', $form_id, $args ); |
| 71 |
} |
| 72 |
?> |
| 73 |
</fieldset> |
| 74 |
<?php |
| 75 |
// Remove Address Fields if user has option enabled. |
| 76 |
$billing_fields_enabled = give_get_option( 'stripe_collect_billing' ); |
| 77 |
if ( ! $billing_fields_enabled ) { |
| 78 |
remove_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
| 79 |
} |
| 80 |
|
| 81 |
do_action( 'give_after_cc_fields', $form_id, $args ); |
| 82 |
|
| 83 |
return ob_get_clean(); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* This function is used to determine whether to show the payment fields or not. |
| 88 |
* |
| 89 |
* @since 2.7.0 |
| 90 |
* @access public |
| 91 |
* |
| 92 |
* @return bool |
| 93 |
*/ |
| 94 |
public function canShowFields() { |
| 95 |
|
| 96 |
$status = true; |
| 97 |
$isConfigured = \Give\Helpers\Gateways\Stripe::isAccountConfigured(); |
| 98 |
$isTestMode = give_is_test_mode(); |
| 99 |
$isSslActive = is_ssl(); |
| 100 |
|
| 101 |
if ( ! $isConfigured && ! $isSslActive && ! $isTestMode ) { |
| 102 |
// Account not configured, No SSL scenario. |
| 103 |
Give_Notices::print_frontend_notice( |
| 104 |
sprintf( |
| 105 |
'<strong>%1$s</strong> %2$s', |
| 106 |
esc_html__( 'Notice:', 'give' ), |
| 107 |
$this->errorMessages['accountNotConfiguredNoSsl'] |
| 108 |
) |
| 109 |
); |
| 110 |
$status = false; |
| 111 |
|
| 112 |
} elseif ( ! $isConfigured ) { |
| 113 |
// Account not configured scenario. |
| 114 |
Give_Notices::print_frontend_notice( |
| 115 |
sprintf( |
| 116 |
'<strong>%1$s</strong> %2$s', |
| 117 |
esc_html__( 'Notice:', 'give' ), |
| 118 |
$this->errorMessages['accountNotConfigured'] |
| 119 |
) |
| 120 |
); |
| 121 |
$status = false; |
| 122 |
|
| 123 |
} elseif ( ! $isTestMode && ! $isSslActive ) { |
| 124 |
// Account configured, No SSL scenario. |
| 125 |
Give_Notices::print_frontend_notice( |
| 126 |
sprintf( |
| 127 |
'<strong>%1$s</strong> %2$s', |
| 128 |
esc_html__( 'Notice:', 'give' ), |
| 129 |
$this->errorMessages['accountConfiguredNoSsl'] |
| 130 |
) |
| 131 |
); |
| 132 |
$status = false; |
| 133 |
} |
| 134 |
|
| 135 |
return $status; |
| 136 |
} |
| 137 |
} |
| 138 |
|