Update Stripe package (#23083)

* Update ICard#customer type def

Add `string` to `customer` type.

* Add pay options to Invoices#pay method

* Add tests

* Change IMetadata to a `type` equal to `any`

See tests as to the reasons why I believe it's useful for it to be
changed.

* Add proration creation options to SubscriptionItems

Plus tests.

Documentation:
https://stripe.com/docs/api#create_subscription_item

* Update IMetadata definition with tests

* Add IOptionsMetadata
This commit is contained in:
CodeAnimal
2018-01-23 09:34:26 -08:00
committed by Andy
parent ff671eae53
commit ede9553e0c
2 changed files with 85 additions and 39 deletions
+45 -36
View File
@@ -8,6 +8,7 @@
// Kyle Kamperschroer <https://github.com/kkamperschroer>
// Kensuke Hoshikawa <https://github.com/starhoshi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="node" />
@@ -557,7 +558,7 @@ declare namespace Stripe {
interface IApplicationFeeRefunds extends IList<IApplicationFeeRefund>, resources.ApplicationFeeRefunds { }
interface IApplicationFeeRefundCreationOptions extends IDataOptions {
interface IApplicationFeeRefundCreationOptions extends IDataOptionsWithMetadata {
/**
* A positive integer in pence representing how much of this fee to refund.
* Can only refund up to the unrefunded amount remaining of the fee.
@@ -565,14 +566,6 @@ declare namespace Stripe {
* default is entire application fee
*/
amount?: number;
/**
* A set of key/value pairs that you can attach to a refund object. It can be
* useful for storing additional information about the refund in a structured
* format. You can unset an individual key by setting its value to null and
* then saving. To clear all keys, set metadata to null, then save.
*/
metadata?: IMetadata;
}
}
@@ -878,7 +871,7 @@ declare namespace Stripe {
transfer: string | transfers.ITransfer;
}
interface IChargeCreationOptions extends IDataOptions {
interface IChargeCreationOptions extends IDataOptionsWithMetadata {
/**
* A positive integer in the smallest currency unit (e.g 100 cents to charge
* $1.00, or 1 to charge ¥1, a 0-decimal currency) representing how much to
@@ -947,14 +940,6 @@ declare namespace Stripe {
*/
on_behalf_of?: string;
/**
* A set of key/value pairs that you can attach to a charge object. It can be
* useful for storing additional information about the customer in a
* structured format. It's often a good idea to store an email address in
* metadata for tracking later.
*/
metadata?: IMetadata;
/**
* The email address to send this charge's receipt to. The receipt will not be
* sent until the charge is paid. If this charge is for a customer, the email
@@ -2088,6 +2073,14 @@ declare namespace Stripe {
tax_percent?: number;
}
interface IInvoicePayOptions extends IDataOptionsWithMetadata {
/**
* A payment source to be charged. The source must be the ID of a source
* belonging to the customer associated with the invoice being paid.
*/
source?: sources.ISourceCreationOptions;
}
interface IInvoiceListOptions extends IListOptions {
/**
* The identifier of the customer whose invoices to return. If none is provided, all invoices will be returned.
@@ -4024,7 +4017,7 @@ declare namespace Stripe {
* in the card object if the card belongs to an account or recipient
* instead.
*/
customer?: customers.ICustomer;
customer?: string | customers.ICustomer;
/**
* Only applicable on accounts (not customers or recipients). This
@@ -4157,7 +4150,7 @@ declare namespace Stripe {
interface ISourceCreationOptions {
/**
* he type of payment source. Should be "card".
* The type of payment source. Should be "card".
*/
object: "card";
@@ -4195,7 +4188,7 @@ declare namespace Stripe {
address_state?: string;
address_zip?: string;
metadata?: IMetadata;
metadata?: IOptionsMetadata;
}
interface ISourceCreationOptionsExtended extends ISourceCreationOptions {
@@ -4550,6 +4543,17 @@ declare namespace Stripe {
* The quantity you’d like to apply to the subscription item you’re creating.
*/
quantity?: number;
/**
* Flag indicating whether to prorate switching plans during a billing cycle.
*/
prorate?: boolean;
/**
* If set, the proration will be calculated as though the subscription was updated at the given time. This can be used to apply the same
* proration that was previewed with the upcoming invoice endpoint.
*/
proration_date?: number;
}
interface ISubscriptionItemUpdateOptions extends IDataOptionsWithMetadata {
@@ -4646,7 +4650,7 @@ declare namespace Stripe {
receipt_number: string;
}
interface IRefundCreationOptions extends IDataOptions {
interface IRefundCreationOptions extends IDataOptionsWithMetadata {
/**
* A positive integer in cents/pence representing how much of this charge to
* refund. Can only refund up to the unrefunded amount remaining of the
@@ -4656,14 +4660,6 @@ declare namespace Stripe {
*/
amount?: number;
/**
* A set of key/value pairs that you can attach to a refund object. It can be
* useful for storing additional information about the refund in a structured
* format. You can unset an individual key by setting its value to null and
* then saving. To clear all keys, set metadata to null, then save.
*/
metadata?: IMetadata;
/**
* String indicating the reason for the refund. If set, possible values are
* "duplicate", "fraudulent", and "requested_by_customer". Specifying
@@ -4980,8 +4976,8 @@ declare namespace Stripe {
*
* This request only accepts metadata as an argument.
*/
updateRefund(feeId: string, refundId: string, data: { metadata?: IMetadata }, options: HeaderOptions, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
updateRefund(feeId: string, refundId: string, data: { metadata?: IMetadata }, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
updateRefund(feeId: string, refundId: string, data: { metadata?: IOptionsMetadata }, options: HeaderOptions, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
updateRefund(feeId: string, refundId: string, data: { metadata?: IOptionsMetadata }, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
/**
* You can see a list of the refunds belonging to a specific application fee. Note that the 10 most recent refunds are always available
@@ -5025,8 +5021,8 @@ declare namespace Stripe {
*
* This request only accepts metadata as an argument.
*/
update(refundId: string, data: { metadata?: IMetadata }, options: HeaderOptions, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
update(refundId: string, data: { metadata?: IMetadata }, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
update(refundId: string, data: { metadata?: IOptionsMetadata }, options: HeaderOptions, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
update(refundId: string, data: { metadata?: IOptionsMetadata }, response?: IResponseFn<applicationFees.IApplicationFeeRefund>): Promise<applicationFees.IApplicationFeeRefund>;
/**
* You can see a list of the refunds belonging to a specific application fee. Note that the 10 most recent refunds are always available
@@ -6155,6 +6151,9 @@ declare namespace Stripe {
*
* @param id The ID of the invoice to pay.
*/
pay(id: string, data: invoices.IInvoicePayOptions, options: HeaderOptions, response?: IResponseFn<invoices.IInvoice>): Promise<invoices.IInvoice>;
pay(id: string, data: invoices.IInvoicePayOptions, response: IResponseFn<invoices.IInvoice>): Promise<invoices.IInvoice>;
pay(id: string, data: invoices.IInvoicePayOptions): Promise<invoices.IInvoice>;
pay(id: string, options: HeaderOptions, response?: IResponseFn<invoices.IInvoice>): Promise<invoices.IInvoice>;
pay(id: string, response?: IResponseFn<invoices.IInvoice>): Promise<invoices.IInvoice>;
@@ -6790,7 +6789,17 @@ declare namespace Stripe {
* A set of key/value pairs that you can attach to an object. It can be useful for storing
* additional information about the object in a structured format.
*/
interface IMetadata { }
interface IOptionsMetadata {
[x: string]: string | number;
}
/**
* A set of key/value pairs that you can attach to an object. It can be useful for storing
* additional information about the object in a structured format.
*/
interface IMetadata {
[x: string]: string;
}
interface IShippingInformation {
/**
@@ -6919,7 +6928,7 @@ declare namespace Stripe {
* format. You can unset an individual key by setting its value to null and
* then saving. To clear all keys, set metadata to null, then save.
*/
metadata?: IMetadata;
metadata?: IOptionsMetadata;
}
interface IHeaderOptions {
+40 -3
View File
@@ -1,4 +1,5 @@
import Stripe = require('stripe');
import { customers } from 'stripe';
var stripe = new Stripe("sk_test_BF573NobVn98OiIsPAv7A04K")
@@ -230,17 +231,22 @@ stripe.charges.markAsFraudulent('ch_15fvyXEe31JkLCeQOo0SwFk9').then(function (re
stripe.customers.create({
description: 'Customer for test@example.com',
source: "tok_15V2YhEe31JkLCeQy9iUgsJX" // obtained with Stripe.js
source: "tok_15V2YhEe31JkLCeQy9iUgsJX", // obtained with Stripe.js
metadata: { test: "123", test2: 123 } // IOptionsMetadata test
}, function (err, customer) {
// asynchronously called
});
stripe.customers.create({
description: 'Customer for test@example.com',
source: "tok_15V2YhEe31JkLCeQy9iUgsJX" // obtained with Stripe.js
source: "tok_15V2YhEe31JkLCeQy9iUgsJX", // obtained with Stripe.js
metadata: null // IOptionsMetadata test
}).then( function (customer) {
// asynchronously called
customer.cards.create({ card: "tok_17wV94BoqMA9o2xkhlAd3ALf"}).then(function (customer) {});
customer.cards.retrieve("card_17xMvXBoqMA9o2xkq6W5gamx").then(function (card) {});
customer.cards.retrieve("card_17xMvXBoqMA9o2xkq6W5gamx").then(function (card) {
let strCustomer: string = <string>card.customer;
let objCustomer: customers.ICustomer = <customers.ICustomer>card.customer;
});
customer.cards.update("card_17xMvXBoqMA9o2xkq6W5gamx", { name: "Test" }).then(function (card) {});
customer.cards.list().then(function (cards) {});
customer.cards.del("card_17xMvXBoqMA9o2xkq6W5gamx").then(function (confirmation) {});
@@ -251,6 +257,29 @@ stripe.customers.create({
customer.subscriptions.list().then(function (subscriptions) { });
customer.subscriptions.del("sub_8Eluur5KoIKxuy").then(function (subscription) { });
customer.subscriptions.deleteDiscount("sub_8Eluur5KoIKxuy").then(function (confirmation) { });
// IMetadata tests:
let str: string;
customer.metadata["test"] == str;
customer.metadata.test1 == str;
//IOptionsMetadata tests:
let metadata: Stripe.IOptionsMetadata;
let num: number;
metadata["test"] = str;
metadata["test"] = num;
metadata["test"] == str;
metadata["test"] == num;
metadata.testStr = str;
metadata.testNum = num;
metadata.test1 == str;
metadata.test2 == num;
metadata = {
test1: str,
test2: num
}
metadata = {};
metadata = null;
});
@@ -880,6 +909,10 @@ stripe.invoices.pay("in_15fvyXEe31JkLCeQH7QbgZZb").then(function (invoice) {
// asynchronously called
});
stripe.invoices.pay("in_15fvyXEe31JkLCeQH7QbgZZb", { source: "source_id" }).then(function (invoice) {
// asynchronously called
});
stripe.invoices.list(
{ customer: "cus_5rfJKDJkuxzh5Q", limit: 3 },
function (err, invoices) {
@@ -1134,6 +1167,10 @@ stripe.subscriptionItems.create({ subscription: "sub_C9giwDfCeN8fwt", plan: "pla
// asynchronously called
});
stripe.subscriptionItems.create({ subscription: "sub_C9giwDfCeN8fwt", plan: "platypi-dev", prorate: true, proration_date: Math.round(new Date().valueOf() / 1000) }).then(function(subscriptionItem) {
// asynchronously called
});
stripe.subscriptionItems.retrieve("si_C9gimdd2l9qvCU", function(err, subscriptionItem) {
// asynchronously called
});