-
-
Save jmont96/f0337629009e20a6d658fbab67eddbfc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function onSuccess(args: [args: string | { | |
paymentId: string; | |
hash?: string | undefined; | |
}]){ | |
window.location.href = | |
`intent://callback?status=success&payment_id=${args.paymentId}#Intent;scheme=coinflow_demo;package=com.example.coinflow_demo;end;`} | |
} | |
// IFRAME on your website checkout page | |
<iframe | |
… other props | |
src={‘url for coinflow checkout’} | |
onLoad={() => { | |
window.addEventListener(‘message’, event => { | |
if (event.data === ‘success’) onSuccess() | |
}); | |
}} | |
/> | |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<!-- No WebView needed anymore --> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.coinflow_demo"> | |
<!-- Permission to access the internet --> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" | |
android:usesCleartextTraffic="true" | |
> | |
<activity | |
android:name=".MainActivity" | |
android:exported="true"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
<intent-filter> | |
<action android:name="android.intent.action.VIEW" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
<category android:name="android.intent.category.BROWSABLE" /> | |
<data android:scheme="coinflow_demo" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains hidden or 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
package com.example.coinflow_demo | |
import android.content.Intent | |
import android.net.Uri | |
import android.os.Bundle | |
import android.widget.Toast | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.browser.customtabs.CustomTabsIntent | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// Handle normal app launch | |
if (Intent.ACTION_MAIN == intent.action) { | |
launchCustomTab("url here") | |
} | |
// Handle any deep links that launched the app | |
handleIntent(intent) | |
} | |
override fun onNewIntent(intent: Intent) { | |
super.onNewIntent(intent) | |
handleIntent(intent) | |
} | |
private fun handleIntent(intent: Intent) { | |
val appLinkAction = intent.action | |
val appLinkData: Uri? = intent.data | |
if (Intent.ACTION_VIEW == appLinkAction && appLinkData != null) { | |
val scheme = appLinkData.scheme | |
val host = appLinkData.host | |
if (scheme == "coinflow_demo" && host == "callback") { | |
val status = appLinkData.getQueryParameter("status") | |
val paymentId = appLinkData.getQueryParameter("payment_id") | |
Toast.makeText(this, paymentId, Toast.LENGTH_LONG).show() | |
if (status == "success") { | |
handleSuccessCallback() | |
} | |
} | |
} | |
} | |
private fun handleSuccessCallback() { | |
// Handle success event here | |
Toast.makeText(this, "Transaction successful!", Toast.LENGTH_LONG).show() | |
// Update UI, navigate to success screen, etc. | |
} | |
private fun launchCustomTab(url: String) { | |
val customTabsIntent = CustomTabsIntent.Builder() | |
.setShowTitle(true) | |
.build() | |
customTabsIntent.launchUrl(this, Uri.parse(url)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment