kopia lustrzana https://github.com/ryukoposting/Signal-Android
A lot more logging for donor badges.
rodzic
41059a2b67
commit
1f649057d6
|
@ -70,6 +70,7 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestTokenFromGooglePay(price: FiatMoney, label: String, requestCode: Int) {
|
fun requestTokenFromGooglePay(price: FiatMoney, label: String, requestCode: Int) {
|
||||||
|
Log.d(TAG, "Requesting a token from google pay...")
|
||||||
googlePayApi.requestPayment(price, label, requestCode)
|
googlePayApi.requestPayment(price, label, requestCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +81,7 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
|
||||||
expectedRequestCode: Int,
|
expectedRequestCode: Int,
|
||||||
paymentsRequestCallback: GooglePayApi.PaymentRequestCallback
|
paymentsRequestCallback: GooglePayApi.PaymentRequestCallback
|
||||||
) {
|
) {
|
||||||
|
Log.d(TAG, "Processing possible google pay result...")
|
||||||
googlePayApi.onActivityResult(requestCode, resultCode, data, expectedRequestCode, paymentsRequestCallback)
|
googlePayApi.onActivityResult(requestCode, resultCode, data, expectedRequestCode, paymentsRequestCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,26 +101,36 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
|
||||||
}
|
}
|
||||||
|
|
||||||
fun continueSubscriptionSetup(paymentData: PaymentData): Completable {
|
fun continueSubscriptionSetup(paymentData: PaymentData): Completable {
|
||||||
|
Log.d(TAG, "Continuing subscription setup...", true)
|
||||||
return stripeApi.createSetupIntent()
|
return stripeApi.createSetupIntent()
|
||||||
.flatMapCompletable { result ->
|
.flatMapCompletable { result ->
|
||||||
stripeApi.confirmSetupIntent(GooglePayPaymentSource(paymentData), result.setupIntent)
|
Log.d(TAG, "Retrieved SetupIntent, confirming...", true)
|
||||||
|
stripeApi.confirmSetupIntent(GooglePayPaymentSource(paymentData), result.setupIntent).doOnComplete {
|
||||||
|
Log.d(TAG, "Confirmed SetupIntent...", true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancelActiveSubscription(): Completable {
|
fun cancelActiveSubscription(): Completable {
|
||||||
|
Log.d(TAG, "Canceling active subscription...", true)
|
||||||
val localSubscriber = SignalStore.donationsValues().requireSubscriber()
|
val localSubscriber = SignalStore.donationsValues().requireSubscriber()
|
||||||
return ApplicationDependencies.getDonationsService()
|
return ApplicationDependencies.getDonationsService()
|
||||||
.cancelSubscription(localSubscriber.subscriberId)
|
.cancelSubscription(localSubscriber.subscriberId)
|
||||||
.flatMap(ServiceResponse<EmptyResponse>::flattenResult).ignoreElement()
|
.flatMap(ServiceResponse<EmptyResponse>::flattenResult)
|
||||||
|
.ignoreElement()
|
||||||
|
.doOnComplete { Log.d(TAG, "Cancelled active subscription.", true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ensureSubscriberId(): Completable {
|
fun ensureSubscriberId(): Completable {
|
||||||
|
Log.d(TAG, "Ensuring SubscriberId exists on Signal service...", true)
|
||||||
val subscriberId = SignalStore.donationsValues().getSubscriber()?.subscriberId ?: SubscriberId.generate()
|
val subscriberId = SignalStore.donationsValues().getSubscriber()?.subscriberId ?: SubscriberId.generate()
|
||||||
return ApplicationDependencies
|
return ApplicationDependencies
|
||||||
.getDonationsService()
|
.getDonationsService()
|
||||||
.putSubscription(subscriberId)
|
.putSubscription(subscriberId)
|
||||||
.flatMap(ServiceResponse<EmptyResponse>::flattenResult).ignoreElement()
|
.flatMap(ServiceResponse<EmptyResponse>::flattenResult).ignoreElement()
|
||||||
.doOnComplete {
|
.doOnComplete {
|
||||||
|
Log.d(TAG, "Successfully set SubscriberId exists on Signal service.", true)
|
||||||
|
|
||||||
SignalStore
|
SignalStore
|
||||||
.donationsValues()
|
.donationsValues()
|
||||||
.setSubscriber(Subscriber(subscriberId, SignalStore.donationsValues().getSubscriptionCurrency().currencyCode))
|
.setSubscriber(Subscriber(subscriberId, SignalStore.donationsValues().getSubscriptionCurrency().currencyCode))
|
||||||
|
@ -245,6 +257,7 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOrCreateLevelUpdateOperation(subscriptionLevel: String): Single<LevelUpdateOperation> = Single.fromCallable {
|
private fun getOrCreateLevelUpdateOperation(subscriptionLevel: String): Single<LevelUpdateOperation> = Single.fromCallable {
|
||||||
|
Log.d(TAG, "Retrieving level update operation for $subscriptionLevel")
|
||||||
val levelUpdateOperation = SignalStore.donationsValues().getLevelOperation(subscriptionLevel)
|
val levelUpdateOperation = SignalStore.donationsValues().getLevelOperation(subscriptionLevel)
|
||||||
if (levelUpdateOperation == null) {
|
if (levelUpdateOperation == null) {
|
||||||
val newOperation = LevelUpdateOperation(
|
val newOperation = LevelUpdateOperation(
|
||||||
|
@ -254,36 +267,48 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
|
||||||
|
|
||||||
SignalStore.donationsValues().setLevelOperation(newOperation)
|
SignalStore.donationsValues().setLevelOperation(newOperation)
|
||||||
LevelUpdate.updateProcessingState(true)
|
LevelUpdate.updateProcessingState(true)
|
||||||
|
Log.d(TAG, "Created a new operation for $subscriptionLevel")
|
||||||
newOperation
|
newOperation
|
||||||
} else {
|
} else {
|
||||||
LevelUpdate.updateProcessingState(true)
|
LevelUpdate.updateProcessingState(true)
|
||||||
|
Log.d(TAG, "Reusing operation for $subscriptionLevel")
|
||||||
levelUpdateOperation
|
levelUpdateOperation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchPaymentIntent(price: FiatMoney, description: String?): Single<StripeApi.PaymentIntent> {
|
override fun fetchPaymentIntent(price: FiatMoney, description: String?): Single<StripeApi.PaymentIntent> {
|
||||||
|
Log.d(TAG, "Fetching payment intent from Signal service...")
|
||||||
return ApplicationDependencies
|
return ApplicationDependencies
|
||||||
.getDonationsService()
|
.getDonationsService()
|
||||||
.createDonationIntentWithAmount(price.minimumUnitPrecisionString, price.currency.currencyCode, description)
|
.createDonationIntentWithAmount(price.minimumUnitPrecisionString, price.currency.currencyCode, description)
|
||||||
.flatMap(ServiceResponse<SubscriptionClientSecret>::flattenResult)
|
.flatMap(ServiceResponse<SubscriptionClientSecret>::flattenResult)
|
||||||
.map {
|
.map {
|
||||||
StripeApi.PaymentIntent(it.id, it.clientSecret)
|
StripeApi.PaymentIntent(it.id, it.clientSecret)
|
||||||
|
}.doOnSuccess {
|
||||||
|
Log.d(TAG, "Got payment intent from Signal service!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchSetupIntent(): Single<StripeApi.SetupIntent> {
|
override fun fetchSetupIntent(): Single<StripeApi.SetupIntent> {
|
||||||
|
Log.d(TAG, "Fetching setup intent from Signal service...")
|
||||||
return Single.fromCallable { SignalStore.donationsValues().requireSubscriber() }
|
return Single.fromCallable { SignalStore.donationsValues().requireSubscriber() }
|
||||||
.flatMap { ApplicationDependencies.getDonationsService().createSubscriptionPaymentMethod(it.subscriberId) }
|
.flatMap { ApplicationDependencies.getDonationsService().createSubscriptionPaymentMethod(it.subscriberId) }
|
||||||
.flatMap(ServiceResponse<SubscriptionClientSecret>::flattenResult)
|
.flatMap(ServiceResponse<SubscriptionClientSecret>::flattenResult)
|
||||||
.map { StripeApi.SetupIntent(it.id, it.clientSecret) }
|
.map { StripeApi.SetupIntent(it.id, it.clientSecret) }
|
||||||
|
.doOnSuccess {
|
||||||
|
Log.d(TAG, "Got setup intent from Signal service!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setDefaultPaymentMethod(paymentMethodId: String): Completable {
|
override fun setDefaultPaymentMethod(paymentMethodId: String): Completable {
|
||||||
|
Log.d(TAG, "Setting default payment method via Signal service...")
|
||||||
return Single.fromCallable {
|
return Single.fromCallable {
|
||||||
SignalStore.donationsValues().requireSubscriber()
|
SignalStore.donationsValues().requireSubscriber()
|
||||||
}.flatMap {
|
}.flatMap {
|
||||||
ApplicationDependencies.getDonationsService().setDefaultPaymentMethodId(it.subscriberId, paymentMethodId)
|
ApplicationDependencies.getDonationsService().setDefaultPaymentMethodId(it.subscriberId, paymentMethodId)
|
||||||
}.flatMap(ServiceResponse<EmptyResponse>::flattenResult).ignoreElement()
|
}.flatMap(ServiceResponse<EmptyResponse>::flattenResult).ignoreElement().doOnComplete {
|
||||||
|
Log.d(TAG, "Set default payment method via Signal service!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
Ładowanie…
Reference in New Issue