-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[NT-438] Create backing with free shipping #901
Changes from 6 commits
7844cb7
c05c7b8
8130c90
b7bddaf
b890141
45a4e1c
3aa9733
eff58e5
b2a9efa
0935229
6e34706
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,3 +216,27 @@ internal func classNameWithoutModule(_ class: AnyClass) -> String { | |
.dropFirst() | ||
.joined(separator: ".") | ||
} | ||
|
||
typealias FormattedPledgeParameters = (pledgeTotal: String, rewardId: String?, locationId: String?) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I read |
||
|
||
internal func formattedPledgeParameters( | ||
from reward: Reward, | ||
pledgeAmount: Double, | ||
selectedShippingRule: ShippingRule? | ||
) -> FormattedPledgeParameters { | ||
let pledgeAmountDecimal = Decimal(pledgeAmount) | ||
var shippingAmountDecimal: Decimal = Decimal() | ||
var shippingLocationId: String? | ||
|
||
if let shippingRule = selectedShippingRule { | ||
shippingAmountDecimal = Decimal(shippingRule.cost) | ||
shippingLocationId = String(shippingRule.location.id) | ||
} | ||
|
||
let pledgeTotal = NSDecimalNumber(decimal: pledgeAmountDecimal + shippingAmountDecimal) | ||
let formattedPledgeTotal = Format.decimalCurrency(for: pledgeTotal.doubleValue) | ||
|
||
let rewardId = reward == Reward.noReward ? nil : reward.graphID | ||
|
||
return (formattedPledgeTotal, rewardId, shippingLocationId) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,16 @@ extension UpdateBackingInput { | |
from updateBackingData: UpdateBackingData, | ||
isApplePay: Bool | ||
) -> UpdateBackingInput { | ||
let pledgeAmount: String? = updateBackingData.pledgeAmount.flatMap { pledgeAmount in | ||
pledgeAmountString(withAmount: pledgeAmount, shippingRule: updateBackingData.shippingRule) | ||
} | ||
let backingId: String = updateBackingData.backing.graphID | ||
let locationId: String? = updateBackingData.shippingRule.flatMap { "\($0.location.id)" } | ||
let rewardId: String? = updateBackingData.reward.graphID | ||
let backingId = updateBackingData.backing.graphID | ||
let (pledgeTotal, rewardId, locationId) = | ||
formattedPledgeParameters( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here? |
||
from: updateBackingData.reward, | ||
pledgeAmount: updateBackingData.pledgeAmount, | ||
selectedShippingRule: updateBackingData.shippingRule | ||
) | ||
|
||
return UpdateBackingInput( | ||
amount: pledgeAmount, | ||
amount: pledgeTotal, | ||
applePay: isApplePay ? updateBackingData.applePayParams : nil, | ||
id: backingId, | ||
locationId: locationId, | ||
|
@@ -23,17 +24,3 @@ extension UpdateBackingInput { | |
) | ||
} | ||
} | ||
|
||
private func pledgeAmountString(withAmount amount: Double, shippingRule: ShippingRule?) -> String { | ||
let pledgeAmountDecimal = Decimal(amount) | ||
var shippingAmountDecimal: Decimal = Decimal() | ||
|
||
if let shippingRule = shippingRule, shippingRule.cost > 0 { | ||
shippingAmountDecimal = Decimal(shippingRule.cost) | ||
} | ||
|
||
let pledgeTotal = NSDecimalNumber(decimal: pledgeAmountDecimal + shippingAmountDecimal) | ||
let formattedPledgeTotal = Format.decimalCurrency(for: pledgeTotal.doubleValue) | ||
|
||
return formattedPledgeTotal | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to the same line as
let pledgeParams