當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript stripejs.StripeJS類代碼示例

本文整理匯總了TypeScript中stripejs.StripeJS的典型用法代碼示例。如果您正苦於以下問題:TypeScript StripeJS類的具體用法?TypeScript StripeJS怎麽用?TypeScript StripeJS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了StripeJS類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('StripeJS', () => {
    const stripe: StripeJS = {} as any;

    it('Should be able to initialize', () => {
        stripe('test');
        stripe('test', {stripeAccount: 'test123'});
    });

    it('Should be possible to get information from stripe', () => {
        stripe._apiKey;
        stripe._keyMode;
    });

    it('Should be possible to create and modify elements', () => {
        const creator = stripe.elements();
        stripe.elements({fonts: [], locale: 'nl'});
        stripe.elements({fonts: [], locale: 'nl', isIETFLocaleTag: true});

        const element = creator.create("cardCvc", {value: {postalCode: '94110'}});
        element.blur();
        element.focus();
        element.clear();
        element.on('focus', () => null);
        element.on('click', (event: { preventDefault: () => void }) => event.preventDefault());
        element.mount('#card-element');
        element.mount(new HTMLElement());
        element.unmount();
        element.update({value: {postalCode: '123'}});
        element.destroy();
    });

    it('Should be possible to create a payment request', () => {
        const data = {country: 'NL', currency: 'eur', total: {amount: 100, label: 'hello world'}};
        const request = stripe.paymentRequest(data);
        request.canMakePayment().then((result: CanMakePaymentResult | null) => null);
        request.on('token', ((event: StripePaymentResponse) => {
            const token: any = event.token ? event.token : null;
            event.complete("fail");
            const name: string = event.payerName ? event.payerName : '';
        }));
        request.show();
        request.update(data);
    });

    it('Should be possible to create a token', () => {
        const element: StripeElement = {} as any;
        const data: TokenData = {
            name: '',
            currency: 'eur',
            address_city: '',
            address_country: 'NL',
            address_line1: '',
            address_line2: '',
            address_state: '',
            address_zip: '',
        };
        stripe.createToken(element, data).then((result: TokenResult) => result.token);

        const iban: IBANTokenData = {
            currency: 'eur',
            account_holder_name: '',
            account_holder_type: 'company',
        };
        stripe.createToken(element, iban).then((result: TokenResult) => result.token);

        const bankData = {
            country: 'NL',
            account_number: '12345'
        };
        const bank: BankTokenData = {...iban, ...bankData};
        stripe.createToken('bank_account', bank).then((result: TokenResult) => result.token);

        stripe.createToken('pii', {personal_id_number: ''}).then((result: TokenResult) => result.error);
    });

    it('Should be possible to create a source object', () => {
        const element: StripeElement = {} as any;
        const data: SourceData = {
            type: 'alipay',
            flow: 'none',
            amount: 1000,
            currency: 'eur',
            usage: 'single_use'
        };
        stripe.createSource(element, data).then((result: SourceResult) => result.source);
        stripe.createSource(data).then((result: SourceResult) => result.error);
    });

    it('Should be possible to fetch a source object', () => {
        stripe.retrieveSource({id: '', client_secret: ''}).then((result: SourceResult) => result.source);
    });
});
開發者ID:itslenny,項目名稱:DefinitelyTyped,代碼行數:92,代碼來源:stripejs-tests.ts

示例2: it

    it('Should be possible to create a token', () => {
        const element: StripeElement = {} as any;
        const data: TokenData = {
            name: '',
            currency: 'eur',
            address_city: '',
            address_country: 'NL',
            address_line1: '',
            address_line2: '',
            address_state: '',
            address_zip: '',
        };
        stripe.createToken(element, data).then((result: TokenResult) => result.token);

        const iban: IBANTokenData = {
            currency: 'eur',
            account_holder_name: '',
            account_holder_type: 'company',
        };
        stripe.createToken(element, iban).then((result: TokenResult) => result.token);

        const bankData = {
            country: 'NL',
            account_number: '12345'
        };
        const bank: BankTokenData = {...iban, ...bankData};
        stripe.createToken('bank_account', bank).then((result: TokenResult) => result.token);

        stripe.createToken('pii', {personal_id_number: ''}).then((result: TokenResult) => result.error);
    });
開發者ID:itslenny,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:stripejs-tests.ts


注:本文中的stripejs.StripeJS類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。