register_store_api_callbacks();
} else {
add_action( 'woocommerce_blocks_loaded', [ $this, 'register_store_api_callbacks' ] );
}
}
/**
* Register every QR Pay gateway with the Checkout Block.
*
* @param \Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $registry Registry.
*/
public function register_block_payment_methods( $registry ): void {
if ( ! function_exists( 'WC' ) || ! WC()->payment_gateways() ) {
return;
}
foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
if ( $gateway instanceof \AQRPFW\Gateway\AbstractQRPay ) {
$registry->register( new \AQRPFW\Blocks\QRPayBlocks( $gateway ) );
}
}
}
/**
* Let the block checkout tell the server which payment method is selected,
* so the processing fee is shown in cart totals before the order is placed.
*/
public function register_store_api_callbacks(): void {
if ( ! function_exists( 'woocommerce_store_api_register_update_callback' ) ) {
return;
}
woocommerce_store_api_register_update_callback(
[
'namespace' => 'aqrpfw',
'callback' => function ( $data ) {
if ( ! WC()->session ) {
return;
}
$method = isset( $data['payment_method'] ) ? sanitize_key( $data['payment_method'] ) : '';
// Only accept our own gateway IDs (or empty to clear).
if ( '' !== $method && 0 !== strpos( $method, 'aqrpfw_' ) ) {
return;
}
WC()->session->set( 'chosen_payment_method', $method );
},
]
);
}
/**
* Register payment gateways
*/
public function registerGateway( array $gateways ): array {
$gateways[] = \AQRPFW\Gateway\bKash::class;
$gateways[] = \AQRPFW\Gateway\Nagad::class;
$gateways[] = \AQRPFW\Gateway\Upay::class;
$gateways[] = \AQRPFW\Gateway\Rocket::class;
// Optional international providers (safe)
$gateways[] = \AQRPFW\Gateway\Wise::class;
$gateways[] = \AQRPFW\Gateway\PayPal::class;
$gateways[] = \AQRPFW\Gateway\GooglePay::class;
$gateways[] = \AQRPFW\Gateway\ApplePay::class;
$gateways[] = \AQRPFW\Gateway\Payoneer::class;
$gateways[] = \AQRPFW\Gateway\NexusPay::class;
$gateways[] = \AQRPFW\Gateway\Stripe::class;
$gateways[] = \AQRPFW\Gateway\AmazonPay::class;
$gateways[] = \AQRPFW\Gateway\MCash::class;
$gateways[] = \AQRPFW\Gateway\SureCash::class;
$gateways[] = \AQRPFW\Gateway\Klarna::class;
$gateways[] = \AQRPFW\Gateway\Afterpay::class;
$gateways[] = \AQRPFW\Gateway\Paytm::class;
$gateways[] = \AQRPFW\Gateway\PhonePe::class;
$gateways[] = \AQRPFW\Gateway\eSewa::class;
$gateways[] = \AQRPFW\Gateway\Khalti::class;
$gateways[] = \AQRPFW\Gateway\Fonepay::class;
$gateways[] = \AQRPFW\Gateway\GCash::class;
$gateways[] = \AQRPFW\Gateway\JazzCash::class;
$gateways[] = \AQRPFW\Gateway\Easypaisa::class;
$gateways[] = \AQRPFW\Gateway\Maya::class;
$gateways[] = \AQRPFW\Gateway\Alipay::class;
$gateways[] = \AQRPFW\Gateway\WeChatPay::class;
$gateways[] = \AQRPFW\Gateway\MPesa::class;
return $gateways;
}
/**
* Resolve payer verification value + display label from order meta.
*
* Prefers new `_aqrpfw_payer_ref` meta; falls back to legacy `_aqrpfw_payer_last4`.
*
* @param \WC_Order $order Order object.
* @return array{value:string,label:string}
*/
protected function get_payer_ref_display( $order ): array {
$value = (string) $order->get_meta( '_aqrpfw_payer_ref' );
$type = (string) $order->get_meta( '_aqrpfw_payer_ref_type' );
$label = (string) $order->get_meta( '_aqrpfw_payer_ref_label' );
if ( '' === $value ) {
$value = (string) $order->get_meta( '_aqrpfw_payer_last4' );
if ( $value && '' === $type ) {
$type = 'phone_last4';
}
}
if ( '' === $label && $value ) {
switch ( $type ) {
case 'email':
$label = __( 'Payer email', 'all-qr-pay-for-woocommerce' );
break;
case 'account':
$label = __( 'Payer account ID', 'all-qr-pay-for-woocommerce' );
break;
case 'phone_last4':
default:
$label = __( 'Payer phone (last 4)', 'all-qr-pay-for-woocommerce' );
break;
}
}
return [
'value' => $value,
'label' => $label,
];
}
/**
* Frontend – Thank You page & My Account
*/
public function show_payment_details( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
return;
}
$provider = $order->get_meta( '_aqrpfw_provider' );
$txn = $order->get_meta( '_aqrpfw_txn_id' );
$payer_ref = $this->get_payer_ref_display( $order );
if ( ! $provider && ! $txn && ! $payer_ref['value'] ) {
return;
}
echo ' ';
if ( $provider ) {
echo esc_html__( 'Provider:', 'all-qr-pay-for-woocommerce' ) . ' ' . esc_html( $provider ) . '' . esc_html__( 'QR Payment Details', 'all-qr-pay-for-woocommerce' ) . '
';
}
if ( $txn ) {
echo esc_html__( 'Transaction ID:', 'all-qr-pay-for-woocommerce' ) . ' ' . esc_html( $txn ) . '
';
}
if ( $payer_ref['value'] ) {
echo esc_html( $payer_ref['label'] ) . ': ' . esc_html( $payer_ref['value'] ) . '';
}
echo '
| ' . esc_html__( 'Provider', 'all-qr-pay-for-woocommerce' ) . ' | ' . esc_html( $provider ) . ' |
|---|---|
| ' . esc_html__( 'Transaction ID', 'all-qr-pay-for-woocommerce' ) . ' | ' . esc_html( $txn ) . ' |
| ' . esc_html( $payer_ref['label'] ) . ' | ' . esc_html( $payer_ref['value'] ) . ' |
| ' . esc_html__( 'Provider', 'all-qr-pay-for-woocommerce' ) . ' | ' . esc_html( $provider ) . ' |
|---|---|
| ' . esc_html__( 'Transaction ID', 'all-qr-pay-for-woocommerce' ) . ' | ' . esc_html( $txn ) . ' |
| ' . esc_html( $payer_ref['label'] ) . ' | ' . esc_html( $payer_ref['value'] ) . ' |
' . esc_html__( 'Verify in wallet dashboard, then mark order as Processing or Completed.', 'all-qr-pay-for-woocommerce' ) . '
'; echo '