Skip to content

Commit

Permalink
Add example on how to access customer's cash tag after successful app…
Browse files Browse the repository at this point in the history
…roval
  • Loading branch information
tir38 committed Aug 27, 2024
1 parent 3ab6c78 commit cbf3122
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions sample/src/main/java/com/example/CashAppV3SampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import app.cash.paykit.core.CashAppPayState.ReadyToAuthorize
import app.cash.paykit.core.CashAppPayState.Refreshing
import app.cash.paykit.core.CashAppPayState.RetrievingExistingCustomerRequest
import app.cash.paykit.core.CashAppPayState.UpdatingCustomerRequest
import app.cash.paykit.core.models.response.Grant
import app.cash.paykit.core.models.sdk.CashAppPayCurrency.USD
import app.cash.paykit.core.models.sdk.CashAppPayPaymentAction
import com.afterpay.android.Afterpay
Expand Down Expand Up @@ -86,13 +87,22 @@ class CashAppV3SampleActivity : AppCompatActivity() {
* Step 8: After successful approval, confirm checkout with Afterpay
*/
Log.d(tag, newState.responseData.toString())
// TODO @jatwood what happens if I have multiple grants?
newState.responseData.grants?.get(0)?.let { grant ->
CoroutineScope(Dispatchers.IO).launch {
confirmCheckoutWithAfterpay(
grantId = grant.id,
customerId = grant.customerId,
)

newState.responseData.apply {
// optionally, retrieve customer's cash tag
val cashTag = customerProfile?.cashTag
showToast(
this@CashAppV3SampleActivity,
"Grant approved for customer: $cashTag",
)

grants?.get(0)?.let { grant: Grant ->
CoroutineScope(Dispatchers.IO).launch {
confirmCheckoutWithAfterpay(
grantId = grant.id,
customerId = grant.customerId,
)
}
}
}
}
Expand Down

0 comments on commit cbf3122

Please sign in to comment.