Files
DefinitelyTyped/types/tpdirect/tpdirect-tests.ts
YuJack ba94778eba 🤖 Merge PR #49967 feature: Add TapPay payment typing. by @Yu-Jack
* feature: Add TapPay payment typing.

* fix: remove rules from tslint.json

* fix: fix code style

* feature: fix typo and add more detail for merchant_reference_info field

* fix: change project url to official documentation

* feature: remove README and change major version in the header of index.d.ts
2020-12-09 16:49:54 -08:00

232 lines
5.3 KiB
TypeScript

/**
* Test the startup function
*/
// $ExpectType void
TPDirect.setupSDK(1, "appKey", "sandbox");
// $ExpectType void
TPDirect.setupSDK(1, "appKey", "production");
/**
* Test DirectPay
*/
// $ExpectType void
TPDirect.card.getPrime((result) => {
/**
* Only test different field with other payment response
*/
result.clientip; // $ExpectType Pick<BaseResult, "client_ip">
result.card.countrycode; // $ExpectType string
result.card.lastfour; // $ExpectType string
});
// $ExpectType UpdateResult
TPDirect.card.getTappayFieldsStatus();
// $ExpectType void
TPDirect.card.onUpdate((update) => {
update.cardType; // $ExpectType "mastercard" | "visa" | "jcb" | "amex" | "unionpay" | "unknown"
});
// $ExpectType void
TPDirect.card.setup({
number: {
element: "#body",
placeholder: "**** **** **** ****"
},
ccv: {
element: "#body",
placeholder: "***"
},
expirationDate: {
element: "#body",
placeholder: "MM / YYYY"
}
});
// $ExpectType void
TPDirect.card.setup({
number: {
element: "#body",
placeholder: "**** **** **** ****"
},
ccv: {
element: "#body",
placeholder: "***"
},
expirationDate: {
element: "#body",
placeholder: "MM / YYYY"
},
}, {
input: {
color: "red"
}
});
/**
* Test Apple Pay
*/
// $ExpectType boolean
TPDirect.paymentRequestApi.checkAvailability();
// $ExpectType void
TPDirect.paymentRequestApi.setupApplePay({
countryCode: "TW",
merchantIdentifier: "merchantid"
});
TPDirect.paymentRequestApi.getPrime((result) => {
/**
* Only test different field with other payment response
*/
result.client_ip; // $ExpectType string
result.card_info.country_code; // $ExpectType string
result.card_info.last_four; // $ExpectType string
result.card.lastfour; // $ExpectType string
});
/**
* Test Google Pay
*/
// $ExpectType void
TPDirect.googlePay.getPrime((error, prime, result) => {
error.originalError; // // $ExpectType string | Error
prime; // $ExpectType Pick<BaseResult, "prime">
/**
* Only test different field with other payment response
*/
result.client_ip; // $ExpectType string
result.card_info.country_code; // $ExpectType string
result.card_info.last_four; // $ExpectType string
});
// $ExpectType void
TPDirect.googlePay.setupGooglePay({
allowPrepaidCards: true,
allowedCardAuthMethods: ["CRYPTOGRAM_3DS", "PAN_ONLY"],
allowedCountryCodes: ["TW"],
billingAddressFormat: "FULL",
googleMerchantId: "test",
merchantName: "merchant name"
});
// $ExpectType void
TPDirect.googlePay.setupTransactionPrice({
currency: "TWD",
price: "1.00"
});
// $ExpectType void
TPDirect.googlePay.setupGooglePayButton({
color: "black",
el: "#button",
type: "long",
getPrimeCallback: (error, prime, result) => {
error.originalError; // // $ExpectType string | Error
prime; // $ExpectType Pick<BaseResult, "prime">
/**
* Only test different field with other payment response
*/
result.client_ip; // $ExpectType string
result.card_info.country_code; // $ExpectType string
result.card_info.last_four; // $ExpectType string
}
});
// $ExpectType void
TPDirect.googlePay.setupPaymentRequest({
allowedNetworks: ["AMEX"],
currency: "TWD",
price: "1.00"
});
/**
* Test Samsung Pay
*/
// $ExpectType void
TPDirect.samsungPay.getPrime((result) => {
result.client_ip; // $ExpectType string
result.msg; // $ExpectType string
result.prime; // $ExpectType string
result.status; // $ExpectType number
result.card.lastfour; // $ExpectType string
/**
* Only test different field with other payment response
*/
result.client_ip; // $ExpectType string
result.card_info.country_code; // $ExpectType string
result.card_info.last_four; // $ExpectType string
});
// $ExpectType void
TPDirect.samsungPay.setup({
country_code: "tw"
});
// $ExpectType void
TPDirect.samsungPay.setupPaymentRequest({
supportedNetworks: ["AMEX"],
total: {
label: "test",
amount: {
currency: "TWD",
value: "1.00"
}
}
});
// $ExpectType void
TPDirect.samsungPay.setupSamsungPayButton(
"#button", {
color: "black",
shape: "rectangular",
type: "buy"
}
);
/**
* Test LINE Pay
* LINE Pay doesn't have card_info fields
*/
// $ExpectType void
TPDirect.linePay.getPrime((result) => {
result.client_ip; // $ExpectType string
result.msg; // $ExpectType string
result.prime; // $ExpectType string
result.status; // $ExpectType number
result.cs_key; // $ExpectType string
});
/**
* Test JKOPay
* JKOPay doesn't have card_info fields
*/
// $ExpectType void
TPDirect.jkoPay.getPrime((result) => {
result.client_ip; // $ExpectType string
result.msg; // $ExpectType string
result.prime; // $ExpectType string
result.status; // $ExpectType number
});
/**
* Test EasyWallet
* EasyWallet doesn't have card_info fields
*/
// $ExpectType void
TPDirect.easyWallet.getPrime((result) => {
result.client_ip; // $ExpectType string
result.msg; // $ExpectType string
result.prime; // $ExpectType string
result.status; // $ExpectType number
});