Skip to content

Commit

Permalink
Merge pull request #9 from afterpay/maintenance/update-from-upstream-…
Browse files Browse the repository at this point in the history
…4.2.0

Maintenance: update from upstream 4.2.0
  • Loading branch information
ScottAntonacAP authored Oct 31, 2022
2 parents 7c2db36 + e058a87 commit 1cee27c
Show file tree
Hide file tree
Showing 87 changed files with 497 additions and 413 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true

[*.md]
trim_trailing_whitespace = false

Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: 11
distribution: 'zulu'

- name: Lint
run: ./gradlew afterpay:lintDebug afterpay:ktlint
Expand All @@ -30,12 +31,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: 11
distribution: 'zulu'

- name: Build and Lint
run: ./gradlew example:buildDebug example:lintDebug example:ktlint
7 changes: 4 additions & 3 deletions .github/workflows/release-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: 11
distribution: 'zulu'

- name: Clean repository before building SDK
run: ./gradlew clean
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: 11
distribution: 'zulu'

- name: Remove SNAPSHOT from version
run: sed -i 's/-SNAPSHOT//g' gradle.properties
Expand Down
9 changes: 0 additions & 9 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion afterpay/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations

# kotlinx-serialization-json specific. Add this if you have java.lang.NoClassDefFoundError kotlinx.serialization.json.JsonObjectSerializer
-keepclassmembers class kotlinx.serialization.json.** {
Expand Down
32 changes: 17 additions & 15 deletions afterpay/src/main/kotlin/com/afterpay/android/Afterpay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.afterpay.android.internal.getCancellationStatusExtraV3
import com.afterpay.android.internal.getOrderTokenExtra
import com.afterpay.android.internal.getRegionLanguage
import com.afterpay.android.internal.getResultDataExtra
import com.afterpay.android.internal.putCheckoutShouldLoadRedirectUrls
import com.afterpay.android.internal.putCheckoutUrlExtra
import com.afterpay.android.internal.putCheckoutV2OptionsExtra
import com.afterpay.android.internal.putCheckoutV3OptionsExtra
Expand Down Expand Up @@ -75,10 +76,11 @@ object Afterpay {
* Afterpay checkout.
*/
@JvmStatic
fun createCheckoutIntent(context: Context, checkoutUrl: String): Intent {
fun createCheckoutIntent(context: Context, checkoutUrl: String, loadRedirectUrls: Boolean = false): Intent {
val url = if (enabled) { checkoutUrl } else { "LANGUAGE_NOT_SUPPORTED" }
return Intent(context, AfterpayCheckoutActivity::class.java)
.putCheckoutUrlExtra(url)
.putCheckoutShouldLoadRedirectUrls(loadRedirectUrls)
}

/**
Expand All @@ -89,7 +91,7 @@ object Afterpay {
@JvmStatic
fun createCheckoutV2Intent(
context: Context,
options: AfterpayCheckoutV2Options = AfterpayCheckoutV2Options()
options: AfterpayCheckoutV2Options = AfterpayCheckoutV2Options(),
): Intent = Intent(context, AfterpayCheckoutV2Activity::class.java)
.putCheckoutV2OptionsExtra(options)

Expand Down Expand Up @@ -125,14 +127,14 @@ object Afterpay {
maximumAmount: String,
currencyCode: String,
locale: Locale,
environment: AfterpayEnvironment
environment: AfterpayEnvironment,
) {
configuration = Configuration(
minimumAmount = minimumAmount?.toBigDecimal(),
maximumAmount = maximumAmount.toBigDecimal(),
currency = Currency.getInstance(currencyCode),
locale = locale.clone() as Locale,
environment = environment
environment = environment,
).also { validateConfiguration(it) }
}

Expand Down Expand Up @@ -192,7 +194,7 @@ object Afterpay {
orderTotal: OrderTotal,
items: Array<CheckoutV3Item> = arrayOf(),
buyNow: Boolean,
configuration: CheckoutV3Configuration? = checkoutV3Configuration
configuration: CheckoutV3Configuration? = checkoutV3Configuration,
): Intent {
requireNotNull(configuration) {
"`configuration` must be set via `setCheckoutV3Configuration` or passed into this function"
Expand All @@ -207,7 +209,7 @@ object Afterpay {
buyNow = buyNow,
checkoutPayload = Json.encodeToString(checkoutRequest),
checkoutUrl = configuration.v3CheckoutUrl,
confirmUrl = configuration.v3CheckoutConfirmationUrl
confirmUrl = configuration.v3CheckoutConfirmationUrl,
)

return Intent(context, AfterpayCheckoutV3Activity::class.java)
Expand All @@ -221,7 +223,7 @@ object Afterpay {
fun updateMerchantReferenceV3(
merchantReference: String,
tokens: CheckoutV3Tokens,
configuration: CheckoutV3Configuration? = checkoutV3Configuration
configuration: CheckoutV3Configuration? = checkoutV3Configuration,
): Result<Unit> {
requireNotNull(configuration) {
"`configuration` must be set via `setCheckoutV3Configuration` or passed into this function"
Expand All @@ -231,13 +233,13 @@ object Afterpay {
merchantReference,
token = tokens.token,
ppaConfirmToken = tokens.ppaConfirmToken,
singleUseCardToken = tokens.singleUseCardToken
singleUseCardToken = tokens.singleUseCardToken,
)

return ApiV3.requestUnit(
configuration.v3CheckoutUrl,
ApiV3.HttpVerb.PUT,
payload
payload,
)
}

Expand All @@ -256,7 +258,7 @@ object Afterpay {
updateMerchantReferenceV3(merchantReference, tokens, configuration)
.fold(
onSuccess = { null },
onFailure = { throw it }
onFailure = { throw it },
)
}
}
Expand All @@ -266,7 +268,7 @@ object Afterpay {
*/
@JvmSynthetic
fun fetchMerchantConfigurationV3(
configuration: CheckoutV3Configuration? = checkoutV3Configuration
configuration: CheckoutV3Configuration? = checkoutV3Configuration,
): Result<Configuration> {
requireNotNull(configuration) {
"`configuration` must be set via `setCheckoutV3Configuration` or passed into this function"
Expand All @@ -279,7 +281,7 @@ object Afterpay {
maximumAmount = it.maximumAmount.amount,
currency = Currency.getInstance(configuration.region.currencyCode),
locale = configuration.region.locale,
environment = configuration.environment
environment = configuration.environment,
)
}
}
Expand All @@ -291,7 +293,7 @@ object Afterpay {
@JvmStatic
@JvmOverloads
fun fetchMerchantConfigurationV3Async(
configuration: CheckoutV3Configuration? = checkoutV3Configuration
configuration: CheckoutV3Configuration? = checkoutV3Configuration,
): CompletableFuture<Configuration> {
requireNotNull(configuration) {
"`configuration` must be set via `setCheckoutV3Configuration` or passed into this function"
Expand All @@ -305,13 +307,13 @@ object Afterpay {
maximumAmount = it.maximumAmount.amount,
currency = Currency.getInstance(configuration.region.currencyCode),
locale = configuration.region.locale,
environment = configuration.environment
environment = configuration.environment,
)
}

result.fold(
onSuccess = { it },
onFailure = { throw it }
onFailure = { throw it },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ interface AfterpayCheckoutV2Handler {

fun shippingAddressDidChange(
address: ShippingAddress,
onProvideShippingOptions: (ShippingOptionsResult) -> Unit
onProvideShippingOptions: (ShippingOptionsResult) -> Unit,
)

fun shippingOptionDidChange(
shippingOption: ShippingOption,
onProvideShippingOption: (ShippingOptionUpdateResult?) -> Unit
onProvideShippingOption: (ShippingOptionUpdateResult?) -> Unit,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ data class AfterpayCheckoutV2Options(
val pickup: Boolean? = null,
val buyNow: Boolean? = null,
val shippingOptionRequired: Boolean? = null,
val enableSingleShippingOptionUpdate: Boolean? = null
val enableSingleShippingOptionUpdate: Boolean? = null,
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
parcel.readValue(Boolean::class.java.classLoader) as? Boolean
parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
)

override fun writeToParcel(parcel: Parcel, flags: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import java.util.Locale
enum class AfterpayEnvironment {
SANDBOX, PRODUCTION;

override fun toString(): String = name.toLowerCase(Locale.ROOT)
override fun toString(): String = name.lowercase(Locale.ROOT)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ enum class CancellationStatus {
enum class CancellationStatusV3 {
USER_INITIATED,
CONFIGURATION_ERROR,
REQUEST_ERROR
REQUEST_ERROR,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import kotlinx.serialization.Serializable
@Serializable
internal data class AfterpayCheckoutCompletion(
val status: Status,
val orderToken: String
val orderToken: String,
) {

@Suppress("UNUSED_PARAMETER")
@Serializable
internal enum class Status(statusString: String) {
SUCCESS("SUCCESS"),
CANCELLED("CANCELLED")
CANCELLED("CANCELLED"),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ internal sealed class AfterpayCheckoutMessage {

fun fromShippingOptionsResult(
result: ShippingOptionsResult,
meta: AfterpayCheckoutMessageMeta
meta: AfterpayCheckoutMessageMeta,
): AfterpayCheckoutMessage = when (result) {
is ShippingOptionsErrorResult -> CheckoutErrorMessage(meta, result.error.name)
is ShippingOptionsSuccessResult -> ShippingOptionsMessage(meta, result.shippingOptions)
}

fun fromShippingOptionUpdateResult(
result: ShippingOptionUpdateResult?,
meta: AfterpayCheckoutMessageMeta
meta: AfterpayCheckoutMessageMeta,
): AfterpayCheckoutMessage = when (result) {
is ShippingOptionUpdateErrorResult -> CheckoutErrorMessage(meta, result.error.name)
is ShippingOptionUpdateSuccessResult -> ShippingOptionUpdateMessage(
meta,
result.shippingOptionUpdate
result.shippingOptionUpdate,
)
null -> EmptyPayloadMessage(meta)
}
Expand All @@ -48,53 +48,53 @@ internal sealed class AfterpayCheckoutMessage {
@SerialName("onMessage")
internal data class CheckoutLogMessage(
override val meta: AfterpayCheckoutMessageMeta,
val payload: CheckoutLog
val payload: CheckoutLog,
) : AfterpayCheckoutMessage() {

@Serializable
internal data class CheckoutLog(
val severity: String,
val message: String
val message: String,
)
}

@Serializable
@SerialName("onError")
internal data class CheckoutErrorMessage(
override val meta: AfterpayCheckoutMessageMeta,
val error: String
val error: String,
) : AfterpayCheckoutMessage()

@Serializable
@SerialName("onShippingAddressChange")
internal data class ShippingAddressMessage(
override val meta: AfterpayCheckoutMessageMeta,
val payload: ShippingAddress
val payload: ShippingAddress,
) : AfterpayCheckoutMessage()

@Serializable
@SerialName("onShippingOptionChange")
internal data class ShippingOptionMessage(
override val meta: AfterpayCheckoutMessageMeta,
val payload: ShippingOption
val payload: ShippingOption,
) : AfterpayCheckoutMessage()

@Serializable
@SerialName("onShippingOptionUpdateChange")
internal data class ShippingOptionUpdateMessage(
override val meta: AfterpayCheckoutMessageMeta,
val payload: ShippingOptionUpdate?
val payload: ShippingOptionUpdate?,
) : AfterpayCheckoutMessage()

@Serializable
@SerialName("onShippingOptionsChange")
internal data class ShippingOptionsMessage(
override val meta: AfterpayCheckoutMessageMeta,
val payload: List<ShippingOption>
val payload: List<ShippingOption>,
) : AfterpayCheckoutMessage()

@Serializable
@SerialName("onEmptyPayload")
internal data class EmptyPayloadMessage(
override val meta: AfterpayCheckoutMessageMeta
override val meta: AfterpayCheckoutMessageMeta,
) : AfterpayCheckoutMessage()
Loading

0 comments on commit 1cee27c

Please sign in to comment.