-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
947351b
commit ab9e133
Showing
18 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
example/src/main/java/com/stripe/example/activity/CryptoActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.stripe.example.activity | ||
|
||
import android.os.Bundle | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.CircularProgressIndicator | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.google.accompanist.themeadapter.material.MdcTheme | ||
import com.stripe.android.model.PaymentMethod | ||
import com.stripe.android.model.PaymentMethodCreateParams | ||
|
||
class CryptoActivity : StripeIntentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
val isProcessing by viewModel.inProgress.observeAsState(initial = false) | ||
val status by viewModel.status.observeAsState(initial = "") | ||
|
||
CryptoPayScreen( | ||
isProcessing = isProcessing, | ||
status = status, | ||
onButtonPressed = { payWithCrypto() } | ||
) | ||
} | ||
} | ||
|
||
private fun payWithCrypto() { | ||
val params = PaymentMethodCreateParams.createCrypto() | ||
createAndConfirmPaymentIntent( | ||
country = "US", | ||
paymentMethodCreateParams = params, | ||
supportedPaymentMethods = PaymentMethod.Type.Crypto.code, | ||
currency = "USD", | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun CryptoPayScreen( | ||
isProcessing: Boolean, | ||
status: String, | ||
onButtonPressed: () -> Unit | ||
) { | ||
MdcTheme { | ||
Column(modifier = Modifier.fillMaxSize()) { | ||
Row(verticalAlignment = Alignment.CenterVertically) { | ||
Button( | ||
onClick = onButtonPressed, | ||
enabled = !isProcessing, | ||
modifier = Modifier.padding(16.dp) | ||
) { | ||
Text("Pay with Crypto") | ||
} | ||
|
||
if (isProcessing) { | ||
CircularProgressIndicator(modifier = Modifier.size(24.dp)) | ||
} | ||
} | ||
|
||
if (status.isNotBlank()) { | ||
Divider( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 16.dp), | ||
) | ||
|
||
Text( | ||
text = status, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(16.dp), | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
payments-ui-core/res/drawable-night/stripe_ic_paymentsheet_pm_crypto.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="16dp" | ||
android:height="16dp" | ||
android:viewportWidth="16" | ||
android:viewportHeight="16"> | ||
<path | ||
android:pathData="M8,16C12.418,16 16,12.418 16,8C16,3.582 12.418,0 8,0C3.582,0 0,3.582 0,8C0,12.418 3.582,16 8,16ZM6.625,3C6.28,3 6,3.28 6,3.625V4.536C5.572,4.783 5.19,5.109 4.877,5.501C4.312,6.206 4.003,7.082 4,7.986C3.997,8.89 4.3,9.768 4.86,10.478C5.176,10.879 5.564,11.212 6,11.464V12.375C6,12.72 6.28,13 6.625,13C6.97,13 7.25,12.72 7.25,12.375V11.929C7.748,12.024 8.257,12.023 8.75,11.929V12.375C8.75,12.72 9.03,13 9.375,13C9.72,13 10,12.72 10,12.375V11.464C10.451,11.204 10.845,10.859 11.162,10.45C11.433,10.101 11.265,9.615 10.869,9.419C10.474,9.223 10.001,9.399 9.687,9.709C9.495,9.899 9.271,10.056 9.023,10.173C8.532,10.404 7.978,10.462 7.45,10.337C6.921,10.213 6.451,9.913 6.115,9.487C5.779,9.061 5.597,8.534 5.599,7.992C5.601,7.449 5.786,6.923 6.125,6.5C6.464,6.076 6.937,5.78 7.466,5.659C7.995,5.538 8.549,5.6 9.038,5.835C9.285,5.953 9.508,6.111 9.698,6.302C10.011,6.614 10.482,6.794 10.879,6.601C11.276,6.408 11.447,5.923 11.179,5.572C10.859,5.153 10.459,4.801 10,4.536V3.625C10,3.28 9.72,3 9.375,3C9.03,3 8.75,3.28 8.75,3.625V4.071C8.257,3.977 7.748,3.976 7.25,4.071V3.625C7.25,3.28 6.97,3 6.625,3Z" | ||
android:fillColor="#000000" | ||
android:fillType="evenOdd"/> | ||
</vector> |
10 changes: 10 additions & 0 deletions
10
payments-ui-core/res/drawable/stripe_ic_paymentsheet_pm_crypto.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="16dp" | ||
android:height="16dp" | ||
android:viewportWidth="16" | ||
android:viewportHeight="16"> | ||
<path | ||
android:pathData="M8,16C12.418,16 16,12.418 16,8C16,3.582 12.418,0 8,0C3.582,0 0,3.582 0,8C0,12.418 3.582,16 8,16ZM6.625,3C6.28,3 6,3.28 6,3.625V4.536C5.572,4.783 5.191,5.109 4.878,5.501C4.313,6.206 4.004,7.082 4.001,7.986C3.998,8.89 4.301,9.768 4.86,10.478C5.177,10.878 5.564,11.212 6,11.464V12.375C6,12.72 6.28,13 6.625,13C6.97,13 7.25,12.72 7.25,12.375V11.929C7.748,12.024 8.257,12.023 8.75,11.929V12.375C8.75,12.72 9.03,13 9.375,13C9.72,13 10,12.72 10,12.375V11.465C10.451,11.204 10.846,10.859 11.163,10.45C11.433,10.101 11.265,9.615 10.87,9.419C10.474,9.223 10.002,9.399 9.687,9.709C9.495,9.899 9.271,10.056 9.024,10.173C8.533,10.404 7.978,10.462 7.45,10.337C6.922,10.213 6.452,9.913 6.116,9.487C5.779,9.061 5.598,8.534 5.599,7.992C5.601,7.449 5.787,6.923 6.126,6.5C6.465,6.076 6.937,5.78 7.466,5.659C7.995,5.538 8.549,5.6 9.039,5.835C9.285,5.953 9.508,6.111 9.699,6.302C10.011,6.614 10.482,6.794 10.879,6.601C11.276,6.408 11.448,5.923 11.18,5.572C10.86,5.153 10.459,4.8 10,4.535V3.625C10,3.28 9.72,3 9.375,3C9.03,3 8.75,3.28 8.75,3.625V4.071C8.257,3.977 7.748,3.976 7.25,4.071V3.625C7.25,3.28 6.97,3 6.625,3Z" | ||
android:fillColor="#EBEBEB" | ||
android:fillType="evenOdd"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
paymentsheet-example/src/androidTest/java/com/stripe/android/lpm/TestCrypto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.stripe.android.lpm | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.stripe.android.BasePlaygroundTest | ||
import com.stripe.android.model.PaymentMethod | ||
import com.stripe.android.paymentsheet.example.playground.settings.Country | ||
import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition | ||
import com.stripe.android.paymentsheet.example.playground.settings.Currency | ||
import com.stripe.android.paymentsheet.example.playground.settings.CurrencySettingsDefinition | ||
import com.stripe.android.paymentsheet.example.playground.settings.SupportedPaymentMethodsSettingsDefinition | ||
import com.stripe.android.test.core.TestParameters | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
internal class TestCrypto : BasePlaygroundTest() { | ||
private val testParameters = TestParameters.create( | ||
paymentMethodCode = "crypto", | ||
) { settings -> | ||
settings[CountrySettingsDefinition] = Country.US | ||
settings[CurrencySettingsDefinition] = Currency.USD | ||
settings[SupportedPaymentMethodsSettingsDefinition] = listOf( | ||
PaymentMethod.Type.Crypto | ||
).joinToString(",") | ||
} | ||
|
||
@Test | ||
fun testCrypto() { | ||
testDriver.confirmCustom( | ||
testParameters = testParameters, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.