🤖 Merge PR #65833 Added PSE types by @AleFossati

* added new form properties to pse and 3ds setup

* fix bricks style as optional

* fix MercadoPago second parameter as optional

* added entity type to initialization

* added semicolon

* formatting
This commit is contained in:
Alexandre Fossati
2023-06-20 10:40:58 -03:00
committed by GitHub
parent 729e11e1cb
commit ff9bb7773f
7 changed files with 651 additions and 652 deletions

View File

@@ -4,160 +4,152 @@
/// <reference path="./modules/fields.d.ts" />
declare namespace mercadopagocore {
enum Locale {
ES_AR = 'es-AR',
ES_CL = 'es-CL',
ES_CO = 'es-CO',
ES_MX = 'es-MX',
ES_VE = 'es-VE',
ES_UY = 'es-UY',
ES_PE = 'es-PE',
PT_BR = 'pt-BR',
EN_US = 'en-US'
}
enum Locale {
ES_AR = 'es-AR',
ES_CL = 'es-CL',
ES_CO = 'es-CO',
ES_MX = 'es-MX',
ES_VE = 'es-VE',
ES_UY = 'es-UY',
ES_PE = 'es-PE',
PT_BR = 'pt-BR',
EN_US = 'en-US',
}
interface Options {
locale?: Locale;
advancedFraudPrevention?: boolean;
trackingDisabled?: boolean;
}
interface Options {
locale?: Locale;
advancedFraudPrevention?: boolean;
trackingDisabled?: boolean;
}
type ProcessingMode = "gateway" | "aggregator";
type ProcessingMode = 'gateway' | 'aggregator';
interface IdentificationTypesResponse {
id: string;
name: string;
type: string;
min_length: number;
max_length: number;
}
interface IdentificationTypesResponse {
id: string;
name: string;
type: string;
min_length: number;
max_length: number;
}
interface PaymentMethodsParams {
bin: string;
processingMode?: ProcessingMode;
}
interface PaymentMethodsParams {
bin: string;
processingMode?: ProcessingMode;
}
interface FinancingDeals {
legals?: unknown;
installments?: unknown;
expiration_date?: unknown;
start_date?: unknown;
status: string;
}
interface FinancingDeals {
legals?: unknown;
installments?: unknown;
expiration_date?: unknown;
start_date?: unknown;
status: string;
}
interface Result {
financial_institutions: unknown[];
secure_thumbnail: string;
payer_costs: shared.PayerCost[];
issuer: shared.Issuer;
total_financial_cost?: unknown;
min_accreditation_days: number;
max_accreditation_days: number;
merchant_account_id: string;
id: string;
payment_type_id: string;
accreditation_time: number;
thumbnail: string;
bins: unknown[];
marketplace: string;
deferred_capture: string;
agreements: unknown[];
labels: string[];
financing_deals: FinancingDeals;
name: string;
site_id: string;
processing_mode: string;
additional_info_needed: string[];
status: string;
settings: shared.Setting[];
}
interface Result {
financial_institutions: unknown[];
secure_thumbnail: string;
payer_costs: shared.PayerCost[];
issuer: shared.Issuer;
total_financial_cost?: unknown;
min_accreditation_days: number;
max_accreditation_days: number;
merchant_account_id: string;
id: string;
payment_type_id: string;
accreditation_time: number;
thumbnail: string;
bins: unknown[];
marketplace: string;
deferred_capture: string;
agreements: unknown[];
labels: string[];
financing_deals: FinancingDeals;
name: string;
site_id: string;
processing_mode: string;
additional_info_needed: string[];
status: string;
settings: shared.Setting[];
}
interface Paging {
total: number;
limit: number;
offset: number;
}
interface Paging {
total: number;
limit: number;
offset: number;
}
interface PaymentMethodsResponse {
paging: Paging;
results: Result[];
}
interface PaymentMethodsResponse {
paging: Paging;
results: Result[];
}
interface IssuersParams {
payment_method_id?: string;
paymentMethodId?: string;
bin: string;
}
interface IssuersParams {
payment_method_id?: string;
paymentMethodId?: string;
bin: string;
}
interface IssuersResponse {
id: string;
name: string;
secure_thumbnail: string;
thumbnail: string;
processing_mode: string;
merchant_account_id: string;
}
interface IssuersResponse {
id: string;
name: string;
secure_thumbnail: string;
thumbnail: string;
processing_mode: string;
merchant_account_id: string;
}
interface InstallmentsParams {
locale?: Locale;
amount: string;
bin: string;
paymentMethodId?: string;
payment_method_id?: string;
processingMode?: ProcessingMode;
processing_mode?: ProcessingMode;
paymentTypeId?: string;
payment_type_id?: string;
}
interface InstallmentsParams {
locale?: Locale;
amount: string;
bin: string;
paymentMethodId?: string;
payment_method_id?: string;
processingMode?: ProcessingMode;
processing_mode?: ProcessingMode;
paymentTypeId?: string;
payment_type_id?: string;
}
interface InstallmentsResponse {
payment_method_id: string;
payment_type_id: string;
issuer: shared.Issuer;
processing_mode: string;
merchant_account_id?: string;
payer_costs: shared.PayerCost[];
agreements?: unknown;
}
interface InstallmentsResponse {
payment_method_id: string;
payment_type_id: string;
issuer: shared.Issuer;
processing_mode: string;
merchant_account_id?: string;
payer_costs: shared.PayerCost[];
agreements?: unknown;
}
interface CardTokenParams {
cardNumber?: string;
cardholderName?: string;
identificationType?: string;
identificationNumber?: string;
securityCode?: string;
cardExpirationMonth?: string;
cardExpirationYear?: string;
cardId?: string;
}
interface CardTokenParams {
cardNumber?: string;
cardholderName?: string;
identificationType?: string;
identificationNumber?: string;
securityCode?: string;
cardExpirationMonth?: string;
cardExpirationYear?: string;
cardId?: string;
}
interface CardTokenUpdateParams {
securityCode?: string;
cardExpirationMonth?: string;
cardExpirationYear?: string;
token?: string;
}
interface CardTokenUpdateParams {
securityCode?: string;
cardExpirationMonth?: string;
cardExpirationYear?: string;
token?: string;
}
interface MercadoPagoCore {
getIdentificationTypes(): Promise<IdentificationTypesResponse[]>;
getPaymentMethods(
paymentMethodsParams: PaymentMethodsParams
): Promise<PaymentMethodsResponse>;
getIssuers(issuersParams: IssuersParams): Promise<IssuersResponse[]>;
getInstallments(
installmentsParams: InstallmentsParams
): Promise<InstallmentsResponse[]>;
createCardToken(
cardTokenParams: CardTokenParams
): Promise<shared.CardTokenResponse>;
updateCardToken(
CardTokenUpdateParams: CardTokenUpdateParams
): Promise<shared.CardTokenResponse>;
interface MercadoPagoCore {
getIdentificationTypes(): Promise<IdentificationTypesResponse[]>;
getPaymentMethods(paymentMethodsParams: PaymentMethodsParams): Promise<PaymentMethodsResponse>;
getIssuers(issuersParams: IssuersParams): Promise<IssuersResponse[]>;
getInstallments(installmentsParams: InstallmentsParams): Promise<InstallmentsResponse[]>;
createCardToken(cardTokenParams: CardTokenParams): Promise<shared.CardTokenResponse>;
updateCardToken(CardTokenUpdateParams: CardTokenUpdateParams): Promise<shared.CardTokenResponse>;
fields: fields.Fields;
fields: fields.Fields;
bricks(style: bricks.BricksStyle): bricks.Bricks;
bricks(style?: bricks.BricksStyle): bricks.Bricks;
cardForm(options: cardform.CardFormOptions): cardform.CardForm;
}
cardForm(options: cardform.CardFormOptions): cardform.CardForm;
}
}

View File

@@ -7,9 +7,9 @@
/// <reference path="core.d.ts" />
declare namespace mercadopago {
interface MercadoPago {
new(publicKey: string, options: mercadopagocore.Options): mercadopagocore.MercadoPagoCore;
}
interface MercadoPago {
new (publicKey: string, options?: mercadopagocore.Options): mercadopagocore.MercadoPagoCore;
}
}
declare var MercadoPago: mercadopago.MercadoPago;

View File

@@ -1,42 +1,40 @@
// initiate MP library
const mpInstance = new MercadoPago("pk", {});
const mpInstance = new MercadoPago('pk', {});
mpInstance.getIdentificationTypes();
mpInstance.getInstallments({ amount: "100", bin: "123456" });
mpInstance.getIssuers({ bin: "123456" });
mpInstance.getPaymentMethods({ bin: "123456" });
mpInstance.createCardToken(
{
cardholderName: "APRO",
identificationType: "<BUYER_IDENTIFICATION_TYPE>",
identificationNumber: "<BUYER_IDENTIFICATION_NUMBER>",
cardExpirationMonth: "<CARD_EXPIRATION_MONTH>",
cardExpirationYear: "<CARD_EXPIRATION_MONTH>",
cardNumber: "<CARD_NUMBER>",
securityCode: "<SECURITY_CODE>"
}
);
mpInstance.getInstallments({ amount: '100', bin: '123456' });
mpInstance.getIssuers({ bin: '123456' });
mpInstance.getPaymentMethods({ bin: '123456' });
mpInstance.createCardToken({
cardholderName: 'APRO',
identificationType: '<BUYER_IDENTIFICATION_TYPE>',
identificationNumber: '<BUYER_IDENTIFICATION_NUMBER>',
cardExpirationMonth: '<CARD_EXPIRATION_MONTH>',
cardExpirationYear: '<CARD_EXPIRATION_MONTH>',
cardNumber: '<CARD_NUMBER>',
securityCode: '<SECURITY_CODE>',
});
const brickBuilder = mpInstance.bricks({});
brickBuilder.isInitialized();
brickBuilder.create('cardPayment', 'container', {
initialization: {
amount: 100
},
callbacks: {
onSubmit: (formData: any, additionalData: any) => {
return new Promise(() => {
console.log(formData, additionalData);
});
}
}
initialization: {
amount: 100,
},
callbacks: {
onSubmit: (formData: any, additionalData: any) => {
return new Promise(() => {
console.log(formData, additionalData);
});
},
},
});
const fieldInstance = mpInstance.fields.create("cardNumber", {});
fieldInstance.mount("containerId");
const fieldInstance = mpInstance.fields.create('cardNumber', {});
fieldInstance.mount('containerId');
fieldInstance.update({});
fieldInstance.on('validityChange', (args: any) => { });
fieldInstance.on('validityChange', (args: any) => {});
mpInstance.fields.createCardToken({}, undefined);
fieldInstance.unmount();

View File

@@ -1,328 +1,336 @@
declare namespace bricks {
interface BrickError {
type: "non_critical" | "critical";
cause: string;
message: string;
}
interface BrickError {
type: 'non_critical' | 'critical';
cause: string;
message: string;
}
interface BrickCallbacks {
onSubmit: (
formData: CardFormData | PaymentFormData,
param2?: AdditionalCardFormData | AdditionalPaymentFormData
) => Promise<void>;
onReady?: () => void;
onError?: (error: BrickError) => void;
onBinChange?: (bin: string) => void;
}
interface BrickCallbacks {
onSubmit: (
formData: CardFormData | PaymentFormData,
param2?: AdditionalCardFormData | AdditionalPaymentFormData,
) => Promise<void>;
onReady?: () => void;
onError?: (error: BrickError) => void;
onBinChange?: (bin: string) => void;
}
interface PayerAddress {
zipCode?: string;
federalUnit?: string;
city?: string;
streetName?: string;
streetNumber?: string;
neighborhood?: string;
complement?: string;
}
interface PayerAddress {
zipCode?: string;
federalUnit?: string;
city?: string;
streetName?: string;
streetNumber?: string;
neighborhood?: string;
complement?: string;
}
interface Payer {
email?: string;
identification?: PayerIdentification;
customerId?: string;
cardsIds?: string[];
address?: PayerAddress;
firstName?: string;
lastName?: string;
}
type EntityType = 'individual' | 'association';
interface CustomizableTexts {
[key: string]: string | { [key: string]: string };
}
interface Payer {
email?: string;
identification?: PayerIdentification;
customerId?: string;
cardsIds?: string[];
address?: PayerAddress;
firstName?: string;
lastName?: string;
entityType?: EntityType;
}
enum PaymentOption {
CREDIT_CARD_FORM = "creditCardForm",
DEBIT_CARD_FORM = "debitCardForm",
SAVED_CARD_FORM = "savedCardForm",
TICKET_FORM = "ticketForm",
BANK_TRANSFER_FORM = "bankTransferForm",
MERCADO_PAGO_FORM = "walletForm",
ONBOARDING_CREDITS_FORM = "creditForm",
}
interface CustomizableTexts {
[key: string]: string | { [key: string]: string };
}
interface PaymentOptions {
[PaymentOption.CREDIT_CARD_FORM]?: boolean;
[PaymentOption.DEBIT_CARD_FORM]?: boolean;
[PaymentOption.SAVED_CARD_FORM]?: string | boolean;
[PaymentOption.TICKET_FORM]?: boolean;
[PaymentOption.BANK_TRANSFER_FORM]?: boolean;
[PaymentOption.MERCADO_PAGO_FORM]?: boolean;
[PaymentOption.ONBOARDING_CREDITS_FORM]?: boolean;
}
enum PaymentOption {
CREDIT_CARD_FORM = 'creditCardForm',
DEBIT_CARD_FORM = 'debitCardForm',
SAVED_CARD_FORM = 'savedCardForm',
TICKET_FORM = 'ticketForm',
BANK_TRANSFER_FORM = 'bankTransferForm',
MERCADO_PAGO_FORM = 'walletForm',
ONBOARDING_CREDITS_FORM = 'creditForm',
}
interface PaymentOptionsBooleanOnly extends PaymentOptions {
[PaymentOption.SAVED_CARD_FORM]?: boolean;
}
interface PaymentOptions {
[PaymentOption.CREDIT_CARD_FORM]?: boolean;
[PaymentOption.DEBIT_CARD_FORM]?: boolean;
[PaymentOption.SAVED_CARD_FORM]?: string | boolean;
[PaymentOption.TICKET_FORM]?: boolean;
[PaymentOption.BANK_TRANSFER_FORM]?: boolean;
[PaymentOption.MERCADO_PAGO_FORM]?: boolean;
[PaymentOption.ONBOARDING_CREDITS_FORM]?: boolean;
}
enum WalletButtonBackground {
MERCADO_PAGO_COLOR = "default",
BLACK = "black",
BLUE = "blue",
WHITE = "white",
}
interface PaymentOptionsBooleanOnly extends PaymentOptions {
[PaymentOption.SAVED_CARD_FORM]?: boolean;
}
enum WalletButtonValuePropColor {
WHITE = "white",
GREY = "grey",
}
enum WalletButtonBackground {
MERCADO_PAGO_COLOR = 'default',
BLACK = 'black',
BLUE = 'blue',
WHITE = 'white',
}
enum WalletButtonAction {
PAY = "pay",
BUY = "buy",
}
enum WalletButtonValuePropColor {
WHITE = 'white',
GREY = 'grey',
}
enum WalletButtonValueProp {
PRACTICALITY = "practicality",
CONVENIENCE = "convenience",
SECURITY_DETAILS = "security_details",
SECURITY_SAFETY = "security_safety",
}
enum WalletButtonAction {
PAY = 'pay',
BUY = 'buy',
}
enum WalletButtonRedirectMode {
MODAL = "modal",
SELF = "self",
BLANK = "blank",
}
enum WalletButtonValueProp {
PRACTICALITY = 'practicality',
CONVENIENCE = 'convenience',
SECURITY_DETAILS = 'security_details',
SECURITY_SAFETY = 'security_safety',
}
interface BrickVisualCustomization {
texts?: CustomizableTexts;
font?: string;
style?: BricksStyle;
hideNewCardForm?: boolean;
hidePaymentButton?: boolean;
hideFormTitle?: boolean;
hideValuePropsFrom?: PaymentOptionsBooleanOnly;
defaultPaymentOption?: PaymentOptions;
preserveSavedCardsOrder?: boolean;
hideRedirectionPanel?: boolean;
showExternalReference?: boolean;
hideStatusDetails?: boolean;
hideTransactionDate?: boolean;
buttonBackground?: WalletButtonBackground;
borderRadius?: string;
valuePropColor?: WalletButtonValuePropColor;
buttonHeight?: string;
verticalPadding?: string;
horizontalPadding?: string;
hideValueProp?: boolean;
}
enum WalletButtonRedirectMode {
MODAL = 'modal',
SELF = 'self',
BLANK = 'blank',
}
type GenericPaymentMethod = string | string[];
interface BrickVisualCustomization {
texts?: CustomizableTexts;
font?: string;
style?: BricksStyle;
hideNewCardForm?: boolean;
hidePaymentButton?: boolean;
hideFormTitle?: boolean;
hideValuePropsFrom?: PaymentOptionsBooleanOnly;
defaultPaymentOption?: PaymentOptions;
preserveSavedCardsOrder?: boolean;
hideRedirectionPanel?: boolean;
showExternalReference?: boolean;
hideStatusDetails?: boolean;
hideTransactionDate?: boolean;
buttonBackground?: WalletButtonBackground;
borderRadius?: string;
valuePropColor?: WalletButtonValuePropColor;
buttonHeight?: string;
verticalPadding?: string;
horizontalPadding?: string;
hideValueProp?: boolean;
}
interface PaymentMethods {
maxInstallments?: number;
minInstallments?: number;
creditCard?: GenericPaymentMethod;
debitCard?: GenericPaymentMethod;
ticket?: GenericPaymentMethod;
bankTransfer?: GenericPaymentMethod;
atm?: GenericPaymentMethod;
mercadoPago?: GenericPaymentMethod;
}
type GenericPaymentMethod = string | string[];
interface CheckoutThemes {
headerColor?: string;
elementsColor?: string;
}
interface PaymentMethods {
maxInstallments?: number;
minInstallments?: number;
creditCard?: GenericPaymentMethod;
debitCard?: GenericPaymentMethod;
ticket?: GenericPaymentMethod;
bankTransfer?: GenericPaymentMethod;
atm?: GenericPaymentMethod;
mercadoPago?: GenericPaymentMethod;
}
interface Checkout {
theme: CheckoutThemes;
}
interface CheckoutThemes {
headerColor?: string;
elementsColor?: string;
}
interface WalletButtonTextCustomization {
action: WalletButtonAction;
valueProp: WalletButtonValueProp;
}
interface Checkout {
theme: CheckoutThemes;
}
interface StatusBrickBackUrls {
error: string;
return: string;
}
interface WalletButtonTextCustomization {
action: WalletButtonAction;
valueProp: WalletButtonValueProp;
}
interface BrickCustomization {
visual?: BrickVisualCustomization;
paymentMethods?: PaymentMethods;
checkout?: Checkout;
texts?: WalletButtonTextCustomization;
backUrls?: StatusBrickBackUrls;
}
interface StatusBrickBackUrls {
error: string;
return: string;
}
interface BrickInitialization {
amount?: number;
payer?: Payer;
preferenceId?: string;
paymentId?: number;
externalReference?: string;
redirectMode?: WalletButtonRedirectMode;
}
interface BrickCustomization {
visual?: BrickVisualCustomization;
paymentMethods?: PaymentMethods;
checkout?: Checkout;
texts?: WalletButtonTextCustomization;
backUrls?: StatusBrickBackUrls;
}
interface BrickSettings {
// For a more detailed view of each Brick`s supported settings, please check the documentation at: https://github.com/mercadopago/sdk-js/blob/main/API/bricks/index.md
callbacks?: BrickCallbacks;
initialization?: BrickInitialization;
customization?: BrickCustomization;
}
interface StatusBrickAdditionalData {
externalResourceUrl: string;
creq: string;
}
interface BricksStyle {
theme?: "default" | "dark" | "flat" | "bootstrap";
customVariables?: CustomVariables;
}
interface BrickInitialization {
amount?: number;
payer?: Payer;
preferenceId?: string;
paymentId?: number;
externalReference?: string;
redirectMode?: WalletButtonRedirectMode;
additionalData?: StatusBrickAdditionalData;
}
interface CustomVariables {
textPrimaryColor?: string;
textSecondaryColor?: string;
inputBackgroundColor?: string;
formBackgroundColor?: string;
baseColor?: string;
baseColorFirstVariant?: string;
baseColorSecondVariant?: string;
errorColor?: string;
successColor?: string;
outlinePrimaryColor?: string;
outlineSecondaryColor?: string;
buttonTextColor?: string;
fontSizeExtraSmall?: string;
fontSizeSmall?: string;
fontSizeMedium?: string;
fontSizeLarge?: string;
fontSizeExtraLarge?: string;
fontWeightNormal?: string;
fontWeightSemiBold?: string;
formInputsTextTransform?: string;
inputVerticalPadding?: string;
inputHorizontalPadding?: string;
inputFocusedBoxShadow?: string;
inputErrorFocusedBoxShadow?: string;
inputBorderWidth?: string;
inputFocusedBorderWidth?: string;
borderRadiusSmall?: string;
borderRadiusMedium?: string;
borderRadiusLarge?: string;
borderRadiusFull?: string;
formPadding?: string;
secondaryColor?: string;
warningColor?: string;
fontSizeExtraExtraLarge?: string;
}
interface BrickSettings {
// For a more detailed view of each Brick`s supported settings, please check the documentation at: https://github.com/mercadopago/sdk-js/blob/main/API/bricks/index.md
callbacks?: BrickCallbacks;
initialization?: BrickInitialization;
customization?: BrickCustomization;
}
interface PayerIdentification {
type: string;
number: string;
}
interface BricksStyle {
theme?: 'default' | 'dark' | 'flat' | 'bootstrap';
customVariables?: CustomVariables;
}
interface PayerAddressAPI {
zip_code: string;
federal_unit: string;
city: string;
street_name: string;
street_number: string;
neighborhood: string;
}
interface CustomVariables {
textPrimaryColor?: string;
textSecondaryColor?: string;
inputBackgroundColor?: string;
formBackgroundColor?: string;
baseColor?: string;
baseColorFirstVariant?: string;
baseColorSecondVariant?: string;
errorColor?: string;
successColor?: string;
outlinePrimaryColor?: string;
outlineSecondaryColor?: string;
buttonTextColor?: string;
fontSizeExtraSmall?: string;
fontSizeSmall?: string;
fontSizeMedium?: string;
fontSizeLarge?: string;
fontSizeExtraLarge?: string;
fontWeightNormal?: string;
fontWeightSemiBold?: string;
formInputsTextTransform?: string;
inputVerticalPadding?: string;
inputHorizontalPadding?: string;
inputFocusedBoxShadow?: string;
inputErrorFocusedBoxShadow?: string;
inputBorderWidth?: string;
inputFocusedBorderWidth?: string;
borderRadiusSmall?: string;
borderRadiusMedium?: string;
borderRadiusLarge?: string;
borderRadiusFull?: string;
formPadding?: string;
secondaryColor?: string;
warningColor?: string;
fontSizeExtraExtraLarge?: string;
}
interface PayerAPI {
email?: string;
identification?: PayerIdentification;
address?: PayerAddressAPI;
first_name?: string;
last_name?: string;
}
interface PayerIdentification {
type: string;
number: string;
}
enum PaymentType {
CREDIT_CARD = "credit_card",
DEBIT_CARD = "debit_card",
ICKET = "ticket",
BANK_TRANSFER = "bank_transfer",
WALLET_PURCHASE = "wallet_purchase",
ONBOARDING_CREDITS = "onboarding_credits",
ATM = "atm",
ATM_ONLINE = "atm_online",
NONE = "",
}
interface PayerAddressAPI {
zip_code: string;
federal_unit: string;
city: string;
street_name: string;
street_number: string;
neighborhood: string;
}
interface SavedCardPayer {
type: "customer";
id: string;
}
interface PayerAPI {
email?: string;
identification?: PayerIdentification;
address?: PayerAddressAPI;
first_name?: string;
last_name?: string;
entity_type?: EntityType;
}
interface CardFormData {
token: string;
issuer_id: string | null;
payment_method_id: string;
transaction_amount: number;
payment_method_option_id?: string;
processing_mode?: string;
installments: number;
payer: PayerAPI;
}
enum PaymentType {
CREDIT_CARD = 'credit_card',
DEBIT_CARD = 'debit_card',
ICKET = 'ticket',
BANK_TRANSFER = 'bank_transfer',
WALLET_PURCHASE = 'wallet_purchase',
ONBOARDING_CREDITS = 'onboarding_credits',
ATM = 'atm',
ATM_ONLINE = 'atm_online',
NONE = '',
}
interface SavedCardFormData {
token: string;
issuer_id: string | null;
payment_method_id: string;
transaction_amount: number;
payment_method_option_id?: string;
processing_mode?: string;
installments: number;
payer: SavedCardPayer;
}
interface SavedCardPayer {
type: 'customer';
id: string;
}
interface TicketFormData {
transaction_amount: number;
payment_method_id: string;
payer: PayerAPI;
}
interface CardFormData {
token: string;
issuer_id: string | null;
payment_method_id: string;
transaction_amount: number;
payment_method_option_id?: string;
processing_mode?: string;
installments: number;
payer: PayerAPI;
}
interface AdditionalSavedCardFormData {
bin: string;
}
interface SavedCardFormData {
token: string;
issuer_id: string | null;
payment_method_id: string;
transaction_amount: number;
payment_method_option_id?: string;
processing_mode?: string;
installments: number;
payer: SavedCardPayer;
}
interface AdditionalCardFormData {
bin: string;
}
interface Metadata {
payment_point: string;
payment_mode: string;
}
type AdditionalTicketFormData = Record<string, unknown>;
interface TransactionDetails {
financial_institution: string;
}
type AdditionalPaymentFormData =
| AdditionalCardFormData
| AdditionalSavedCardFormData
| AdditionalTicketFormData;
interface TicketFormData {
transaction_amount: number;
payment_method_id: string;
payer: PayerAPI;
metadata?: Metadata;
transaction_details?: TransactionDetails;
}
interface PaymentFormData {
paymentType: PaymentType;
selectedPaymentMethod: PaymentType;
formData?: CardFormData | SavedCardFormData | TicketFormData | null;
additionalData?:
| AdditionalSavedCardFormData
| AdditionalCardFormData
| AdditionalTicketFormData
| null;
}
interface AdditionalSavedCardFormData {
bin: string;
}
interface BrickController {
unmount: () => void;
getFormData: () => Promise<CardFormData | PaymentFormData>;
getAdditionalData: () => Promise<
AdditionalCardFormData | AdditionalPaymentFormData
>;
}
interface AdditionalCardFormData {
bin: string;
}
type BrickTypes = 'cardPayment' | 'payment' | 'statusScreen' | 'wallet';
type AdditionalTicketFormData = Record<string, unknown>;
interface Bricks {
isInitialized(): boolean;
create(
brick: BrickTypes,
containerId: string,
settings: BrickSettings
): Promise<BrickController>;
}
type AdditionalPaymentFormData = AdditionalCardFormData | AdditionalSavedCardFormData | AdditionalTicketFormData;
interface PaymentFormData {
paymentType: PaymentType;
selectedPaymentMethod: PaymentType;
formData?: CardFormData | SavedCardFormData | TicketFormData | null;
additionalData?: AdditionalSavedCardFormData | AdditionalCardFormData | AdditionalTicketFormData | null;
}
interface BrickController {
unmount: () => void;
getFormData: () => Promise<CardFormData | PaymentFormData>;
getAdditionalData: () => Promise<AdditionalCardFormData | AdditionalPaymentFormData>;
}
type BrickTypes = 'cardPayment' | 'payment' | 'statusScreen' | 'wallet';
interface Bricks {
isInitialized(): boolean;
create(brick: BrickTypes, containerId: string, settings: BrickSettings): Promise<BrickController>;
}
}

View File

@@ -1,173 +1,157 @@
/// <reference types="../shared.d.ts" />
declare namespace cardform {
interface CardFormData {
amount: string;
token: string;
installments: string;
paymentMethodId: string;
issuerId: string;
identificationType: string;
identificationNumber: string;
processingMode: string;
merchantAccountId?: string;
cardholderEmail?: string;
}
interface CardFormData {
amount: string;
token: string;
installments: string;
paymentMethodId: string;
issuerId: string;
identificationType: string;
identificationNumber: string;
processingMode: string;
merchantAccountId?: string;
cardholderEmail?: string;
}
interface UpdatableProperties {
style?: shared.FieldStyle;
placeholder?: string;
settings?: shared.SecurityCode;
}
interface UpdatableProperties {
style?: shared.FieldStyle;
placeholder?: string;
settings?: shared.SecurityCode;
}
interface EventListener {
(evt: Event): void;
}
interface EventListener {
(evt: Event): void;
}
interface CardFormListener {
event: string[];
fn: EventListener;
}
interface CardFormListener {
event: string[];
fn: EventListener;
}
type CardFormListeners = CardFormListener[];
type CardFormListeners = CardFormListener[];
interface CardFormProperties {
id: string;
placeholder?: string;
element?:
| HTMLElement
| HTMLInputElement
| HTMLSelectElement
| HTMLFormElement;
listeners?: CardFormListeners;
hidden?: boolean;
style?: { [key: string]: string };
customFonts?: shared.CustomFonts[];
mode?: string;
}
interface CardFormProperties {
id: string;
placeholder?: string;
element?: HTMLElement | HTMLInputElement | HTMLSelectElement | HTMLFormElement;
listeners?: CardFormListeners;
hidden?: boolean;
style?: { [key: string]: string };
customFonts?: shared.CustomFonts[];
mode?: string;
}
type AVAILABLE_PROCESSING_MODE = "aggregator" | "gateway";
type AVAILABLE_PROCESSING_MODE = 'aggregator' | 'gateway';
interface Error { message: string; code: string; }
interface Error {
message: string;
code: string;
}
interface IdentificationTypesResponseCardForm {
id: string;
name: string;
}
interface IdentificationTypesResponseCardForm {
id: string;
name: string;
}
interface InstallmentsResponseCardForm {
merchant_account_id?: string;
payer_costs: shared.PayerCost[];
}
interface InstallmentsResponseCardForm {
merchant_account_id?: string;
payer_costs: shared.PayerCost[];
}
interface PaymentMethodsResponseCardForm {
issuer: shared.Issuer;
id: string;
payment_type_id: string;
thumbnail: string;
marketplace: string;
deferred_capture: string;
agreements: unknown[];
labels: string[];
name: string;
site_id: string;
processing_mode: string;
additional_info_needed: string[];
status: string;
settings: shared.Setting[];
merchant_account_id: string;
}
interface PaymentMethodsResponseCardForm {
issuer: shared.Issuer;
id: string;
payment_type_id: string;
thumbnail: string;
marketplace: string;
deferred_capture: string;
agreements: unknown[];
labels: string[];
name: string;
site_id: string;
processing_mode: string;
additional_info_needed: string[];
status: string;
settings: shared.Setting[];
merchant_account_id: string;
}
interface CardTokenResponseCardForm {
token: string;
}
interface CardTokenResponseCardForm {
token: string;
}
interface IssuersResponseCardForm {
id: string;
name: string;
thumbnail: string;
processing_mode: string;
merchant_account_id: string;
}
interface IssuersResponseCardForm {
id: string;
name: string;
thumbnail: string;
processing_mode: string;
merchant_account_id: string;
}
type FechingCallback = () => unknown;
type OnFormMounted = (error?: Error) => void;
type OnFormUnmounted = (error?: Error) => void;
type OnIdentificationTypesReceived = (
error?: Error,
response?: IdentificationTypesResponseCardForm[]
) => void;
type OnInstallmentsReceived = (
error?: Error,
response?: InstallmentsResponseCardForm
) => void;
type OnPaymentMethodsReceived = (
error?: Error,
response?: PaymentMethodsResponseCardForm[]
) => void;
type OnCardTokenReceived = (
error?: Error,
response?: CardTokenResponseCardForm
) => void;
type OnIssuersReceived = (
error?: Error,
response?: IssuersResponseCardForm[]
) => void;
type OnSubmit = (event: Event) => void;
type OnFetching = (name: string) => FechingCallback;
type OnReady = () => void;
type OnValidityChange = (error?: Error[], field?: string) => void;
type OnError = (error?: Error[], event?: string) => void;
type OnBinChange = (bin: string) => void;
type FechingCallback = () => unknown;
type OnFormMounted = (error?: Error) => void;
type OnFormUnmounted = (error?: Error) => void;
type OnIdentificationTypesReceived = (error?: Error, response?: IdentificationTypesResponseCardForm[]) => void;
type OnInstallmentsReceived = (error?: Error, response?: InstallmentsResponseCardForm) => void;
type OnPaymentMethodsReceived = (error?: Error, response?: PaymentMethodsResponseCardForm[]) => void;
type OnCardTokenReceived = (error?: Error, response?: CardTokenResponseCardForm) => void;
type OnIssuersReceived = (error?: Error, response?: IssuersResponseCardForm[]) => void;
type OnSubmit = (event: Event) => void;
type OnFetching = (name: string) => FechingCallback;
type OnReady = () => void;
type OnValidityChange = (error?: Error[], field?: string) => void;
type OnError = (error?: Error[], event?: string) => void;
type OnBinChange = (bin: string) => void;
interface Callbacks {
onFormMounted?: OnFormMounted;
onFormUnmounted?: OnFormUnmounted;
onIdentificationTypesReceived?: OnIdentificationTypesReceived;
onPaymentMethodsReceived?: OnPaymentMethodsReceived;
onIssuersReceived?: OnIssuersReceived;
onInstallmentsReceived?: OnInstallmentsReceived;
onCardTokenReceived?: OnCardTokenReceived;
onSubmit?: OnSubmit;
onFetching?: OnFetching;
onReady?: OnReady;
onValidityChange?: OnValidityChange;
onError?: OnError;
onBinChange?: OnBinChange;
}
interface Callbacks {
onFormMounted?: OnFormMounted;
onFormUnmounted?: OnFormUnmounted;
onIdentificationTypesReceived?: OnIdentificationTypesReceived;
onPaymentMethodsReceived?: OnPaymentMethodsReceived;
onIssuersReceived?: OnIssuersReceived;
onInstallmentsReceived?: OnInstallmentsReceived;
onCardTokenReceived?: OnCardTokenReceived;
onSubmit?: OnSubmit;
onFetching?: OnFetching;
onReady?: OnReady;
onValidityChange?: OnValidityChange;
onError?: OnError;
onBinChange?: OnBinChange;
}
interface CardFormMap {
id: string;
cardholderName: CardFormProperties;
cardholderEmail: CardFormProperties;
cardNumber: CardFormProperties;
securityCode: CardFormProperties;
installments: CardFormProperties;
cardExpirationMonth?: CardFormProperties;
cardExpirationYear?: CardFormProperties;
cardExpirationDate?: CardFormProperties;
identificationType: CardFormProperties;
identificationNumber: CardFormProperties;
issuer: CardFormProperties;
expirationDate?: CardFormProperties;
expirationMonth?: CardFormProperties;
}
interface CardFormMap {
id: string;
cardholderName: CardFormProperties;
cardholderEmail: CardFormProperties;
cardNumber: CardFormProperties;
securityCode: CardFormProperties;
installments: CardFormProperties;
cardExpirationMonth?: CardFormProperties;
cardExpirationYear?: CardFormProperties;
cardExpirationDate?: CardFormProperties;
identificationType: CardFormProperties;
identificationNumber: CardFormProperties;
issuer: CardFormProperties;
expirationDate?: CardFormProperties;
expirationMonth?: CardFormProperties;
}
interface CardFormOptions {
form: CardFormMap;
callbacks: Callbacks;
amount: number | string;
processingMode: AVAILABLE_PROCESSING_MODE;
autoMount?: boolean;
iframe?: boolean;
}
interface CardFormOptions {
form: CardFormMap;
callbacks: Callbacks;
amount: number | string;
processingMode: AVAILABLE_PROCESSING_MODE;
autoMount?: boolean;
iframe?: boolean;
}
interface CardForm {
mount(): void;
unmount(): void;
submit(): void;
update(field: string, properties: UpdatableProperties): void;
createCardToken(): Promise<CardTokenResponseCardForm | undefined>;
getCardFormData(): CardFormData;
}
interface CardForm {
mount(): void;
unmount(): void;
submit(): void;
update(field: string, properties: UpdatableProperties): void;
createCardToken(): Promise<CardTokenResponseCardForm | undefined>;
getCardFormData(): CardFormData;
}
}

View File

@@ -14,13 +14,17 @@ declare namespace fields {
enableLuhnValidation?: boolean;
}
type FieldsOptions<T> =
T extends 'cardNumber' ? CardNumberOptions :
T extends 'securityCode' ? BaseFieldsOptions :
T extends 'expirationMonth' ? BaseFieldsOptions :
T extends 'expirationYear' ? DateYearFieldsOptions :
T extends 'expirationDate' ? DateYearFieldsOptions :
never;
type FieldsOptions<T> = T extends 'cardNumber'
? CardNumberOptions
: T extends 'securityCode'
? BaseFieldsOptions
: T extends 'expirationMonth'
? BaseFieldsOptions
: T extends 'expirationYear'
? DateYearFieldsOptions
: T extends 'expirationDate'
? DateYearFieldsOptions
: never;
type FieldEvent = 'blur' | 'focus' | 'change' | 'ready' | 'validityChange' | 'error' | 'binChange' | 'paste';
@@ -56,33 +60,43 @@ declare namespace fields {
interface ErrorMessage<FieldName> {
message: string;
cause:
FieldName extends 'cardNumber' ? CardNumberCause :
FieldName extends 'securityCode' ? SecurityCodeCause :
FieldName extends 'expirationMonth' ? ExpirationDateCause :
FieldName extends 'expirationYear' ? ExpirationYearCause :
FieldName extends 'expirationDate' ? ExpirationDateCause :
never;
cause: FieldName extends 'cardNumber'
? CardNumberCause
: FieldName extends 'securityCode'
? SecurityCodeCause
: FieldName extends 'expirationMonth'
? ExpirationDateCause
: FieldName extends 'expirationYear'
? ExpirationYearCause
: FieldName extends 'expirationDate'
? ExpirationDateCause
: never;
}
interface ValidityChangeArg<FieldName> extends DefaultArg {
errorMessages: ErrorMessage<FieldName[]>;
}
type CallbackArgs<FieldEvent, FieldName> =
FieldEvent extends 'blur' ? DefaultArg :
FieldEvent extends 'focus' ? DefaultArg :
FieldEvent extends 'ready' ? DefaultArg :
FieldEvent extends 'change' ? DefaultArg :
FieldEvent extends 'validityChange' ? ValidityChangeArg<FieldName> :
FieldEvent extends 'error' ? ErrorArg :
FieldEvent extends 'binChange' ? BinChangeArg :
DefaultArg;
type CallbackArgs<FieldEvent, FieldName> = FieldEvent extends 'blur'
? DefaultArg
: FieldEvent extends 'focus'
? DefaultArg
: FieldEvent extends 'ready'
? DefaultArg
: FieldEvent extends 'change'
? DefaultArg
: FieldEvent extends 'validityChange'
? ValidityChangeArg<FieldName>
: FieldEvent extends 'error'
? ErrorArg
: FieldEvent extends 'binChange'
? BinChangeArg
: DefaultArg;
interface Field {
mount: (container: string) => void;
unmount: () => void;
on: < FieldEvent> (event: FieldEvent, callback: (args: CallbackArgs<FieldEvent, FieldName>) => void) => void;
on: <FieldEvent>(event: FieldEvent, callback: (args: CallbackArgs<FieldEvent, FieldName>) => void) => void;
update: (properties: FieldsUpdatableProperties) => void;
focus: () => void;
blur: () => void;
@@ -97,17 +111,20 @@ declare namespace fields {
type OptionsToken =
| {
group: string;
productId?: string;
fingerprint?: unknown;
requireEsc?: boolean;
}
group: string;
productId?: string;
fingerprint?: unknown;
requireEsc?: boolean;
}
| string
| undefined;
interface Fields {
create(field: FieldName, options?: FieldsOptions<FieldName>): Field;
createCardToken(nonPCIData: FieldsCardTokenParams, options: OptionsToken): Promise<shared.CardTokenResponse | undefined>;
createCardToken(
nonPCIData: FieldsCardTokenParams,
options: OptionsToken,
): Promise<shared.CardTokenResponse | undefined>;
updateCardToken(token: string, options: OptionsToken): Promise<shared.CardTokenResponse | undefined>;
}
}

View File

@@ -67,38 +67,38 @@ declare namespace shared {
interface FieldStyle {
color?: string;
"font-family"?: string;
'font-family'?: string;
fontFamily?: string;
"font-size"?: string;
'font-size'?: string;
fontSize?: string;
"font-style"?: string;
'font-style'?: string;
fontStyle?: string;
"font-variant"?: string;
'font-variant'?: string;
fontVariant?: string;
"font-weight"?: string;
'font-weight'?: string;
fontWeight?: string;
height?: string;
margin?: string;
"margin-bottom"?: string;
'margin-bottom'?: string;
marginBottom?: string;
"margin-left"?: string;
'margin-left'?: string;
marginLeft?: string;
"margin-right"?: string;
'margin-right'?: string;
marginRight?: string;
"margin-top"?: string;
'margin-top'?: string;
marginTop?: string;
padding?: string;
"padding-bottom"?: string;
'padding-bottom'?: string;
paddingBottom?: string;
"padding-left"?: string;
'padding-left'?: string;
paddingLeft?: string;
"padding-right"?: string;
'padding-right'?: string;
paddingRight?: string;
"padding-top"?: string;
'padding-top'?: string;
paddingTop?: string;
"placeholder-color"?: string;
'placeholder-color'?: string;
placeholderColor?: string;
"text-align"?: string;
'text-align'?: string;
textAlign?: string;
width?: string;
}