mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #65841 [mercadopago-sdk-js] Improve params and returns from constructors and submits by @francineemilia
* adds brick type to differ settings * change Bricks Settings to each brick * creates separated parts to callbacks * creates callback interface to each brick * adds tests * adds space
This commit is contained in:
committed by
GitHub
parent
b366e9ce58
commit
b4341a949e
@@ -32,6 +32,39 @@ brickBuilder.create('cardPayment', 'container', {
|
||||
},
|
||||
});
|
||||
|
||||
brickBuilder.create('payment', 'containerPayment', {
|
||||
initialization: {
|
||||
amount: 100,
|
||||
},
|
||||
callbacks: {
|
||||
onSubmit: (formData: any, additionalData: any) => {
|
||||
return new Promise(() => {
|
||||
console.log(formData, additionalData);
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
brickBuilder.create('statusScreen', 'containerStatusScreen', {
|
||||
initialization: {
|
||||
paymentId: 123456789,
|
||||
},
|
||||
callbacks: {},
|
||||
});
|
||||
|
||||
brickBuilder.create('wallet', 'containerWallet', {
|
||||
initialization: {
|
||||
paymentId: 123456789,
|
||||
},
|
||||
callbacks: {
|
||||
onSubmit: (formData: any, additionalData: any) => {
|
||||
return new Promise(() => {
|
||||
console.log(formData, additionalData);
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const fieldInstance = mpInstance.fields.create('cardNumber', {});
|
||||
fieldInstance.mount('containerId');
|
||||
fieldInstance.update({});
|
||||
|
||||
35
types/mercadopago-sdk-js/modules/bricks.d.ts
vendored
35
types/mercadopago-sdk-js/modules/bricks.d.ts
vendored
@@ -5,15 +5,24 @@ declare namespace bricks {
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface BrickCallbacks {
|
||||
interface Submit<BrickType> {
|
||||
onSubmit: (
|
||||
formData: CardFormData | PaymentFormData,
|
||||
param2?: AdditionalCardFormData | AdditionalPaymentFormData,
|
||||
) => Promise<void>;
|
||||
onReady?: () => void;
|
||||
onError?: (error: BrickError) => void;
|
||||
additionalData?: AdditionalCardFormData | AdditionalPaymentFormData,
|
||||
) => BrickType extends 'wallet' ? Promise<string> : Promise<void>;
|
||||
}
|
||||
|
||||
interface BinChange {
|
||||
onBinChange?: (bin: string) => void;
|
||||
}
|
||||
interface BrickCallbacks {
|
||||
onReady?: () => void;
|
||||
onError?: (error: BrickError) => void;
|
||||
}
|
||||
|
||||
interface WalletBrickCallbacks<BrickType> extends BrickCallbacks, Submit<BrickType> {}
|
||||
interface CardPaymentBrickCallbacks<BrickType> extends BrickCallbacks, Submit<BrickType>, BinChange {}
|
||||
interface PaymentBrickCallbacks<BrickType> extends BrickCallbacks, Submit<BrickType>, BinChange {}
|
||||
|
||||
interface PayerAddress {
|
||||
zipCode?: string;
|
||||
@@ -174,9 +183,15 @@ declare namespace bricks {
|
||||
additionalData?: StatusBrickAdditionalData;
|
||||
}
|
||||
|
||||
interface BrickSettings {
|
||||
interface BrickSettings<BrickType> {
|
||||
// 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;
|
||||
callbacks: BrickType extends 'wallet'
|
||||
? WalletBrickCallbacks<BrickType>
|
||||
: BrickType extends 'cardPayment'
|
||||
? CardPaymentBrickCallbacks<BrickType>
|
||||
: BrickType extends 'payment'
|
||||
? PaymentBrickCallbacks<BrickType>
|
||||
: BrickCallbacks;
|
||||
initialization?: BrickInitialization;
|
||||
customization?: BrickCustomization;
|
||||
}
|
||||
@@ -331,6 +346,10 @@ declare namespace bricks {
|
||||
|
||||
interface Bricks {
|
||||
isInitialized(): boolean;
|
||||
create(brick: BrickTypes, containerId: string, settings: BrickSettings): Promise<BrickController>;
|
||||
create<BrickType extends BrickTypes>(
|
||||
brick: BrickType,
|
||||
containerId: string,
|
||||
settings: BrickSettings<BrickType>,
|
||||
): Promise<BrickController>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user