Merge pull request #14243 from jleider/stripe

Package: STRIPE -- Update card and bank account interfaces, rename for consistency.
This commit is contained in:
Bowden Kelly
2017-02-03 18:40:47 -08:00
committed by GitHub
2 changed files with 19 additions and 20 deletions
+17 -18
View File
@@ -1,6 +1,6 @@
// Type definitions for stripe 0.0
// Type definitions for stripe 2.x
// 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 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>, Justin Leider <https://github.com/jleider>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare const Stripe: StripeStatic;
@@ -12,13 +12,13 @@ interface StripeStatic {
validateExpiry(month: string, year: string): boolean;
validateCVC(cardCVC: string): boolean;
cardType(cardNumber: string): StripeCardDataBrand;
getToken(token: string, responseHandler: (status: number, response: StripeTokenResponse) => void): void;
card: StripeCardData;
createToken(data: StripeTokenData, responseHandler: (status: number, response: StripeTokenResponse) => void): void;
getToken(token: string, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void;
card: StripeCard;
createToken(data: StripeCardTokenData, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void;
bankAccount: StripeBankAccount;
}
interface StripeTokenData {
interface StripeCardTokenData {
number: string;
exp_month?: number;
exp_year?: number;
@@ -35,7 +35,6 @@ interface StripeTokenData {
interface StripeTokenResponse {
id: string;
card: StripeCardData;
created: number;
livemode: boolean;
object: string;
@@ -44,6 +43,10 @@ interface StripeTokenResponse {
error?: StripeError;
}
interface StripeCardTokenResponse extends StripeTokenResponse {
card: StripeCard;
}
interface StripeError {
type: string;
code: string;
@@ -53,7 +56,7 @@ interface StripeError {
type StripeCardDataBrand = 'Visa' | 'American Express' | 'MasterCard' | 'Discover' | 'JCB' | 'Diners Club' | 'Unknown';
interface StripeCardData {
interface StripeCard {
object: string;
last4: string;
exp_month: number;
@@ -67,7 +70,10 @@ interface StripeCardData {
address_zip?: string;
address_country?: string;
brand?: StripeCardDataBrand;
createToken(data: StripeTokenData, responseHandler: (status: number, response: StripeTokenResponse) => void): void;
createToken(data: StripeCardTokenData, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void;
validateCardNumber(cardNumber: string): boolean;
validateExpiry(month: string, year: string): boolean;
validateCVC(cardCVC: string): boolean;
}
interface StripeBankAccount {
@@ -85,8 +91,7 @@ interface StripeBankTokenParams {
account_holder_type: string;
}
interface StripeBankTokenResponse {
id: string;
interface StripeBankTokenResponse extends StripeTokenResponse {
bank_account: {
country: string;
bank_name: string;
@@ -94,12 +99,6 @@ interface StripeBankTokenResponse {
validated: boolean;
object: string;
};
created: number;
livemode: boolean;
type: string;
object: string;
used: boolean;
error?: StripeError;
}
interface StripeApplePay {
@@ -134,7 +133,7 @@ interface StripeApplePayLineItem {
}
interface StripeApplePaySessionResult {
token: StripeTokenResponse;
token: StripeCardTokenResponse;
shippingContact?: StripeApplePayPaymentContact;
shippingMethod?: StripeApplePayShippingMethod;
}
+2 -2
View File
@@ -1,4 +1,4 @@
function success(card: StripeCardData) {
function success(card: StripeCard) {
console.log(card.brand && card.brand.toString());
}
@@ -6,7 +6,7 @@ const cardNumber = '4242424242424242';
const isValid = Stripe.validateCardNumber(cardNumber);
if (isValid) {
const tokenData: StripeTokenData = {
const tokenData: StripeCardTokenData = {
number: cardNumber,
exp_month: 1,
exp_year: 2100,