Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GrabPay at Checkout #10336

Merged
merged 8 commits into from
Feb 14, 2025
4 changes: 4 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
background-image: url( '../images/payment-methods/klarna.svg' );
}

.payment-method__brand--grabpay {
background-image: url( '../images/payment-methods/grabpay.svg' );
}

.wc_gateways tr[data-gateway_id='woocommerce_payments'] .payment-method__icon {
border: 1px solid #ddd;
border-radius: 2px;
Expand Down
4 changes: 4 additions & 0 deletions changelog/add-grabpay-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Implement checkout for GrabPay payments.
2 changes: 1 addition & 1 deletion includes/class-wc-payments-order-success-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function show_lpm_payment_method_name( $gateway, $payment_method ) {
ob_start();
?>
<div class="wc-payment-gateway-method-logo-wrapper wc-payment-lpm-logo wc-payment-lpm-logo--<?php echo esc_attr( $payment_method->get_id() ); ?>">
<img alt="<?php echo esc_attr( $payment_method->get_title() ); ?>" src="<?php echo esc_url_raw( $method_logo_url ); ?>">
<img alt="<?php echo esc_attr( $payment_method->get_title() ); ?>" title="<?php echo esc_attr( $payment_method->get_title() ); ?>" src="<?php echo esc_url_raw( $method_logo_url ); ?>">
</div>
<?php
return ob_get_clean();
Expand Down
41 changes: 29 additions & 12 deletions tests/unit/test-class-wc-payments-order-success-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package WooCommerce\Payments\Tests
*/

use WCPay\Payment_Methods\UPE_Payment_Method;

/**
* WC_Payments_Order_Success_Page unit tests.
*/
Expand Down Expand Up @@ -93,19 +95,34 @@ public function test_show_woopay_payment_method_name_without_woopay_meta() {
$this->assertSame( $method_name, $result );
}

public function test_show_woopay_payment_method_name_order_with_woopay_meta() {
$order = WC_Helper_Order::create_order();
$order->add_meta_data( 'is_woopay', true );
$order->add_meta_data( 'last4', '1234' );
$order->set_payment_method( 'woocommerce_payments' );
$order->save();
public function test_show_lpm_payment_method_name() {
$gateway = $this->createMock( WC_Payment_Gateway_WCPay::class );
$gateway->method( 'get_account_country' )->willReturn( 'SG' );

$payment_method = $this->createMock( UPE_Payment_Method::class );
$payment_method->method( 'get_title' )->willReturn( 'GrabPay' );
$payment_method->method( 'get_id' )->willReturn( 'grabpay' );
$payment_method->method( 'get_payment_method_icon_for_location' )->willReturn( '/grabpay.svg' );

$result = $this->payments_order_success_page->show_lpm_payment_method_name( $gateway, $payment_method );

$this->assertStringContainsString( 'wc-payment-gateway-method-logo-wrapper', $result );
$this->assertStringContainsString( 'alt="GrabPay"', $result );
$this->assertStringContainsString( 'title="GrabPay"', $result );
$this->assertStringContainsString( 'src="/grabpay.svg"', $result );
}

public function test_show_lpm_payment_method_name_icon_not_found() {
$gateway = $this->createMock( WC_Payment_Gateway_WCPay::class );
$gateway->method( 'get_account_country' )->willReturn( 'SG' );

$payment_method = $this->createMock( UPE_Payment_Method::class );
$payment_method->method( 'get_title' )->willReturn( 'GrabPay' );
$payment_method->method( 'get_id' )->willReturn( 'grabpay' );
$payment_method->method( 'get_payment_method_icon_for_location' )->willReturn( '' );

add_filter( 'woocommerce_is_order_received_page', '__return_true' );
$result = $this->payments_order_success_page->show_woocommerce_payments_payment_method_name( 'Credit card', $order );
remove_filter( 'woocommerce_is_order_received_page', '__return_true' );
$result = $this->payments_order_success_page->show_lpm_payment_method_name( $gateway, $payment_method, true );

$this->assertStringContainsString( 'wc-payment-gateway-method-logo-wrapper woopay', $result );
$this->assertStringContainsString( 'img alt="WooPay"', $result );
$this->assertStringContainsString( sprintf( 'Card ending in %s', $order->get_meta( 'last4' ) ), $result );
$this->assertFalse( $result );
}
}
Loading