From abbfdfafc5c1ae1ae0686a24e8bdc720e58b15b5 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Tue, 17 Aug 2021 15:40:33 -0400 Subject: [PATCH] Support for cloning a payment method. --- CHANGELOG.md | 4 ++++ .../PaymentMethods/PaymentMethodRoutes.swift | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de61f5b3..b4acd2b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Sources/StripeKit/Payment Methods/PaymentMethods/PaymentMethodRoutes.swift b/Sources/StripeKit/Payment Methods/PaymentMethods/PaymentMethodRoutes.swift index 7511e610..9f485be1 100644 --- a/Sources/StripeKit/Payment Methods/PaymentMethods/PaymentMethodRoutes.swift +++ b/Sources/StripeKit/Payment Methods/PaymentMethods/PaymentMethodRoutes.swift @@ -58,6 +58,15 @@ public protocol PaymentMethodRoutes { wechatPay: [String: Any]?, expand: [String]?) -> EventLoopFuture + /// 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 + /// Retrieves a PaymentMethod object. /// /// - Parameters: @@ -160,6 +169,10 @@ extension PaymentMethodRoutes { expand: expand) } + public func clone(paymentMethod: String, customer: String? = nil) -> EventLoopFuture { + clone(paymentMethod: paymentMethod, customer: customer) + } + public func retrieve(paymentMethod: String, expand: [String]? = nil) -> EventLoopFuture { return retrieve(paymentMethod: paymentMethod, expand: expand) } @@ -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 { + 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 { var queryParams = "" if let expand = expand {