Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pedro/release 2.5.0 #148

Merged
merged 32 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6129240
Fix Retrieve Existing request ID behavior for PROCESSING state (#95)
pedronveloso Apr 17, 2023
be86a83
Code cleanup (and research on proguard rules being handed to consumer…
pedronveloso Apr 24, 2023
c1fc480
Add enum for GrantType (#99)
pedronveloso Apr 25, 2023
761eaaa
Update Robolectric dependency (#102)
pedronveloso Apr 28, 2023
25017aa
Update changelog
pedronveloso Apr 28, 2023
723c538
Merge branch 'main' into develop
pedronveloso Apr 28, 2023
f001043
Merge branch 'main' into develop
pedronveloso May 15, 2023
d84525c
Use Epoch usec for Analytics timestamp (#107)
pedronveloso Jun 5, 2023
8cc7804
Add UT for Analytics (#108)
pedronveloso Jun 21, 2023
b975e84
Refresh Auth Token for Customer Request (#109)
pedronveloso Jun 29, 2023
3101dff
Merge branch 'main' into develop
pedronveloso Jun 29, 2023
1338f8d
Abstract thread managment away from main class (#113)
pedronveloso Jul 5, 2023
1cb9081
Redact PII for logs and metrics (#112)
pedronveloso Jul 7, 2023
1602b4b
Merge branch 'main' into develop
pedronveloso Jul 7, 2023
8a94624
Simplify internal class names (#115)
pedronveloso Jul 10, 2023
01b9db5
Modify CashAppPayButton to allow for dynamic styles (#116)
pedronveloso Jul 14, 2023
fdd4c04
Add PR template (#120)
pedronveloso Jul 19, 2023
e236267
Logging abstraction (#119)
pedronveloso Jul 20, 2023
d8a4001
Set default PR template (#121)
pedronveloso Jul 21, 2023
282d764
Make Initializer open to modification (#123)
pedronveloso Aug 1, 2023
eb25c8d
Update Spotless Plugin and Ktlint version (#124)
pedronveloso Aug 4, 2023
2883886
Add minify rules (#125)
pedronveloso Aug 18, 2023
22a6975
Update Core dependency on OkHttp (#126)
pedronveloso Aug 18, 2023
5f8ce69
Merge branch 'main' into develop
pedronveloso Aug 21, 2023
899d5d2
Update Android target version (#133)
pedronveloso Nov 2, 2023
c96b2f0
Update AGP & Gradle (#138)
pedronveloso Dec 5, 2023
3b8e953
Pedro/sdk kotlin 1.8 (#139)
pedronveloso Jan 12, 2024
e48a5f6
Update AGP and dev app version
pedronveloso Feb 27, 2024
9957ef1
Use reference_id param correctly (#145)
pedronveloso Jul 16, 2024
f08c551
Bump develop version
pedronveloso Jul 17, 2024
67845e0
Reference id mixup fix (#147)
pedronveloso Jul 19, 2024
56c0a38
Prepare release 2.5.0
pedronveloso Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 2.4.0 - UPCOMING
# 2.5.0

- Fix correct usage of `account_reference_id` in `OnFileAction`
- Add `reference_id` as a parameter of creating a customer request. This is to bring the Android SDK to parity with iOS and Web.

# 2.4.0

- Fix: `OnFileAction` param `accountReferenceId` is now properly being sent over the network
- Update Android target SDK version to API 33
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ subprojects { subproject ->
}
}

def NEXT_VERSION = "2.4.1-SNAPSHOT"
def NEXT_VERSION = "2.5.1-SNAPSHOT"

allprojects {

group = 'app.cash.paykit'
version = '2.4.0'
version = '2.5.0'

plugins.withId("com.vanniktech.maven.publish.base") {
mavenPublishing {
Expand Down
11 changes: 9 additions & 2 deletions core/src/main/java/app/cash/paykit/core/CashAppPay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ interface CashAppPay {
* @param paymentAction A wrapper class that contains all of the necessary ingredients for building a customer requests.
* Look at [PayKitPaymentAction] for more details.
* @param redirectUri The URI for Cash App to redirect back to your app. If you do not set this, back navigation from CashApp might not work as intended.
* @param referenceId Optional identifier generated by you for this request, typically used to associate the resource with a record in an external system.
*/
@WorkerThread
fun createCustomerRequest(paymentAction: CashAppPayPaymentAction, redirectUri: String?)
fun createCustomerRequest(paymentAction: CashAppPayPaymentAction, redirectUri: String?, referenceId: String? = null)

/**
* Create customer request given list of [CashAppPayPaymentAction].
Expand All @@ -57,9 +58,11 @@ interface CashAppPay {
* @param paymentActions A wrapper class that contains all of the necessary ingredients for building one or more customer requests.
* Look at [PayKitPaymentAction] for more details.
* @param redirectUri The URI for Cash App to redirect back to your app. If you do not set this, back navigation from CashApp might not work as intended.
* @param referenceId Optional identifier generated by you for this request, typically used to associate the resource with a record in an external system.
*
*/
@WorkerThread
fun createCustomerRequest(paymentActions: List<CashAppPayPaymentAction>, redirectUri: String?)
fun createCustomerRequest(paymentActions: List<CashAppPayPaymentAction>, redirectUri: String?, referenceId: String? = null)

/**
* Update an existing customer request given its [requestId] and the updated definitions contained within [CashAppPayPaymentAction].
Expand All @@ -69,11 +72,13 @@ interface CashAppPay {
* @param requestId ID of the request we intent do update.
* @param paymentAction A wrapper class that contains all of the necessary ingredients for updating a customer request for a given [requestId].
* Look at [CashAppPayPaymentAction] for more details.
* @param referenceId Optional identifier generated by you for this request, typically used to associate the resource with a record in an external system.
*/
@WorkerThread
fun updateCustomerRequest(
requestId: String,
paymentAction: CashAppPayPaymentAction,
referenceId: String? = null,
)

/**
Expand All @@ -84,11 +89,13 @@ interface CashAppPay {
* @param requestId ID of the request we intent do update.
* @param paymentActions A wrapper class that contains all of the necessary ingredients for updating one more more customer requests that share the same [requestId].
* Look at [CashAppPayPaymentAction] for more details.
* @param referenceId Optional identifier generated by you for this request, typically used to associate the resource with a record in an external system.
*/
@WorkerThread
fun updateCustomerRequest(
requestId: String,
paymentActions: List<CashAppPayPaymentAction>,
referenceId: String? = null,
)

/**
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/app/cash/paykit/core/NetworkManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ internal interface NetworkManager {
clientId: String,
paymentActions: List<CashAppPayPaymentAction>,
redirectUri: String?,
referenceId: String?,
): NetworkResult<CustomerTopLevelResponse>

@Throws(IOException::class)
fun updateCustomerRequest(
clientId: String,
requestId: String,
referenceId: String?,
paymentActions: List<CashAppPayPaymentAction>,
): NetworkResult<CustomerTopLevelResponse>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import app.cash.paykit.core.models.request.CustomerRequestDataFactory.CHANNEL_IN
import app.cash.paykit.core.models.response.CustomerResponseData
import app.cash.paykit.core.models.response.Grant
import app.cash.paykit.core.models.sdk.CashAppPayPaymentAction
import app.cash.paykit.core.models.sdk.CashAppPayPaymentAction.OnFileAction
import app.cash.paykit.core.network.MoshiProvider
import app.cash.paykit.core.utils.Clock
import app.cash.paykit.core.utils.ClockRealImpl
Expand Down Expand Up @@ -218,14 +217,6 @@ internal class PayKitAnalyticsEventDispatcherImpl(
val moshiAdapter: JsonAdapter<List<Action>> = moshi.adapter()
val apiActionsAsJson: String = moshiAdapter.toJson(apiActions)

// Inner payload of the ES2 event.
var possibleReferenceId: String? = null
for (paymentAction in paymentKitActions) {
if (paymentAction is OnFileAction) {
possibleReferenceId = paymentAction.accountReferenceId
}
}

return AnalyticsCustomerRequestPayload(
sdkVersion,
userAgent,
Expand All @@ -235,7 +226,6 @@ internal class PayKitAnalyticsEventDispatcherImpl(
createActions = apiActionsAsJson,
createChannel = CHANNEL_IN_APP,
createRedirectUrl = redirectUri?.let { PiiString(redirectUri) },
createReferenceId = possibleReferenceId?.let { PiiString(possibleReferenceId) },
environment = sdkEnvironment,
)
}
Expand Down Expand Up @@ -285,7 +275,6 @@ internal class PayKitAnalyticsEventDispatcherImpl(
customerId = customerResponseData?.customerProfile?.id,
customerCashTag = customerResponseData?.customerProfile?.cashTag,
requestId = customerResponseData?.id,
referenceId = customerResponseData?.referenceId,
environment = sdkEnvironment,
)
}
Expand Down
37 changes: 30 additions & 7 deletions core/src/main/java/app/cash/paykit/core/impl/CashAppPayImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ internal class CashAppPayImpl(
analyticsEventDispatcher.sdkInitialized()
}

override fun createCustomerRequest(paymentAction: CashAppPayPaymentAction, redirectUri: String?) {
createCustomerRequest(listOf(paymentAction), redirectUri)
override fun createCustomerRequest(
paymentAction: CashAppPayPaymentAction,
redirectUri: String?,
referenceId: String?,
) {
createCustomerRequest(listOf(paymentAction), redirectUri, referenceId)
}

/**
Expand All @@ -132,7 +136,11 @@ internal class CashAppPayImpl(
* Look at [PayKitPaymentAction] for more details.
*/
@WorkerThread
override fun createCustomerRequest(paymentActions: List<CashAppPayPaymentAction>, redirectUri: String?) {
override fun createCustomerRequest(
paymentActions: List<CashAppPayPaymentAction>,
redirectUri: String?,
referenceId: String?,
) {
enforceRegisteredStateUpdatesListener()

// Validate [paymentActions] is not empty.
Expand All @@ -145,7 +153,12 @@ internal class CashAppPayImpl(
currentState = CreatingCustomerRequest

// Network call.
val networkResult = networkManager.createCustomerRequest(clientId, paymentActions, redirectUri)
val networkResult = networkManager.createCustomerRequest(
clientId = clientId,
paymentActions = paymentActions,
redirectUri = redirectUri,
referenceId = referenceId,
)
when (networkResult) {
is Failure -> {
currentState = CashAppPayExceptionState(networkResult.exception)
Expand All @@ -159,8 +172,12 @@ internal class CashAppPayImpl(
}
}

override fun updateCustomerRequest(requestId: String, paymentAction: CashAppPayPaymentAction) {
updateCustomerRequest(requestId, listOf(paymentAction))
override fun updateCustomerRequest(
requestId: String,
paymentAction: CashAppPayPaymentAction,
referenceId: String?,
) {
updateCustomerRequest(requestId, listOf(paymentAction), referenceId)
}

/**
Expand All @@ -175,6 +192,7 @@ internal class CashAppPayImpl(
override fun updateCustomerRequest(
requestId: String,
paymentActions: List<CashAppPayPaymentAction>,
referenceId: String?,
) {
enforceRegisteredStateUpdatesListener()

Expand All @@ -188,7 +206,12 @@ internal class CashAppPayImpl(
currentState = UpdatingCustomerRequest

// Network request.
val networkResult = networkManager.updateCustomerRequest(clientId, requestId, paymentActions)
val networkResult = networkManager.updateCustomerRequest(
clientId = clientId,
requestId = requestId,
referenceId = referenceId,
paymentActions = paymentActions,
)
when (networkResult) {
is Failure -> {
currentState = CashAppPayExceptionState(networkResult.exception)
Expand Down
23 changes: 20 additions & 3 deletions core/src/main/java/app/cash/paykit/core/impl/NetworkManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ internal class NetworkManagerImpl(
clientId: String,
paymentActions: List<CashAppPayPaymentAction>,
redirectUri: String?,
referenceId: String?,
): NetworkResult<CustomerTopLevelResponse> {
val customerRequestData = CustomerRequestDataFactory.build(clientId, redirectUri, paymentActions)
val customerRequestData = CustomerRequestDataFactory.build(
clientId = clientId,
redirectUri = redirectUri,
referenceId = referenceId,
paymentActions = paymentActions,
)
val createCustomerRequest = CreateCustomerRequest(
idempotencyKey = UUID.randomUUID().toString(),
customerRequestData = customerRequestData,
Expand All @@ -103,16 +109,27 @@ internal class NetworkManagerImpl(
override fun updateCustomerRequest(
clientId: String,
requestId: String,
referenceId: String?,
paymentActions: List<CashAppPayPaymentAction>,
): NetworkResult<CustomerTopLevelResponse> {
val customerRequestData =
CustomerRequestDataFactory.build(clientId, null, paymentActions, isRequestUpdate = true)
CustomerRequestDataFactory.build(
clientId = clientId,
redirectUri = null,
referenceId = referenceId,
paymentActions = paymentActions,
isRequestUpdate = true,
)
val createCustomerRequest = CreateCustomerRequest(
customerRequestData = customerRequestData,
)

// Record analytics.
analyticsEventDispatcher?.updatedCustomerRequest(requestId, paymentActions, customerRequestData.actions)
analyticsEventDispatcher?.updatedCustomerRequest(
requestId = requestId,
paymentKitActions = paymentActions,
apiActions = customerRequestData.actions,
)

return executeNetworkRequest(
PATCH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package app.cash.paykit.core.models.common

import app.cash.paykit.core.models.pii.PiiString
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

Expand All @@ -28,4 +29,6 @@ data class Action(
val scopeId: String,
@Json(name = "type")
val type: String,
@Json(name = "account_reference_id")
val accountReferenceId: PiiString? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@ object CustomerRequestDataFactory {
fun build(
clientId: String,
redirectUri: String?,
referenceId: String?,
paymentActions: List<CashAppPayPaymentAction>,
isRequestUpdate: Boolean = false,
): CustomerRequestData {
val actions = ArrayList<Action>(paymentActions.size)
var possibleReferenceId: String? = null

for (paymentAction in paymentActions) {
when (paymentAction) {
is OnFileAction -> {
actions.add(buildFromOnFileAction(clientId, paymentAction))
if (paymentAction.accountReferenceId != null) {
possibleReferenceId = paymentAction.accountReferenceId
}
}
is OnFileAction -> actions.add(buildFromOnFileAction(clientId, paymentAction))
is OneTimeAction -> actions.add(buildFromOneTimeAction(clientId, paymentAction))
}
}
Expand All @@ -56,14 +51,14 @@ object CustomerRequestDataFactory {
actions = actions,
channel = null,
redirectUri = null,
referenceId = possibleReferenceId?.let { PiiString(it) },
referenceId = referenceId?.let { PiiString(it) },
)
} else {
CustomerRequestData(
actions = actions,
channel = CHANNEL_IN_APP,
redirectUri = redirectUri?.let { PiiString(it) },
referenceId = possibleReferenceId?.let { PiiString(it) },
referenceId = referenceId?.let { PiiString(it) },
)
}
}
Expand All @@ -78,6 +73,7 @@ object CustomerRequestDataFactory {
return Action(
scopeId = scopeIdOrClientId,
type = PAYMENT_TYPE_ON_FILE,
accountReferenceId = onFileAction.accountReferenceId?.let { PiiString(it) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import app.cash.paykit.core.CashAppPay
/**
* This class holds the information necessary for [CashAppPay.createCustomerRequest] to be executed.
*/
sealed class CashAppPayPaymentAction(scopeId: String?) {
sealed class CashAppPayPaymentAction(open val scopeId: String?, open val referenceId: String?) {

/**
* Describes an intent for a client to charge a customer a given amount.
Expand All @@ -38,8 +38,9 @@ sealed class CashAppPayPaymentAction(scopeId: String?) {
data class OneTimeAction(
val currency: CashAppPayCurrency?,
val amount: Int?,
val scopeId: String? = null,
) : CashAppPayPaymentAction(scopeId)
override val scopeId: String? = null,
override val referenceId: String? = null,
) : CashAppPayPaymentAction(scopeId, referenceId)

/**
* Describes an intent for a client to store a customer's account, allowing a client to create payments
Expand All @@ -49,8 +50,9 @@ sealed class CashAppPayPaymentAction(scopeId: String?) {
* @param accountReferenceId Identifier of the account or customer associated to the on file action.
*/
data class OnFileAction(
val scopeId: String? = null,
override val scopeId: String? = null,
val accountReferenceId: String? = null,
override val referenceId: String? = null,
) :
CashAppPayPaymentAction(scopeId)
CashAppPayPaymentAction(scopeId, referenceId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CashAppPayExceptionsTests {
val listener = mockk<CashAppPayListener>(relaxed = true)
payKit.registerForStateUpdates(listener)

every { networkManager.createCustomerRequest(any(), any(), any()) } returns NetworkResult.failure(
every { networkManager.createCustomerRequest(any(), any(), any(), any()) } returns NetworkResult.failure(
Exception("bad"),
)
payKit.createCustomerRequest(FakeData.oneTimePayment, FakeData.REDIRECT_URI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CashAppPayStateTests {
val listener = mockk<CashAppPayListener>(relaxed = true)
payKit.registerForStateUpdates(listener)

every { networkManager.createCustomerRequest(any(), any(), any()) } returns NetworkResult.failure(
every { networkManager.createCustomerRequest(any(), any(), any(), any()) } returns NetworkResult.failure(
Exception("bad"),
)

Expand All @@ -95,6 +95,7 @@ class CashAppPayStateTests {
any(),
any(),
any(),
any(),
)
} returns NetworkResult.failure(
Exception("bad"),
Expand Down Expand Up @@ -180,6 +181,7 @@ class CashAppPayStateTests {
any(),
any(),
any(),
any(),
)
} returns customerTopLevelResponse

Expand Down
Loading