Skip to content

Commit

Permalink
Merge pull request #234 from afterpay/feature/button
Browse files Browse the repository at this point in the history
Feature/button
  • Loading branch information
tir38 authored Jul 26, 2024
2 parents 66fe371 + 5c66a5c commit b5c2cec
Show file tree
Hide file tree
Showing 164 changed files with 3,644 additions and 3,417 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ obj/
.idea/deploymentTargetDropDown.xml
.idea/kotlinc.xml
.idea/appInsightsSettings.xml
.idea/other.xml
.idea/deploymentTargetSelector.xml

# OS-specific files
.DS_Store
Expand Down Expand Up @@ -114,5 +116,3 @@ docs/_site
### AndroidStudio Patch ###

!/gradle/wrapper/gradle-wrapper.jar
/.idea/deploymentTargetSelector.xml
/.idea/other.xml
2 changes: 0 additions & 2 deletions .idea/codeStyles/Project.xml

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

70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,76 @@ The Afterpay Android SDK makes it quick and easy to provide an excellent payment
## Documentation
Documentation for usage can be found [here][docs], including the [getting started][docs-getting-started] guide and [UI component][docs-ui] docs.

## V3 Documentation

### Launching the Checkout

Launch the Afterpay checkout v3 flow by starting the intent provided by the SDK for the given options.

The activity result returns a `CheckoutV3Data` with the information required to complete the merchant transaction, as well as the tokens required by `Afterpay.updateMerchantReferenceV3|Async`.


```kotlin
class ExampleActivity: Activity {
private companion object {
const val CHECKOUT_WITH_AFTERPAY = 1234
}

override fun onCreate(savedInstanceState: Bundle?) {
// ...

val afterpayCheckoutButton = findViewById<Button>(R.id.button_afterpay)
afterpayCheckoutButton.setOnClickListener {
val options = Afterpay.createCheckoutV3Intent(
requireContext(),
consumer = // `CheckoutV3Consumer` interface
orderTotal = OrderTotal(
total = BigDecimal.ZERO,
shipping = BigDecimal.ZERO,
tax = BigDecimal.ZERO
)
items = // Optional `List<CheckoutV3Item>`
buyNow = command.buyNow // Changes checkout button title from 'Confirm' to 'Buy Now'
)
startActivityForResult(intent, CHECKOUT_WITH_AFTERPAY)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// ...

when (requestCode to resultCode) {
CHECKOUT_WITH_AFTERPAY to AppCompatActivity.RESULT_OK -> {
val intent = checkNotNull(data) {
"Intent should always be populated by the SDK"
}
// `CheckoutV3Data` containing values required
val resultData = checkNotNull(Afterpay.parseCheckoutSuccessResponseV3(intent)) {
"Result data is always associated with a successful V3 Afterpay transaction"
}
findNavController().navigate(
nav_graph.action.to_details_v3,
bundleOf(nav_graph.args.result_data_v3 to resultData)
)
}
CHECKOUT_WITH_AFTERPAY to AppCompatActivity.RESULT_CANCELED -> {
val intent = requireNotNull(data) {
"Intent should always be populated by the SDK"
}
val pair = checkNotNull(Afterpay.parseCheckoutCancellationResponseV3(intent)) {
"A cancelled Afterpay transaction always contains a status, and optionally an `Exception`"
}
TODO("Notify user of checkout cancellation")
}
}
}
}
```

### Configuration

V3 users can retrieve the confirmation object directly from Afterpay by using `Afterpay.fetchMerchantConfigurationV3|Async()`

## Contributing

Contributions are welcome! Please read our [contributing guidelines][contributing].
Expand Down
65 changes: 0 additions & 65 deletions afterpay/build.gradle

This file was deleted.

83 changes: 83 additions & 0 deletions afterpay/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2024 Afterpay
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.vanniktech.maven.publish)
alias(libs.plugins.kotlin.serialization)
}

android {
compileSdk = libs.versions.compileSdkVersion.get().toInt()
buildToolsVersion = libs.versions.buildTools.get()

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.compileSdkVersion.get().toInt()

val VERSION_NAME: String by project
buildConfigField("String", "AfterpayLibraryVersion", "\"$VERSION_NAME\"")

consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
create("staging") {
initWith(getByName("debug"))
}
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = libs.versions.java.get()
}

namespace = "com.afterpay.android"
}

dependencies {
implementation(libs.kotlinCoroutinesAndroid)
implementation(libs.kotlinSerializationJson)
implementation(libs.kotlinCoroutinesJdk8)
implementation(libs.androidxLifecycleRuntimeKtx)

implementation(libs.androidxCoreKtx)
implementation(libs.androidxAppcompat)

testImplementation(libs.junit)
coreLibraryDesugaring(libs.androidToolsDesugarJdk)
testImplementation(libs.kotlinCoroutinesTest)
testImplementation(libs.mockK)
}

tasks.withType<Sign> {
val version = project.version.toString()
onlyIf { !version.endsWith("SNAPSHOT") }
}

signing {
useInMemoryPgpKeys(
findProperty("signingKeyId").toString(),
findProperty("signingKey").toString(),
findProperty("signingPassword").toString(),
)
}
4 changes: 4 additions & 0 deletions afterpay/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
android:name=".view.AfterpayCheckoutV2Activity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:theme="@style/AfterpayDialog" />
<activity
android:name=".view.AfterpayCheckoutV3Activity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:theme="@style/AfterpayDialog" />
<activity
android:name=".internal.AfterpayInfoActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
Expand Down
Loading

0 comments on commit b5c2cec

Please sign in to comment.