Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/expandable objects #72

Merged
merged 25 commits into from
Apr 20, 2020
Merged

Feature/expandable objects #72

merged 25 commits into from
Apr 20, 2020

Conversation

Andrewangeta
Copy link
Member

This PR adds support for expandable objects.

Properties on Stripe objects/entities that can be expanded have been annotated with a new @Expandable property wrapper.

All API routes that can return expanded objects have an extra parameter expand: [String] that allows specifying which objects to expand.
For existing listAll(filter: [String: Any]?) routes on a given resource, you'd just specify the expand key and the array as a value.

Usage:

  1. Expanding a single field.
// Expanding a customer from creating a `PaymentIntent`.
stripeclient.paymentIntents.create(amount: 2500, currency: .usd, expand: ["customer"])
.flatMap { paymentIntent in
// Accessing the expanded `StripeCustomer` object   
 paymentIntent.$customer.email
...
}
  1. Expanding multiple fields.
// Expanding a customer and payment method from creating a `PaymentIntent`.
stripeclient.paymentIntents.create(amount: 2500, currency: .usd, expand: ["customer", "paymentMethod"])
.flatMap { paymentIntent in
// Accessing the expanded `StripeCustomer` object   
 paymentIntent.$customer?.email // "[email protected]"
// Accessing the expanded `StripePaymentMethod` object
 paymentIntent.$paymentMethod?.card?.last4 // "1234"
 ...
}
  1. Expanding nested fields.
// Expanding a payment method and its nested customer from creating a `PaymentIntent`.
stripeclient.paymentIntents.create(amount: 2500, currency: .usd, expand: ["paymentMethod.customer"])
.flatMap { paymentIntent in
// Accessing the expanded `StripePaymentMethod` object
 paymentIntent.$paymentMethod?.card?.last4 // "1234"
// Accessing the nested expanded `StripeCustomer` object   
 paymentIntent.$paymentMethod?.$customer?.email // "[email protected]"
 ...
}
  1. Usage with list all.

Note: For list operations expanded fields must start with data

// Expanding a customer from listing all `PaymentIntent`s.
stripeclient.paymentIntents.listAll(filter: ["expand": ["data.customer"...]])
.flatMap { list in
 // Accessing the first `StripePaymentIntent`'s expanded `StripeCustomer` property
  list.data?.first?.$customer?.email // "[email protected]"
}

@Andrewangeta Andrewangeta merged commit b8d025d into master Apr 20, 2020
@Andrewangeta Andrewangeta mentioned this pull request Apr 20, 2020
@Andrewangeta Andrewangeta deleted the feature/expandable-objects branch July 16, 2020 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant