| 1 |
<?php |
| 2 |
|
| 3 |
namespace MakeCommerce\Payment\Gateway\WooCommerce; |
| 4 |
|
| 5 |
trait Creditcard { |
| 6 |
|
| 7 |
/** |
| 8 |
* Credit card pending payment page. |
| 9 |
* |
| 10 |
* @since 3.0.0 |
| 11 |
*/ |
| 12 |
public function receipt_page( $orderId ) { |
| 13 |
|
| 14 |
$order = new \WC_Order( $orderId ); |
| 15 |
|
| 16 |
if ( substr( get_post_meta( $orderId, '_makecommerce_preselected_method', true ), 0, 5 ) == 'card_' && $order->get_status() == 'pending' ) { |
| 17 |
|
| 18 |
echo "<br>".__( 'The order is still awaiting your payment', 'wc_makecommerce_domain' )."<br>"; |
| 19 |
echo $this->generateCardForm( $order ); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Generates credit card payment form |
| 25 |
* |
| 26 |
* @since 3.0.0 |
| 27 |
*/ |
| 28 |
public function generateCardForm( $orderId ) { |
| 29 |
|
| 30 |
$order = new \WC_Order( $orderId ); |
| 31 |
|
| 32 |
$has_subscription = function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order ); |
| 33 |
|
| 34 |
$transactionId = get_post_meta( $order->get_id(), '_makecommerce_transaction_id', true ); |
| 35 |
|
| 36 |
$idReference = $order->get_id(); |
| 37 |
|
| 38 |
$jsParams = array( |
| 39 |
'key' => $this->MK->getPublishableKey(), |
| 40 |
'transaction' => $transactionId, |
| 41 |
'amount' => sprintf( "%.2F", $order->get_total() ), |
| 42 |
'locale' => \MakeCommerce\i18n::get_two_char_locale(), |
| 43 |
'openonload' => 'true', |
| 44 |
'clientname' => ( $this->settings['cc_pass_cust_data'] == 'yes' ? ( string ) ( ( method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name ) . ' ' . ( method_exists( $order, 'get_billing_last_name' ) ? $order->get_billing_last_name() : $order->billing_last_name ) ) : '' ), |
| 45 |
'email' => ( $this->settings['cc_pass_cust_data'] == 'yes' ? ( string ) ( method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email ) : '' ), |
| 46 |
'name' => get_option( 'mc_shop_name', '' ), |
| 47 |
'description' => __( 'Order', 'woocommerce' ) . ' ' . ( string ) $idReference, |
| 48 |
'completed' => 'makecommerce_cc_complete', |
| 49 |
'currency' => method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->currency, |
| 50 |
'backdropclose' => 'false', |
| 51 |
); |
| 52 |
|
| 53 |
if ( $has_subscription ) { |
| 54 |
|
| 55 |
$jsParams['recurringrequired'] = 'true'; |
| 56 |
$jsParams['recurringtitle'] = __( 'Pay for subscription', 'wc_makecommerce_domain' ); |
| 57 |
$jsParams['recurringdescription'] = __( 'This order contains subscriptions', 'wc_makecommerce_domain' ); |
| 58 |
$jsParams['recurringconfirmation'] = __( 'I agree that my card will be recurringly billed by this store', 'wc_makecommerce_domain' ); |
| 59 |
} |
| 60 |
|
| 61 |
\MakeCommerce::mc_enqueue_script( |
| 62 |
'MC_CC_COMPLETE', |
| 63 |
dirname( __FILE__ ) . '/js/mc_cc_complete.js', |
| 64 |
[ |
| 65 |
'payment_return_url' => $this->payment_return_url, |
| 66 |
'transaction_id' => $transactionId |
| 67 |
], |
| 68 |
); |
| 69 |
|
| 70 |
\MakeCommerce::mc_enqueue_script( |
| 71 |
'MC_MAKECOMMERCE_CC_CHECKOUT', |
| 72 |
$this->MK->getEnvUrls()->checkoutjsUrl.'checkout.js', |
| 73 |
[], |
| 74 |
[], |
| 75 |
true |
| 76 |
); |
| 77 |
|
| 78 |
\MakeCommerce::mc_enqueue_script( |
| 79 |
'MC_CC_INIT', |
| 80 |
dirname( __FILE__ ) . '/js/mc_cc_init.js', |
| 81 |
$jsParams, |
| 82 |
); |
| 83 |
|
| 84 |
$html = ' |
| 85 |
<button type="button" class="btn btn-primary" aria-label="' . __( 'Pay with credit card', 'wc_makecommerce_domain' ) . '" onclick="init_mc_cc_form();">' . __( 'Pay with credit card', 'wc_makecommerce_domain' ) . '</button> |
| 86 |
<div class="mc-processing-message"><img src="' . plugins_url( '/images/loading.png', __FILE__ ) . '"/>' . __( 'Please wait, processing payment...', 'wc_makecommerce_domain' ) . '</div> |
| 87 |
'; |
| 88 |
|
| 89 |
return $html; |
| 90 |
} |
| 91 |
} |