Customize data sent to HiPay
This guides explains how to customize data sent to HiPay.
The HiPay payment module is extensible. It leverages Front-Commerce's "data transform" pattern to allow developers to customize payment data sent to HiPay.
Example
Let's say we want to add more information to the Billing Address sent to HiPay.
To achieve this, we can create a GraphQL Module to register the custom payment data transformations.
example-extension/modules/hipay.ts
import { createGraphQLModule } from "@front-commerce/core/graphql";
export default createGraphQLModule({
namespace: "HiPay/Custom",
dependencies: ["HiPay/Core"],
runtime: () => import("./runtime"),
});
Then we can create the runtime which will register the custom payment data transformation.
example-extension/modules/hipay/runtime.ts
import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import type { Customer, Order } from "~/graphql/graphql";
import type HiPay from "@hipay/hipay-enterprise-sdk-nodejs";
// (Optional) Infer the params type of the OrderRequest constructor
type HiPayOrderRequest = ConstructorParameters<typeof HiPay.OrderRequest>[0];
// (Optional) Helper function for type safety for OrderRequest fields
function createAdditionalData(
additionalData: (
customer: Customer,
order: Order
) => Partial<HiPayOrderRequest>
) {
return additionalData;
}
export default createGraphQLRuntime({
contextEnhancer: ({ loaders }) => {
// create the additional data transformer using the helper function
const additionalDataTransformer = createAdditionalData(
(customer, order) => ({
customerBillingInfo: {
// suffix the first name with "(HiPay)"
firstName: `${customer.firstName} (HiPay)`,
},
})
);
// register the additional data transformer
loaders.HiPay.registerPaymentDataTransform(additionalDataTransformer);
},
});
tip
The customerBillingInfo
is automatically spread with the default values (see reference)
🥳 That's it! You should all your customers should have have their first name suffixed with (HiPay)
in the HiPay Console.
Limitations
- Only some fields can be customized, the fields from this reference is hardcoded and does not allow overriding.
- Only fields supported by the HiPay Enterprise SDK
OrderRequest
object will be sent to HiPay. (see reference)