Skip to content

Commit

Permalink
Merge pull request #134 from vapor-community/clone-payment-method
Browse files Browse the repository at this point in the history
Support for cloning a payment method.
  • Loading branch information
Andrewangeta authored Aug 17, 2021
2 parents edd0580 + abbfdfa commit 52af608
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 13.1.0 - 2021-08-17
* [#134](https://github.com/vapor-community/stripe-kit/pull/134)
* Added support for cloning a payment method.

## 13.0.0 - 2021-08-01
* [#133](https://github.com/vapor-community/stripe-kit/pull/133)
* ⚠️ Breaking changes ⚠️ Multiple API updates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public protocol PaymentMethodRoutes {
wechatPay: [String: Any]?,
expand: [String]?) -> EventLoopFuture<StripePaymentMethod>

/// Clones a payment method to a connect account from the platform account.
///
/// It is possible to clone PaymentMethods to connected accounts without previously attaching them to Customers. However, note that the original PaymentMethod will be consumed, since PaymentMethods that aren’t attached to Customers can only be used once.
/// - Parameters:
/// - paymentMethod: The id of the payment method to clone.
/// - customer: The id of trhe customer this payment method beelongs to. You must provide the Customer ID in the request when cloning PaymentMethods that are attached to Customers for security purposes
/// - Returns: A `StripePaymentMethod`.
func clone(paymentMethod: String, customer: String?) -> EventLoopFuture<StripePaymentMethod>

/// Retrieves a PaymentMethod object.
///
/// - Parameters:
Expand Down Expand Up @@ -160,6 +169,10 @@ extension PaymentMethodRoutes {
expand: expand)
}

public func clone(paymentMethod: String, customer: String? = nil) -> EventLoopFuture<StripePaymentMethod> {
clone(paymentMethod: paymentMethod, customer: customer)
}

public func retrieve(paymentMethod: String, expand: [String]? = nil) -> EventLoopFuture<StripePaymentMethod> {
return retrieve(paymentMethod: paymentMethod, expand: expand)
}
Expand Down Expand Up @@ -312,6 +325,15 @@ public struct StripePaymentMethodRoutes: PaymentMethodRoutes {
return apiHandler.send(method: .POST, path: paymentmethods, body: .string(body.queryParameters), headers: headers)
}

public func clone(paymentMethod: String, customer: String?) -> EventLoopFuture<StripePaymentMethod> {
var body: [String: Any] = ["payment_method": paymentMethod]
if let customer = customer {
body["customer"] = customer
}

return apiHandler.send(method: .POST, path: paymentmethods, body: .string(body.queryParameters), headers: headers)
}

public func retrieve(paymentMethod: String, expand: [String]?) -> EventLoopFuture<StripePaymentMethod> {
var queryParams = ""
if let expand = expand {
Expand Down

0 comments on commit 52af608

Please sign in to comment.