internal_id = (string) $id;
$this->id = WC_Gateway_Przelewy24::PAYMENT_METHOD . '_extra_' . $id;
$this->generator = $generator;
$this->main_gateway = $main_gateway;
$this->icon = $icon;
$this->title = (string) $title;
add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'print_receipt' ) );
}
/**
* Get title.
*
* @return mixed
*/
public function get_title() {
return $this->title;
}
/**
* Aditional conntent on print receipt page.
*
* @param int $order_id If of order.
*/
public function print_receipt( $order_id ) {
$order_id = (int) $order_id;
$order = new WC_Order( (int) $order_id );
$settings_accessor = $this->main_gateway->get_settings_from_internal_formatted( $order->get_currency() );
$hasher = new P24_Hasher( $settings_accessor );
$hashed_order_id = $hasher->hash( $order_id );
$is_blik = self::BLIK_METHOD === $this->internal_id;
if ( $is_blik ) {
$blik_code = $order->get_meta( self::BLIK_CODE_META_KEY );
} else {
$blik_code = false;
}
if ( $blik_code ) {
$legacy_auto_submit = false;
} else {
$legacy_auto_submit = true;
}
$ajax_url = add_query_arg( array( 'wc-api' => 'wc_gateway_przelewy24' ), home_url( '/' ) );
if ( $is_blik ) {
$svg_generator = $this->main_gateway->get_core()->get_cached_icon_generator();
$html_icon_generator = new P24_Icon_Html_Generator( $svg_generator );
$paymethod_all = $this->main_gateway->get_all_payment_methods();
$code = $html_icon_generator->get_bank_html( self::BLIK_METHOD, $paymethod_all[ self::BLIK_METHOD ] );
echo '
', $code, '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
echo $this->generator->generate_przelewy24_form( $order, $legacy_auto_submit ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ( $blik_code ) {
echo P24_Blik_Html::get_modal_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
if ( in_array( $this->internal_id, self::CARD_METHODS, true ) ) {
$combined_card_data = $order->get_meta( self::CARD_COMBINED_FIELD_META_KEY );
echo "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
/**
* Process the payment and return the result
*
* @param int $order_id Id of orer.
* @return array
*/
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
/* This is the default place to reduce stock levels. It is safe to call function below multiple times. */
wc_maybe_reduce_stock_levels( $order );
wp_verify_nonce( null ); /* There is no nonce in request. */
$save_meta = false;
if ( isset( $_POST[ self::BLIK_CODE_INPUT_NAME ] ) ) {
$blik_code = sanitize_text_field( wp_unslash( $_POST[ self::BLIK_CODE_INPUT_NAME ] ) );
$order->update_meta_data( self::BLIK_CODE_META_KEY, $blik_code );
$save_meta = true;
}
if ( isset( $_POST[ self::CARD_COMBINED_INPUT_FIELD_NAME ] ) ) {
$combined_data = sanitize_text_field( wp_unslash( $_POST[ self::CARD_COMBINED_INPUT_FIELD_NAME ] ) );
$order->update_meta_data( self::CARD_COMBINED_FIELD_META_KEY, $combined_data );
$save_meta = true;
}
if ( $save_meta ) {
$order->update_meta_data( P24_Core::CHOSEN_TIMESTAMP_META_KEY, time() );
$order->update_meta_data( P24_Core::P24_METHOD_META_KEY, $this->internal_id );
$order->save_meta_data();
}
$core = $this->main_gateway->get_core();
$email_enforcer = $core->get_email_enforcer();
$email_enforcer->try_execute_early_mails( $order );
do_action( 'wc_extra_gateway_przelewy24_process_payment', $order );
return array(
'result' => 'success',
'redirect' => $order->get_checkout_payment_url( $order ),
);
}
/**
* Check if gateway is valid for provided price.
*
* @param float $price Price to check.
* @return bool
*/
public function is_valid_for_price( $price ) {
return self::is_valid_for_price_static( $price, $this->internal_id );
}
}