PCMARTINEAU / satoshit-nakamoto

/home/user
0 stars 0 forks source link

stripe #2

Open PCMARTINEAU opened 3 years ago

PCMARTINEAU commented 3 years ago

apply plugin: 'com.android.application'

android { ... }

dependencies { // ...

// Stripe Android SDK implementation 'com.stripe:stripe-android:16.0.1'

// AndroidX Browser library implementation 'androidx.browser:browser:1.2.0'

}<?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=".activity.ConnectWithStripeActivity">

<Button
    android:id="@+id/connect_with_stripe"
    android:text="Connect with Stripe"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    style="?attr/materialButtonOutlinedStyle"
    />

</androidx.constraintlayout.widget.ConstraintLayout> Kotlin Java ConnectWithStripeActivity.kt class ConnectWithStripeActivity : AppCompatActivity() {

private val viewBinding: ActivityConnectWithStripeViewBinding by lazy {
    ActivityConnectWithStripeViewBinding.inflate(layoutInflater)
}
private val httpClient = OkHttpClient()

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(viewBinding.root)

    viewBinding.connectWithStripe.setOnClickListener {
        val weakActivity = WeakReference<Activity>(this)
        val request = Request.Builder()
            .url(BACKEND_URL + "onboard-user")
            .post("".toRequestBody())
            .build()
        httpClient.newCall(request)
            .enqueue(object: Callback {
                override fun onFailure(call: Call, e: IOException) {
                    // Request failed
                }
                override fun onResponse(call: Call, response: Response) {
                    if (!response.isSuccessful) {
                        // Request failed
                    } else {
                        val responseData = response.body?.string()
                        val responseJson =
                            responseData?.let { JSONObject(it) } ?: JSONObject()
                        val url = responseJson.getString("url")

                        weakActivity.get()?.let {
                            val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder()
                            val customTabsIntent = builder.build()
                            customTabsIntent.launchUrl(it, Uri.parse(url))
                        }
                    }
                }
            })
    }
}

internal companion object {
    internal const val BACKEND_URL = "https://example-backend-url.com/"
}

}

PCMARTINEAU commented 3 years ago

joinhoney.com/invite/ljun9gz

PCMARTINEAU commented 3 years ago

const stripe = require('stripe')('sk_test_51HhFhzDvpc2jxCLaHYFSNaHid1vzaedLVDPoq2BncyNJy3RZPTzZIdfkMYkP88bjti76xaPDsgZFMQw90l5UK7j500vsgZN8iR'); const express = require('express'); const app = express(); app.use(express.static('.')); const ESOTERIC_U = 'http://localhost:4242'; app.post('/create-checkout-session', async (req, res) => { const session = await stripe.checkout.sessions.create({ payment_method_types: ['card'], line_items: [ { price_data: { currency: 'usd', product_data: { name: 'Stubborn Attachments', images: ['https://i.imgur.com/EHyR2nP.png'], }, unit_amount: 2000, }, quantity: 1, }, ], mode: 'payment', success_url: ${ESOTERIC_U}/success.html, }); res.json({ id: session.id }); }); app.listen(4242, () => console.log('Running on port 4242'));