简体   繁体   English

在 Cordova 中使用 Stripe Checkout

[英]Using Stripe Checkout in Cordova

I am able to get the Stripe Checkout to work in my Ionic/Cordova app.我可以让Stripe Checkout在我的 Ionic/Cordova 应用程序中工作。 It shows an iFrame where allow user to enter their Stripe login info / credit card info to finish the payment process.它显示了一个 iFrame,允许用户输入他们的 Stripe 登录信息/信用卡信息以完成付款过程。

However there is one user case that I can't support correctly - When user clicks the Terms | Privacy但是,我无法正确支持一种用户案例 - 当用户单击Terms | Privacy Terms | Privacy links from the Stripe Checkout iFrame, the link is opened with the Cordova Webview, which destroys my app since the Cordova left my app and went to the Stripe's Terms | Privacy来自 Stripe Checkout iFrame 的Terms | Privacy链接,该链接是使用 Cordova Webview 打开的,这会破坏我的应用程序,因为 Cordova 离开了我的应用程序并转到了 Stripe 的Terms | Privacy Terms | Privacy web page. Terms | Privacy网页。 There is no back button on iOS and even though there is one on Android, the app state is totally destroyed since we've left our app. iOS 上没有后退按钮,即使 Android 上有后退按钮,应用程序状态也完全被破坏,因为我们已经离开了我们的应用程序。

I have tried using In app browser , but with no luck since I can't get URLs from Stripe to feed them to In app browser .我曾尝试使用In app browser ,但没有运气,因为我无法从 Stripe 获取 URL 以将它们提供给In app browser Also I can't manipulate the Stripe Checkout iFrame HTML because of security reasons .此外,由于安全原因,我无法操作 Stripe Checkout iFrame HTML。 So it seems that I don't have any way to either make the Terms | Privacy因此,我似乎没有任何方法可以制定Terms | Privacy Terms | Privacy open in In app browser or hide/remove the Terms | Privacy In app browser打开Terms | Privacy或隐藏/删除Terms | Privacy Terms | Privacy by changing the iFrame HTML.通过更改 iFrame HTML 来保护Terms | Privacy

Is there a solution to this question?这个问题有解决方案吗? If not, I might consider not using Stripe Checkout in my app.如果没有,我可能会考虑不在我的应用中使用 Stripe Checkout。

Thanks!谢谢!

条纹结帐 iFrame

The long and short of it is that you should not use Checkout in Cordova apps.总而言之,您不应在 Cordova 应用程序中使用Checkout While some features may work in some cases, not all of them will work correctly (as is the case with the issue you described).虽然某些功能在某些情况下可能会起作用,但并非所有功能都能正常工作(就像您描述的问题一样)。

Instead, you should design your own custom form using Stripe's Elements library to use it in your Cordova webview.相反,您应该使用 Stripe 的Elements库设计您自己的自定义表单,以便在您的 Cordova webview 中使用它。

I have successfully managed to get Stripe Checkout working in Cordova application using the mentioned InAppBrowser plugin.我已经使用提到的 InAppBrowser 插件成功地让 Stripe Checkout 在 Cordova 应用程序中工作。

You are right, you cannot feed the InAppBrowser plugin with a direct return URL, since Stripes javascript for checkout only creates a redirect.您是对的,您不能使用直接返回 URL 提供 InAppBrowser 插件,因为用于结帐的 Stripes javascript 只会创建重定向。

The way around this, is by creating your own php file, which will do the stripe redirect.解决这个问题的方法是创建您自己的 php 文件,该文件将执行条带重定向。

redirect.php would look something like this, for using sofort payment type. redirect.php 看起来像这样,用于使用软支付类型。

<?php 

// Include neccessary php Stripe sdk 
require_once('PATH TO STRIPE SDK');

$stripe_secret_key = 'YOUR STRIPE SECRET KEY'; 
$stripe_api_key = 'YOUR STRIPE API KEY'; 

// Using Stripe SDK create the Checkout 


// price in € 
$price_including = 100; 


\Stripe\Stripe::setApiKey($stripe_secret_key);

        $session = \Stripe\Checkout\Session::create([
            'payment_method_types' => ['sofort'],
            'line_items' => [[
              'price_data' => [
                'currency' => 'eur',
                'product_data' => [
                  'name' => 'YOUR PRODUCT NAME',
                ],
                'unit_amount' => $price_including*100,
              ],
              'quantity' => 1,
            ]],
            'mode' => 'payment',
            'success_url' => 'URL TO YOUR SUCCESS PAGE',
            'cancel_url' => 'URL TO YOUR ERROR PAGE',
          ]);
        
          $sid = $session->id;


// with the created Session ID call the Stripe Javascript which will do the redirect

// Include Stripe JS First
echo '<script src="https://js.stripe.com/v3/"></script>'; 

          echo '<script type="text/javascript">

                     var stripe = Stripe("'.$stripe_api_key.'");

                      function redirect() 
                      {
                        return stripe.redirectToCheckout({ sessionId: "'.$sid.'" });
                      }

                      redirect(); 
         
          </script>'; 


?>

and this is basically it, all you have left to do now is call the InAppBrowser with the URL pointing towards your created php file ;)基本上就是这样,您现在要做的就是使用指向您创建的 php 文件的 URL 调用 InAppBrowser ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM