-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(android): move to kotlin, change theme
- Loading branch information
1 parent
1665855
commit 5ede478
Showing
3 changed files
with
88 additions
and
87 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 was deleted.
Oops, something went wrong.
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,81 @@ | ||
/** | ||
* This file was auto-generated by the Titanium Module SDK helper for Android | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2018 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
* | ||
*/ | ||
package ti.stripe | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import com.stripe.android.PaymentConfiguration | ||
import org.appcelerator.kroll.KrollDict | ||
import org.appcelerator.kroll.KrollFunction | ||
import org.appcelerator.kroll.KrollModule | ||
import org.appcelerator.kroll.annotations.Kroll.method | ||
import org.appcelerator.kroll.annotations.Kroll.module | ||
import org.appcelerator.kroll.common.Log | ||
import org.appcelerator.titanium.TiApplication | ||
import org.appcelerator.titanium.util.TiActivityResultHandler | ||
import org.appcelerator.titanium.util.TiActivitySupport | ||
|
||
@module(name = "TitaniumStripe", id = "ti.stripe") | ||
class TitaniumStripeModule : KrollModule(), TiActivityResultHandler { | ||
|
||
private var callback: KrollFunction? = null | ||
|
||
@method | ||
fun initialize(params: KrollDict) { | ||
val publishableKey = params.getString("publishableKey") | ||
PaymentConfiguration.init(TiApplication.getAppRootOrCurrentActivity(), publishableKey) | ||
} | ||
|
||
@method | ||
fun showPaymentSheet(params: KrollDict) { | ||
callback = params["callback"] as KrollFunction? | ||
|
||
val merchantDisplayName = params.getString("merchantDisplayName") | ||
val customerId = params.getString("customerId") | ||
val customerEphemeralKeySecret = params.getString("customerEphemeralKeySecret") | ||
val paymentIntentClientSecret = params.getString("paymentIntentClientSecret") | ||
|
||
if (callback == null || merchantDisplayName == null || customerId == null || customerEphemeralKeySecret == null || paymentIntentClientSecret == null) { | ||
Log.e( | ||
"TiStripe", | ||
"Missing required parameters: callback, customerId, customerEphemeralKeySecret or paymentIntentClientSecret" | ||
) | ||
return | ||
} | ||
params.remove("callback") | ||
val intent = Intent(TiApplication.getAppCurrentActivity(), TiStripeHostActivity::class.java) | ||
intent.putExtra("params", params) | ||
val support = TiApplication.getInstance().currentActivity as TiActivitySupport | ||
support.launchActivityForResult(intent, support.uniqueResultCode, this) | ||
} | ||
|
||
override fun onResult(activity: Activity, i: Int, i1: Int, intent: Intent) { | ||
val success = intent.getBooleanExtra("success", false) | ||
val cancel = intent.getBooleanExtra("cancel", false) | ||
val error = intent.getStringExtra("error") | ||
|
||
val event = KrollDict() | ||
|
||
event["success"] = success | ||
event["cancel"] = cancel | ||
event["error"] = error | ||
|
||
callback!!.callAsync(getKrollObject(), event) | ||
} | ||
|
||
override fun onError(activity: Activity, i: Int, e: Exception) { | ||
val event = KrollDict() | ||
|
||
event["success"] = false | ||
event["cancel"] = false | ||
event["error"] = e.message | ||
|
||
callback!!.callAsync(getKrollObject(), event) | ||
} | ||
} |