-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1423 from braintree/rba-metadata-feature
[DO NOT REVIEW] Merge `RBA Metadata` feature branch
- Loading branch information
Showing
10 changed files
with
424 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Sources/BraintreePayPal/RecurringBillingMetadata/BTPayPalBillingCycle.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import Foundation | ||
|
||
/// PayPal recurring billing cycle details. | ||
public struct BTPayPalBillingCycle { | ||
|
||
// MARK: - Public Types | ||
|
||
/// The interval at which the payment is charged or billed. | ||
public enum BillingInterval: String { | ||
case day = "DAY" | ||
case week = "WEEK" | ||
case month = "MONTH" | ||
case year = "YEAR" | ||
} | ||
|
||
// MARK: - Private Properties | ||
|
||
private let isTrial: Bool | ||
private let numberOfExecutions: Int | ||
private let interval: BillingInterval? | ||
private let intervalCount: Int? | ||
private let sequence: Int? | ||
private let startDate: String? | ||
private let pricing: BTPayPalBillingPricing? | ||
|
||
// MARK: - Initializer | ||
|
||
/// Initialize a `BTPayPalBillingCycle` object. | ||
/// - Parameters: | ||
/// - isTrial: Required: The tenure type of the billing cycle. In case of a plan having trial cycle, only 2 trial cycles are allowed per plan. | ||
/// - numberOfExecutions: Required: The number of times this billing cycle gets executed. Trial billing cycles can only be executed a finite number of times (value between 1 and 999). Regular billing cycles can be executed infinite times (value of 0) or a finite number of times (value between 1 and 999). | ||
/// - interval: Optional: The number of intervals after which a subscriber is charged or billed. | ||
/// - intervalCount: Optional: The number of times this billing cycle gets executed. For example, if the `intervalCount` is DAY with an `intervalCount` of 2, the subscription is billed once every two days. Maximum values {DAY -> 365}, {WEEK, 52}, {MONTH, 12}, {YEAR, 1}. | ||
/// - sequence: Optional: The sequence of the billing cycle. Used to identify unique billing cycles. For example, sequence 1 could be a 3 month trial period, and sequence 2 could be a longer term full rater cycle. Max value 100. All billing cycles should have unique sequence values. | ||
/// - startDate: Optional: The date and time when the billing cycle starts, in Internet date and time format `YYYY-MM-DD`. If not provided the billing cycle starts at the time of checkout. If provided and the merchant wants the billing cycle to start at the time of checkout, provide the current time. Otherwise the `startDate` can be in future. | ||
/// - pricing: Optional: The active pricing scheme for this billing cycle. Required if `trial` is false. Optional if `trial` is true. | ||
public init( | ||
isTrial: Bool, | ||
numberOfExecutions: Int, | ||
interval: BillingInterval? = nil, | ||
intervalCount: Int? = nil, | ||
sequence: Int? = nil, | ||
startDate: String? = nil, | ||
pricing: BTPayPalBillingPricing? = nil | ||
) { | ||
self.isTrial = isTrial | ||
self.numberOfExecutions = numberOfExecutions | ||
self.interval = interval | ||
self.intervalCount = intervalCount | ||
self.sequence = sequence | ||
self.startDate = startDate | ||
self.pricing = pricing | ||
} | ||
|
||
// MARK: - Internal Methods | ||
|
||
func parameters() -> [String: Any] { | ||
var parameters: [String: Any] = [ | ||
"number_of_executions": numberOfExecutions, | ||
"trial": isTrial | ||
] | ||
|
||
if let interval { | ||
parameters["billing_frequency_unit"] = interval.rawValue | ||
} | ||
|
||
if let intervalCount { | ||
parameters["billing_frequency"] = intervalCount | ||
} | ||
|
||
if let sequence { | ||
parameters["sequence"] = sequence | ||
} | ||
|
||
if let startDate { | ||
parameters["start_date"] = startDate | ||
} | ||
|
||
if let pricing { | ||
parameters["pricing_scheme"] = pricing.parameters() | ||
} | ||
|
||
return parameters | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Sources/BraintreePayPal/RecurringBillingMetadata/BTPayPalBillingPricing.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Foundation | ||
|
||
/// PayPal Recurring Billing Agreement pricing details. | ||
public struct BTPayPalBillingPricing { | ||
|
||
// MARK: - Public Types | ||
|
||
/// Recurring Billing Agreement pricing model types. | ||
public enum PricingModel: String { | ||
case fixed = "FIXED" | ||
case variable = "VARIABLE" | ||
case autoReload = "AUTO_RELOAD" | ||
} | ||
|
||
// MARK: - Private Properties | ||
|
||
private let pricingModel: PricingModel | ||
private let amount: String? | ||
private let reloadThresholdAmount: String? | ||
|
||
// MARK: - Initializer | ||
|
||
/// Initialize a `BTPayPalBillingPricing` object. | ||
/// - Parameters: | ||
/// - pricingModel: Required: The pricing model associated with the billing agreement. | ||
/// - amount: Optional: Price. The amount to charge for the subscription, recurring, UCOF or installments. | ||
/// - reloadThresholdAmount: Optional: The reload trigger threshold condition amount when the customer is charged. | ||
public init(pricingModel: PricingModel, amount: String? = nil, reloadThresholdAmount: String? = nil) { | ||
self.pricingModel = pricingModel | ||
self.amount = amount | ||
self.reloadThresholdAmount = reloadThresholdAmount | ||
} | ||
|
||
// MARK: - Internal Methods | ||
|
||
func parameters() -> [String: Any] { | ||
var parameters: [String: Any] = [ | ||
"pricing_model": pricingModel.rawValue | ||
] | ||
|
||
if let amount { | ||
parameters["price"] = amount | ||
} | ||
|
||
if let reloadThresholdAmount { | ||
parameters["reload_threshold_amount"] = reloadThresholdAmount | ||
} | ||
|
||
return parameters | ||
} | ||
} |
Oops, something went wrong.