Updated 13 April 2023
A Square In-App Payments SDK provides a secure, managed payments client for Android, iOS, Flutter, and React Native applications.
Use In-App Payments SDK to accept payment cards such as credit cards and digital wallets (Apple Pay, Google Pay, and Secure Remote Commerce) with a fully customized payment screen that seamlessly matches the branding of the application.
In-App Payments SDK is available for native development on iOS and Android and as an open-source plugin for Flutter and React Native.
:app
module:
1 2 3 4 5 6 7 8 9 |
android { ... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } ... } |
1 2 3 4 5 6 7 |
repositories { google() jcenter() maven { url 'https://sdk.squareup.com/public/android' } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
dependencies { implementation "com.squareup.sdk.in-app-payments:card-entry:1.5.0" implementation "com.squareup.moshi:moshi-adapters:1.9.2" implementation "com.squareup.moshi:moshi:1.9.2" implementation "com.squareup.retrofit2:converter-moshi:2.7.2" def inAppPaymentsSdkVersion = '1.5.0' implementation "com.squareup.sdk.in-app-payments:card-entry:$inAppPaymentsSdkVersion" implementation "com.squareup.sdk.in-app-payments:google-pay:$inAppPaymentsSdkVersion" kapt "com.squareup.moshi:moshi-kotlin-codegen:1.9.2" } |
1 |
-keep class sqip.** { *; } |
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application ...> <meta-data android:name="sqip.SQUARE_APPLICATION_ID" android:value="REPLACE_WITH_YOUR_SQUARE_APPLICATION_ID"/> </application> </manifest |
The application minSdkVersion must be API 21 (Lollipop, 5.0) or later.
You have a Square account enabled for payment processing. If you have not enabled payment processing on your account (or you are not sure), visit squareup.com/activate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class CheckoutActivity : BaseActivity(), CardNonceBackgroundHandler { private var squarePay: SquarePay? = null var mBinding: ActivityCheckoutBinding? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mBinding = DataBindingUtil.setContentView(this, R.layout.activity_checkout) //Find the add card button and set a click listener that starts the CardEntry activity sheetView.findViewById(R.id.addCardButton).setOnClickListener((view) -> { if (squarePay != null) { startConfig(squarePay!!) } }); fun startConfig(squarePay: SquarePay) { CardEntry.startCardEntryActivity(this, true, DEFAULT_CARD_ENTRY_REQUEST_CODE); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == DEFAULT_CARD_ENTRY_REQUEST_CODE){ CardEntry.handleActivityResult(data, object : sqip.Callback<CardEntryActivityResult> { override fun onResult(result: CardEntryActivityResult) { if (result.isSuccess()) { val cardResult: CardDetails = result.getSuccessValue() val nonce = cardResult.nonce } else if (result.isCanceled()) { MakeToast().shortToast(this@CheckoutActivity, "Canceled") } } }) } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
fun printCurlCommand(nonce: String) { val uuid = UUID.randomUUID().toString() Log.i("ExampleApplication", """Run this curl command to charge the nonce: curl --request POST https://connect.squareupsandbox.com/v2/payments \ --header "Content-Type: application/json" \ --header "Authorization: Bearer YOUR_ACCESS_TOKEN" \ --header "Accept: application/json" \ --data '{ "idempotency_key": "$uuid", "amount_money": { "amount": 100, "currency": "USD"}, "source_id": "$nonce"}'""") } |
Another mentioned URL
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
2 comments