-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBL-1920: API | Add Support For New BuildPaymentPlan Query (#2187)
* add build payment plan query and models * linter * fix tests * remove test network call * remove unused imports * remove test compose view * formatting * remove unnecessary fields from query and transformer --------- Co-authored-by: Leigh Douglas <[email protected]>
- Loading branch information
1 parent
72537c3
commit 355ecb3
Showing
10 changed files
with
316 additions
and
78 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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/kickstarter/models/BuildPaymentPlanData.kt
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,6 @@ | ||
package com.kickstarter.models | ||
|
||
data class BuildPaymentPlanData( | ||
val slug: String, | ||
val amount: String, | ||
) |
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,54 @@ | ||
package com.kickstarter.models | ||
|
||
import android.os.Parcelable | ||
import com.kickstarter.type.CurrencyCode | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class Money( | ||
val amount: String?, | ||
val currencyCode: CurrencyCode?, | ||
val currencySymbol: String?, | ||
) : Parcelable { | ||
fun amount() = this.amount | ||
fun currencyCode() = this.currencyCode | ||
fun currencySymbol() = this.currencySymbol | ||
|
||
@Parcelize | ||
data class Builder( | ||
var amount: String? = null, | ||
var currencyCode: CurrencyCode? = null, | ||
var currencySymbol: String? = null, | ||
|
||
) : Parcelable { | ||
fun amount(amount: String?) = apply { this.amount = amount } | ||
fun currencyCode(currencyCode: CurrencyCode?) = apply { this.currencyCode = currencyCode } | ||
fun currencySymbol(currencySymbol: String?) = apply { this.currencySymbol = currencySymbol } | ||
fun build() = Money( | ||
amount = amount, | ||
currencyCode = currencyCode, | ||
currencySymbol = currencySymbol | ||
) | ||
} | ||
|
||
override fun equals(obj: Any?): Boolean { | ||
var equals = super.equals(obj) | ||
if (obj is Money) { | ||
equals = amount() == obj.amount() && | ||
currencyCode() == obj.currencyCode() && | ||
currencySymbol() == obj.currencySymbol() | ||
} | ||
return equals | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
amount = amount, | ||
currencyCode = currencyCode, | ||
currencySymbol = currencySymbol, | ||
) | ||
|
||
companion object { | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
} |
101 changes: 68 additions & 33 deletions
101
app/src/main/java/com/kickstarter/models/PaymentIncrement.kt
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 |
---|---|---|
@@ -1,45 +1,80 @@ | ||
package com.kickstarter.models | ||
|
||
import java.time.Instant | ||
import java.time.ZoneOffset | ||
import java.time.ZonedDateTime | ||
import java.time.format.DateTimeFormatter | ||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import org.joda.time.DateTime | ||
|
||
@Parcelize | ||
data class PaymentIncrement( | ||
val id: Long, | ||
val amount: Int, | ||
val amount: Money, | ||
val paymentIncrementableId: String, | ||
val paymentIncrementableType: String, | ||
val scheduledCollection: DateTime, | ||
val state: State, | ||
val paymentIncrementalType: String, | ||
val paymentIncrementalId: Long, | ||
val date: Instant | ||
) { | ||
val formattedDate: String | ||
get() { | ||
val zonedDateTime = ZonedDateTime.ofInstant(date, ZoneOffset.UTC) | ||
val formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy") | ||
return zonedDateTime.format(formatter) | ||
} | ||
enum class State { | ||
UNATTEMPTED, | ||
COLLECTED | ||
val stateReason: String? | ||
) : Parcelable { | ||
fun amount() = this.amount | ||
fun paymentIncrementableId() = this.paymentIncrementableId | ||
fun paymentIncrementableType() = this.paymentIncrementableType | ||
fun scheduledCollection() = this.scheduledCollection | ||
fun state() = this.state | ||
fun stateReason() = this.stateReason | ||
|
||
@Parcelize | ||
data class Builder( | ||
private var amount: Money = Money.builder().build(), | ||
private var paymentIncrementableId: String = "", | ||
private var paymentIncrementableType: String = "", | ||
private var scheduledCollection: DateTime = DateTime.now(), | ||
private var state: State = State.UNKNOWN, | ||
private var stateReason: String? = null | ||
) : Parcelable { | ||
fun amount(amount: Money) = apply { this.amount = amount } | ||
fun paymentIncrementableId(paymentIncrementableId: String) = apply { this.paymentIncrementableId = paymentIncrementableId } | ||
fun paymentIncrementableType(paymentIncrementableType: String) = apply { this.paymentIncrementableType = paymentIncrementableType } | ||
fun scheduledCollection(scheduledCollection: DateTime) = apply { this.scheduledCollection = scheduledCollection } | ||
fun state(state: State) = apply { this.state = state } | ||
fun stateReason(stateReason: String?) = apply { this.stateReason = stateReason } | ||
fun build() = PaymentIncrement( | ||
amount = amount, | ||
paymentIncrementableId = paymentIncrementableId, | ||
paymentIncrementableType = paymentIncrementableType, | ||
scheduledCollection = scheduledCollection, | ||
state = state, | ||
stateReason = stateReason | ||
) | ||
} | ||
|
||
fun stateAsString(): String { | ||
return state.name.lowercase() | ||
override fun equals(obj: Any?): Boolean { | ||
var equals = super.equals(obj) | ||
if (obj is PaymentIncrement) { | ||
equals = amount() == obj.amount() && | ||
paymentIncrementableId() == obj.paymentIncrementableId() && | ||
paymentIncrementableType() == obj.paymentIncrementableType() && | ||
scheduledCollection() == obj.scheduledCollection() && | ||
state() == obj.state() && | ||
stateReason() == obj.stateReason() | ||
} | ||
return equals | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
amount = amount, | ||
paymentIncrementableId = paymentIncrementableId, | ||
paymentIncrementableType = paymentIncrementableType, | ||
scheduledCollection = scheduledCollection, | ||
state = state, | ||
stateReason = stateReason, | ||
) | ||
|
||
companion object { | ||
fun create( | ||
id: Long, | ||
amount: Int, | ||
state: State, | ||
paymentIncrementalType: String, | ||
paymentIncrementalId: Long, | ||
date: Instant | ||
): PaymentIncrement { | ||
return PaymentIncrement( | ||
id, amount, state, paymentIncrementalType, paymentIncrementalId, date | ||
) | ||
} | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
|
||
enum class State { | ||
COLLECTED, | ||
UNATTEMPTED, | ||
UNKNOWN, | ||
} | ||
} |
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 @@ | ||
package com.kickstarter.models | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class PaymentPlan( | ||
val amountIsPledgeOverTimeEligible: Boolean, | ||
val paymentIncrements: List<PaymentIncrement>?, | ||
val projectIsPledgeOverTimeAllowed: Boolean, | ||
) : Parcelable { | ||
fun amountIsPledgeOverTimeEligible() = this.amountIsPledgeOverTimeEligible | ||
fun paymentIncrements() = this.paymentIncrements | ||
fun projectIsPledgeOverTimeAllowed() = this.projectIsPledgeOverTimeAllowed | ||
|
||
@Parcelize | ||
data class Builder( | ||
var amountIsPledgeOverTimeEligible: Boolean = false, | ||
var paymentIncrements: List<PaymentIncrement>? = null, | ||
var projectIsPledgeOverTimeAllowed: Boolean = false, | ||
) : Parcelable { | ||
fun amountIsPledgeOverTimeEligible(amountIsPledgeOverTimeEligible: Boolean) = apply { this.amountIsPledgeOverTimeEligible = amountIsPledgeOverTimeEligible } | ||
fun paymentIncrements(paymentIncrements: List<PaymentIncrement>?) = apply { this.paymentIncrements = paymentIncrements } | ||
fun projectIsPledgeOverTimeAllowed(projectIsPledgeOverTimeAllowed: Boolean) = apply { this.projectIsPledgeOverTimeAllowed = projectIsPledgeOverTimeAllowed } | ||
fun build() = PaymentPlan( | ||
amountIsPledgeOverTimeEligible = amountIsPledgeOverTimeEligible, | ||
paymentIncrements = paymentIncrements, | ||
projectIsPledgeOverTimeAllowed = projectIsPledgeOverTimeAllowed, | ||
) | ||
} | ||
|
||
companion object { | ||
fun builder() = Builder() | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
amountIsPledgeOverTimeEligible = amountIsPledgeOverTimeEligible, | ||
paymentIncrements = paymentIncrements, | ||
projectIsPledgeOverTimeAllowed = projectIsPledgeOverTimeAllowed, | ||
) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
var equals = super.equals(other) | ||
if (other is PaymentPlan) { | ||
equals = amountIsPledgeOverTimeEligible() == other.amountIsPledgeOverTimeEligible() && | ||
paymentIncrements() == other.paymentIncrements() && | ||
projectIsPledgeOverTimeAllowed() == other.projectIsPledgeOverTimeAllowed() | ||
} | ||
return equals | ||
} | ||
} |
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
Oops, something went wrong.