Skip to content

Commit

Permalink
Added ObfuscatedAccountId
Browse files Browse the repository at this point in the history
  • Loading branch information
IrynaTsymbaliuk committed May 29, 2022
1 parent d9c7dda commit 6147514
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class NodeRepository(var deferredNode: DeferredNode) {
suspend fun createPaymentGatewayOrder(req: CreatePaymentGatewayOrderReq) =
withContext(Dispatchers.IO) {
try {
deferredNode.await().createPaymentGatewayOrder(req)
val order = deferredNode.await().createPaymentGatewayOrder(req).decodeToString()
Log.d(TAG, "createPaymentOrder response: $order")
Order.fromJSON(order) ?: error("Could not parse JSON: $order")
} catch (e: Exception) {
if (isBalanceLimitExceeded()) {
throw TopupPreconditionFailedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.google.gson.reflect.TypeToken

data class Order constructor(
@SerializedName("id")
val id: Long,
val id: String,
@SerializedName("identity_address")
val identity: String,
@SerializedName("status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.android.parcel.Parcelize

@Parcelize
data class TopUpPriceCardItem(
val id: String,
val sku: String,
val price: Double,
var isSelected: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class PaymentUseCase(private val nodeRepository: NodeRepository) {
suspend fun createPaymentGatewayOrder(
identityAddress: String,
amountUSD: Double
) {
): Order {
val req = CreatePaymentGatewayOrderReq().apply {
this.payCurrency = currency
this.identityAddress = identityAddress
this.mystAmount = "0"
this.amountUSD = amountUSD.toString()
this.gateway = Gateway.GOOGLE.gateway
}
nodeRepository.createPaymentGatewayOrder(req)
return nodeRepository.createPaymentGatewayOrder(req)
}

suspend fun paymentOrderCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TopUpPaymentViewModel(
return list.map { skuDetails ->
val price = skuDetails.description.filter { it in filterRange }.toDouble()
TopUpPriceCardItem(
id = "",
sku = skuDetails.sku,
price = price,
isSelected = list.indexOf(skuDetails) == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.os.SystemClock
import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.android.billingclient.api.*
import com.android.billingclient.api.Purchase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
Expand Down Expand Up @@ -304,11 +305,13 @@ class BillingDataSource(application: Application) : PurchasesUpdatedListener,
}
}

fun launchBillingFlow(activity: Activity, sku: String) {
fun launchBillingFlow(activity: Activity, sku: String, id: String) {
val skuDetails = skuDetailsMap[sku]?.value
if (null != skuDetails) {
val billingFlowParamsBuilder = BillingFlowParams.newBuilder()
billingFlowParamsBuilder.setSkuDetails(skuDetails)
billingFlowParamsBuilder
.setObfuscatedAccountId(id)
.setSkuDetails(skuDetails)
defaultScope.launch {
val br = billingClient.launchBillingFlow(
activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PaymentSummaryActivity : BaseActivity() {

paymentStatusViewModel.getPayment(price).observe(this) {
it.onSuccess {
topUpPriceCardItem = topUpPriceCardItem?.copy(id = it.id)
inflateOrderData(price)
}
it.onFailure { error ->
Expand Down Expand Up @@ -113,7 +114,8 @@ class PaymentSummaryActivity : BaseActivity() {
topUpPriceCardItem?.let {
paymentViewModel.billingDataSource.launchBillingFlow(
this@PaymentSummaryActivity,
it.sku
it.sku,
it.id
)
}
}
Expand Down

0 comments on commit 6147514

Please sign in to comment.