Added the brand property to the StripeCardData and fix style issues, lint (#13084)

* Add the "brand" field to StipeCardData
Added the StipeCardDataBrand type.
Added the `brand` property to the `StripeCardData` declaration with the type
`'Visa' | 'American Express' | 'MasterCard' | 'Discover JCB' | 'Diners Club' | 'Unknown'`
Reference: https://stripe.com/docs/api#card_object

* Run linter, fix issues. set --strictNullChecks.
Unsure about ambient declaration:
Removed as it seemed to be in error:
  1. case was not correct
  2. the export was the type of the global which is unconditionally defined.
  3. this module does not seem a suitable candidate for a UMD declaration.

* Use header version of 0.0; explain Stripe versioning in comments

* Restore global

* Added tests
This commit is contained in:
Aluan Haddad 2017-01-04 12:20:13 -05:00 committed by Andy
parent f914c29ba3
commit 25ecee9513
4 changed files with 52 additions and 28 deletions

45
stripe/index.d.ts vendored
View File

@ -1,8 +1,10 @@
// Type definitions for stripe
// Type definitions for stripe 0.0
// Project: https://stripe.com/
// Definitions by: Andy Hawkins <https://github.com/a904guy/,http://a904guy.com>, Eric J. Smith <https://github.com/ejsmith/>, Amrit Kahlon <https://github.com/amritk/>, Adam Cmiel <https://github.com/adamcmiel>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare const Stripe: StripeStatic;
interface StripeStatic {
applePay: StripeApplePay;
setPublishableKey(key: string): void;
@ -49,6 +51,8 @@ interface StripeError {
param?: string;
}
type StripeCardDataBrand = 'Visa' | 'American Express' | 'MasterCard' | 'Discover JCB' | 'Diners Club' | 'Unknown';
interface StripeCardData {
object: string;
last4: string;
@ -62,18 +66,17 @@ interface StripeCardData {
address_state?: string;
address_zip?: string;
address_country?: string;
brand?: StripeCardDataBrand;
createToken(data: StripeTokenData, responseHandler: (status: number, response: StripeTokenResponse) => void): void;
}
interface StripeBankAccount
{
createToken(params: StripeBankTokenParams, stripeResponseHandler: (status:number, response: StripeBankTokenResponse) => void): void;
interface StripeBankAccount {
createToken(params: StripeBankTokenParams, stripeResponseHandler: (status: number, response: StripeBankTokenResponse) => void): void;
validateRoutingNumber(routingNumber: number | string, countryCode: string): boolean;
validateAccountNumber(accountNumber: number | string, countryCode: string): boolean;
}
interface StripeBankTokenParams
{
interface StripeBankTokenParams {
country: string;
currency: string;
account_number: number | string;
@ -82,8 +85,7 @@ interface StripeBankTokenParams
account_holder_type: string;
}
interface StripeBankTokenResponse
{
interface StripeBankTokenResponse {
id: string;
bank_account: {
country: string;
@ -100,13 +102,7 @@ interface StripeBankTokenResponse
error?: StripeError;
}
declare var Stripe: StripeStatic;
declare module "Stripe" {
export = StripeStatic;
}
interface StripeApplePay
{
interface StripeApplePay {
checkAvailability(resopnseHandler: (result: boolean) => void): void;
buildSession(data: StripeApplePayPaymentRequest,
onSuccessHandler: (result: StripeApplePaySessionResult, completion: ((value: any) => void)) => void,
@ -117,8 +113,7 @@ type StripeApplePayBillingContactField = 'postalAddress' | 'name';
type StripeApplePayShippingContactField = StripeApplePayBillingContactField | 'phone' | 'email';
type StripeApplePayShipping = 'shipping' | 'delivery' | 'storePickup' | 'servicePickup';
interface StripeApplePayPaymentRequest
{
interface StripeApplePayPaymentRequest {
billingContact: StripeApplePayPaymentContact;
countryCode: string;
currencyCode: string;
@ -132,30 +127,26 @@ interface StripeApplePayPaymentRequest
}
// https://developer.apple.com/reference/applepayjs/1916082-applepay_js_data_types
interface StripeApplePayLineItem
{
interface StripeApplePayLineItem {
type: 'pending' | 'final';
label: string;
amount: number;
}
interface StripeApplePaySessionResult
{
interface StripeApplePaySessionResult {
token: StripeTokenResponse;
shippingContact?: StripeApplePayPaymentContact;
shippingMethod?: StripeApplePayShippingMethod;
}
interface StripeApplePayShippingMethod
{
interface StripeApplePayShippingMethod {
label: string;
detail: string;
amount: number;
identifier: string;
}
interface StripeApplePayPaymentContact
{
interface StripeApplePayPaymentContact {
emailAddress: string;
phoneNumber: string;
givenName: string;
@ -166,3 +157,7 @@ interface StripeApplePayPaymentContact
postalCode: string;
countryCode: string;
}
// The Stripe client side APIs are not made available to package managers for direct installation.
// As explained compliance reasons. Source: https://github.com/stripe/stripe-node/blob/master/README.md#these-are-serverside-bindings-only
// A release date versioning schema is used to version these APIs.

25
stripe/stripe-tests.ts Normal file
View File

@ -0,0 +1,25 @@
function success(card: StripeCardData) {
console.log(card.brand && card.brand.toString());
}
const cardNumber = '4242424242424242';
const isValid = Stripe.validateCardNumber(cardNumber);
if (isValid) {
const tokenData: StripeTokenData = {
number: cardNumber,
exp_month: 1,
exp_year: 2100,
cvc: '111'
};
Stripe.card.createToken(tokenData, (status, response) => {
if (response.error) {
console.error(response.error.message);
if (response.error.param) {
console.error(response.error.param);
}
} else {
success(response.card);
}
});
}

View File

@ -3,7 +3,7 @@
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": false,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
@ -13,6 +13,7 @@
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
"index.d.ts",
"stripe-tests.ts"
]
}
}

3
stripe/tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "../tslint.json"
}