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

GrabPay: Add settings page. #10235

Merged
merged 17 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions assets/images/payment-method-icons/grabpay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions assets/images/payment-methods/grabpay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions changelog/add-grabpay-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add GrabPay to the settings page when eligible.
1 change: 1 addition & 0 deletions client/additional-methods-setup/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const upeMethods = [
'afterpay_clearpay',
'jcb',
'klarna',
'grabpay',
];

export const upeCapabilityStatuses = {
Expand Down
2 changes: 2 additions & 0 deletions client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
PAYMENT_METHOD_NAME_AFFIRM,
PAYMENT_METHOD_NAME_AFTERPAY,
PAYMENT_METHOD_NAME_KLARNA,
PAYMENT_METHOD_NAME_GRABPAY,
} from '../constants.js';
import { getDeferredIntentCreationUPEFields } from './payment-elements';
import { handleWooPayEmailInput } from '../woopay/email-input-iframe';
Expand All @@ -61,6 +62,7 @@ const upeMethods = {
affirm: PAYMENT_METHOD_NAME_AFFIRM,
afterpay_clearpay: PAYMENT_METHOD_NAME_AFTERPAY,
klarna: PAYMENT_METHOD_NAME_KLARNA,
grabpay: PAYMENT_METHOD_NAME_GRABPAY,
};

const enabledPaymentMethodsConfig = getUPEConfig( 'paymentMethodsConfig' );
Expand Down
2 changes: 2 additions & 0 deletions client/checkout/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const PAYMENT_METHOD_NAME_AFFIRM = 'woocommerce_payments_affirm';
export const PAYMENT_METHOD_NAME_AFTERPAY =
'woocommerce_payments_afterpay_clearpay';
export const PAYMENT_METHOD_NAME_KLARNA = 'woocommerce_payments_klarna';
export const PAYMENT_METHOD_NAME_GRABPAY = 'woocommerce_payments_grabpay';
export const PAYMENT_METHOD_NAME_EXPRESS_CHECKOUT_ELEMENT =
'woocommerce_payments_express_checkout';
export const PAYMENT_METHOD_NAME_WOOPAY_EXPRESS_CHECKOUT =
Expand All @@ -32,6 +33,7 @@ export function getPaymentMethodsConstants() {
PAYMENT_METHOD_NAME_AFTERPAY,
PAYMENT_METHOD_NAME_CARD,
PAYMENT_METHOD_NAME_KLARNA,
PAYMENT_METHOD_NAME_GRABPAY,
];
}

Expand Down
5 changes: 5 additions & 0 deletions client/components/payment-method-logos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ApplePay from 'assets/images/payment-method-icons/applepay.svg?asset';
import AfterPay from 'assets/images/payment-method-icons/afterpay.svg?asset';
import Affirm from 'assets/images/payment-method-icons/affirm.svg?asset';
import Klarna from 'assets/images/payment-method-icons/klarna.svg?asset';
import GrabPay from 'assets/images/payment-method-icons/grabpay.svg?asset';
import Jcb from 'assets/images/payment-method-icons/jcb.svg?asset';
import GooglePay from 'assets/images/payment-method-icons/gpay.svg?asset';
import Cartebancaire from 'assets/images/cards/cartes_bancaires.svg?asset';
Expand Down Expand Up @@ -110,6 +111,10 @@ const PaymentMethods = [
name: 'przelewy24',
component: Przelewy24,
},
{
name: 'grabpay',
component: GrabPay,
},
];

export const WooPaymentsMethodsLogos: React.VFC< {
Expand Down
2 changes: 2 additions & 0 deletions client/constants/payment-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum PAYMENT_METHOD_IDS {
CARD_PRESENT = 'card_present',
EPS = 'eps',
KLARNA = 'klarna',
GRABPAY = 'grabpay',
GIROPAY = 'giropay',
IDEAL = 'ideal',
LINK = 'link',
Expand Down Expand Up @@ -46,6 +47,7 @@ export const PAYMENT_METHOD_TITLES = {
ideal: __( 'iDEAL', 'woocommerce-payments' ),
jcb: __( 'JCB', 'woocommerce-payments' ),
klarna: __( 'Klarna', 'woocommerce-payments' ),
grabpay: __( 'GrabPay', 'woocommerce-payments' ),
link: __( 'Link', 'woocommerce-payments' ),
mastercard: __( 'Mastercard', 'woocommerce-payments' ),
multibanco: __( 'Multibanco', 'woocommerce-payments' ),
Expand Down
1 change: 1 addition & 0 deletions client/data/transactions/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface Transaction {
| 'ideal'
| 'jcb'
| 'klarna'
| 'grabpay'
| 'link'
| 'mastercard'
| 'multibanco'
Expand Down
5 changes: 5 additions & 0 deletions client/payment-methods-icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import AfterpayAsset from 'assets/images/payment-methods/afterpay-logo.svg?asset
import ClearpayAsset from 'assets/images/payment-methods/clearpay.svg?asset';
import JCBAsset from 'assets/images/payment-methods/jcb.svg?asset';
import KlarnaAsset from 'assets/images/payment-methods/klarna.svg?asset';
import GrabPayAsset from 'assets/images/payment-methods/grabpay.svg?asset';
import VisaAsset from 'assets/images/cards/visa.svg?asset';
import MasterCardAsset from 'assets/images/cards/mastercard.svg?asset';
import AmexAsset from 'assets/images/cards/amex.svg?asset';
Expand Down Expand Up @@ -150,6 +151,10 @@ export const VisaIcon = iconComponent(
VisaAsset,
__( 'Visa', 'woocommerce-payments' )
);
export const GrabPayIcon = iconComponent(
GrabPayAsset,
__( 'GrabPay', 'woocommerce-payments' )
);
export const WooIcon = iconComponent(
WooAsset,
__( 'WooPay', 'woocommerce-payments' ),
Expand Down
15 changes: 15 additions & 0 deletions client/payment-methods-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
P24Icon,
SepaIcon,
SofortIcon,
GrabPayIcon,
} from 'wcpay/payment-methods-icons';

const accountCountry = window.wcpaySettings?.accountStatus?.country || 'US';
Expand Down Expand Up @@ -233,6 +234,20 @@ const PaymentMethodInformationObject: Record<
allows_pay_later: true,
accepts_only_domestic_payment: true,
},
grabpay: {
id: 'grabpay',
label: __( 'GrabPay', 'woocommerce-payments' ),
description: __(
'A popular digital wallet for cashless payments in Singapore.',
'woocommerce-payments'
),
icon: GrabPayIcon,
currencies: [ 'SGD' ],
stripe_key: 'grabpay_payments',
allows_manual_capture: false,
allows_pay_later: false,
accepts_only_domestic_payment: false,
},
};

export default PaymentMethodInformationObject;
1 change: 1 addition & 0 deletions client/types/charges.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface PaymentMethodDetails {
| 'giropay'
| 'ideal'
| 'klarna'
| 'grabpay'
| 'p24'
| 'sepa_debit'
| 'sofort';
Expand Down
1 change: 1 addition & 0 deletions client/types/payment-methods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type PaymentMethod =
| 'card_present'
| 'eps'
| 'klarna'
| 'grabpay'
| 'giropay'
| 'ideal'
| 'p24'
Expand Down
2 changes: 2 additions & 0 deletions client/utils/account-fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ export const getTransactionsPaymentMethodName = (
return __( 'Afterpay transactions', 'woocommerce-payments' );
case 'klarna':
return __( 'Klarna transactions', 'woocommerce-payments' );
case 'grabpay':
return __( 'GrabPay transactions', 'woocommerce-payments' );
default:
return __( 'Unknown transactions', 'woocommerce-payments' );
}
Expand Down
2 changes: 2 additions & 0 deletions includes/class-duplicates-detection-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use WCPay\Payment_Methods\Klarna_Payment_Method;
use WCPay\Payment_Methods\P24_Payment_Method;
use WCPay\Payment_Methods\Sepa_Payment_Method;
use WCPay\Payment_Methods\Grabpay_Payment_Method;

/**
* Class handling detection of payment methods enabled by multiple plugins simultaneously.
Expand Down Expand Up @@ -103,6 +104,7 @@ private function search_for_additional_payment_methods() {
'afterpay' => Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'clearpay' => Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'klarna' => Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'grabpay' => Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
];

foreach ( $this->get_enabled_gateways() as $gateway ) {
Expand Down
3 changes: 3 additions & 0 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
use WCPay\Payment_Methods\P24_Payment_Method;
use WCPay\Payment_Methods\Sepa_Payment_Method;
use WCPay\Payment_Methods\UPE_Payment_Method;
use WCPay\Payment_Methods\Grabpay_Payment_Method;

/**
* Gateway class for WooPayments
Expand Down Expand Up @@ -351,6 +352,7 @@ public function __construct(
'affirm' => 'affirm_payments',
'afterpay_clearpay' => 'afterpay_clearpay_payments',
'klarna' => 'klarna_payments',
'grabpay' => 'grabpay_payments',
'jcb' => 'jcb_payments',
];

Expand Down Expand Up @@ -4142,6 +4144,7 @@ public function get_upe_available_payment_methods() {
$available_methods[] = Affirm_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;

$available_methods = array_values(
apply_filters(
Expand Down
3 changes: 3 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use WCPay\WooPay\WooPay_Session;
use WCPay\Compatibility_Service;
use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\Grabpay_Payment_Method;
use WCPay\WC_Payments_Currency_Manager;

/**
Expand Down Expand Up @@ -437,6 +438,7 @@ public static function init() {
include_once __DIR__ . '/payment-methods/class-affirm-payment-method.php';
include_once __DIR__ . '/payment-methods/class-afterpay-payment-method.php';
include_once __DIR__ . '/payment-methods/class-klarna-payment-method.php';
include_once __DIR__ . '/payment-methods/class-grabpay-payment-method.php';
include_once __DIR__ . '/express-checkout/class-wc-payments-express-checkout-button-helper.php';
include_once __DIR__ . '/class-wc-payment-token-wcpay-sepa.php';
include_once __DIR__ . '/class-wc-payments-status.php';
Expand Down Expand Up @@ -575,6 +577,7 @@ public static function init() {
Affirm_Payment_Method::class,
Afterpay_Payment_Method::class,
Klarna_Payment_Method::class,
Grabpay_Payment_Method::class,
];

$payment_methods = [];
Expand Down
1 change: 1 addition & 0 deletions includes/constants/class-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Payment_Method extends Base_Constant {
const AFFIRM = 'affirm';
const AFTERPAY = 'afterpay_clearpay';
const KLARNA = 'klarna';
const GRABPAY = 'grabpay';

const IPP_ALLOWED_PAYMENT_METHODS = [
self::CARD_PRESENT,
Expand Down
60 changes: 60 additions & 0 deletions includes/payment-methods/class-grabpay-payment-method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Class Grabpay_Payment_Method
*
* @package WCPay\Payment_Methods
*/

namespace WCPay\Payment_Methods;

use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;

/**
* GrabPay Payment Method class extending UPE base class
*/
class Grabpay_Payment_Method extends UPE_Payment_Method {

const PAYMENT_METHOD_STRIPE_ID = 'grabpay';

/**
* Constructor for GrabPay payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
// Note: If WooPayments becomes available to merchants from Malaysia in the future, we'll need to not only add MYR here, but also implement
// logic to limit the currency based on the Stripe account country, so SG accounts only accept SGD, and MY accounts only accept MYR.
$this->currencies = [ Currency_Code::SINGAPORE_DOLLAR ];
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = false;
$this->icon_url = plugins_url( 'assets/images/payment-methods/grabpay.svg', WCPAY_PLUGIN_FILE );
$this->accept_only_domestic_payment = true;
$this->countries = [ Country_Code::SINGAPORE ];
}

/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'GrabPay', 'woocommerce-payments' );
}

/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
Loading
Loading