mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Implement backup receipt generation.
This commit is contained in:
committed by
Nicholas Tinsley
parent
82c3265be5
commit
816c9360cd
@@ -6,7 +6,7 @@ import androidx.core.content.contentValuesOf
|
||||
import org.signal.core.util.CursorUtil
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.money.FiatMoney
|
||||
import org.thoughtcrime.securesms.database.model.DonationReceiptRecord
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentReceiptRecord
|
||||
import java.math.BigDecimal
|
||||
import java.util.Currency
|
||||
|
||||
@@ -46,7 +46,7 @@ class DonationReceiptTable(context: Context, databaseHelper: SignalDatabase) : D
|
||||
}
|
||||
}
|
||||
|
||||
fun addReceipt(record: DonationReceiptRecord) {
|
||||
fun addReceipt(record: InAppPaymentReceiptRecord) {
|
||||
require(record.id == -1L)
|
||||
|
||||
val values = contentValuesOf(
|
||||
@@ -60,7 +60,7 @@ class DonationReceiptTable(context: Context, databaseHelper: SignalDatabase) : D
|
||||
writableDatabase.insert(TABLE_NAME, null, values)
|
||||
}
|
||||
|
||||
fun getReceipt(id: Long): DonationReceiptRecord? {
|
||||
fun getReceipt(id: Long): InAppPaymentReceiptRecord? {
|
||||
readableDatabase.query(TABLE_NAME, null, ID_WHERE, SqlUtil.buildArgs(id), null, null, null).use { cursor ->
|
||||
return if (cursor.moveToNext()) {
|
||||
readRecord(cursor)
|
||||
@@ -70,15 +70,15 @@ class DonationReceiptTable(context: Context, databaseHelper: SignalDatabase) : D
|
||||
}
|
||||
}
|
||||
|
||||
fun getReceipts(type: DonationReceiptRecord.Type?): List<DonationReceiptRecord> {
|
||||
fun getReceipts(type: InAppPaymentReceiptRecord.Type?): List<InAppPaymentReceiptRecord> {
|
||||
val (where, whereArgs) = if (type != null) {
|
||||
"$TYPE = ?" to SqlUtil.buildArgs(type.code)
|
||||
} else {
|
||||
"$TYPE != ?" to SqlUtil.buildArgs(DonationReceiptRecord.Type.RECURRING_DONATION)
|
||||
"$TYPE != ?" to SqlUtil.buildArgs(InAppPaymentReceiptRecord.Type.RECURRING_DONATION)
|
||||
}
|
||||
|
||||
readableDatabase.query(TABLE_NAME, null, where, whereArgs, null, null, "$DATE DESC").use { cursor ->
|
||||
val results = ArrayList<DonationReceiptRecord>(cursor.count)
|
||||
val results = ArrayList<InAppPaymentReceiptRecord>(cursor.count)
|
||||
while (cursor.moveToNext()) {
|
||||
results.add(readRecord(cursor))
|
||||
}
|
||||
@@ -87,10 +87,10 @@ class DonationReceiptTable(context: Context, databaseHelper: SignalDatabase) : D
|
||||
}
|
||||
}
|
||||
|
||||
private fun readRecord(cursor: Cursor): DonationReceiptRecord {
|
||||
return DonationReceiptRecord(
|
||||
private fun readRecord(cursor: Cursor): InAppPaymentReceiptRecord {
|
||||
return InAppPaymentReceiptRecord(
|
||||
id = CursorUtil.requireLong(cursor, ID),
|
||||
type = DonationReceiptRecord.Type.fromCode(CursorUtil.requireString(cursor, TYPE)),
|
||||
type = InAppPaymentReceiptRecord.Type.fromCode(CursorUtil.requireString(cursor, TYPE)),
|
||||
amount = FiatMoney(
|
||||
BigDecimal(CursorUtil.requireString(cursor, AMOUNT)),
|
||||
Currency.getInstance(CursorUtil.requireString(cursor, CURRENCY))
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription
|
||||
import org.whispersystems.signalservice.internal.push.SubscriptionsConfiguration
|
||||
import java.util.Currency
|
||||
|
||||
data class DonationReceiptRecord(
|
||||
data class InAppPaymentReceiptRecord(
|
||||
val id: Long = -1L,
|
||||
val amount: FiatMoney,
|
||||
val timestamp: Long,
|
||||
@@ -20,18 +20,18 @@ data class DonationReceiptRecord(
|
||||
|
||||
companion object {
|
||||
fun fromCode(code: String): Type {
|
||||
return values().first { it.code == code }
|
||||
return entries.first { it.code == code }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun createForSubscription(subscription: ActiveSubscription.Subscription): DonationReceiptRecord {
|
||||
fun createForSubscription(subscription: ActiveSubscription.Subscription): InAppPaymentReceiptRecord {
|
||||
val activeCurrency = Currency.getInstance(subscription.currency)
|
||||
val activeAmount = subscription.amount.movePointLeft(activeCurrency.defaultFractionDigits)
|
||||
|
||||
return DonationReceiptRecord(
|
||||
return InAppPaymentReceiptRecord(
|
||||
id = -1L,
|
||||
amount = FiatMoney(activeAmount, activeCurrency),
|
||||
timestamp = System.currentTimeMillis(),
|
||||
@@ -40,8 +40,8 @@ data class DonationReceiptRecord(
|
||||
)
|
||||
}
|
||||
|
||||
fun createForBoost(amount: FiatMoney): DonationReceiptRecord {
|
||||
return DonationReceiptRecord(
|
||||
fun createForBoost(amount: FiatMoney): InAppPaymentReceiptRecord {
|
||||
return InAppPaymentReceiptRecord(
|
||||
id = -1L,
|
||||
amount = amount,
|
||||
timestamp = System.currentTimeMillis(),
|
||||
@@ -50,8 +50,8 @@ data class DonationReceiptRecord(
|
||||
)
|
||||
}
|
||||
|
||||
fun createForGift(amount: FiatMoney): DonationReceiptRecord {
|
||||
return DonationReceiptRecord(
|
||||
fun createForGift(amount: FiatMoney): InAppPaymentReceiptRecord {
|
||||
return InAppPaymentReceiptRecord(
|
||||
id = -1L,
|
||||
amount = amount,
|
||||
timestamp = System.currentTimeMillis(),
|
||||
Reference in New Issue
Block a user