javascript - Why is Stripe Element not working on iphone but working fine on Android and Desktop? - Stack Overflow

I'm using an integration of Stripe Element to capture payments and create charges in my phonegapp

I'm using an integration of Stripe Element to capture payments and create charges in my phonegapp app. Everything is tested and hosted on HTTPS. On desktop and Android devices I'm able to pay and enter my credit card information. On iPhone however, the input fields do not even appear. How do I fix this?

js

<!--stripe--> 
 <script>
  //stripe checkout with elements
  // Create a Stripe client.
  var app_mode = 0;//0 = dev 1=prod

  if(app_mode===0){
  var stripe = Stripe('pk_test_xxxxx');
  }else{
  var stripe = Stripe('pk_live_xxxxx');
  }
  // Create an instance of Elements.
  var elements = stripe.elements();

  // Custom styling can be passed to options when creating an Element.
  // (Note that this demo uses a wider set of styles than the guide below.)
  var style = {
    base: {
      color: '#32325d',
      fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
      fontSmoothing: 'antialiased',
      fontSize: '16px',
      '::placeholder': {
        color: '#aab7c4'
      }
    },
    invalid: {
      color: '#fa755a',
      iconColor: '#fa755a'
    }
  };

  // Create an instance of the card Element.
  var card = elements.create('card', {style: style});

  // Add an instance of the card Element into the `card-element` <div>.
  card.mount('#card-element');

  // Handle real-time validation errors from the card Element.
  card.addEventListener('change', function(event) {
    var displayError = document.getElementById('card-errors');
    if (event.error) {
      displayError.textContent = event.error.message;
    } else {
      displayError.textContent = '';
    }
  });

  // Handle form submission.
  var form = document.getElementById('book_cleaning_button');
  form.addEventListener('click', function(event) {
    event.preventDefault();

    stripe.createToken(card).then(function(result) {
      if (result.error) {
        // Inform the user if there was an error.
        var errorElement = document.getElementById('card-errors');
        errorElement.textContent = result.error.message;
      } else {
        // Send the token to your server.
        stripeTokenHandler(result.token);
      }
    });
  });

  // Submit the form with the token ID.
  function stripeTokenHandler(token) {
    // Insert the token ID into the form so it gets submitted to the server
    var form = document.getElementById('payment-form');
    var hiddenInput = document.createElement('input');
    hiddenInput.setAttribute('type', 'hidden');
    hiddenInput.setAttribute('name', 'stripeToken');
    hiddenInput.setAttribute('value', token.id);
    form.appendChild(hiddenInput);

    // Submit the form
    //form.submit();
  }
  </script>

Screenshot from iPhone :

I'm using an integration of Stripe Element to capture payments and create charges in my phonegapp app. Everything is tested and hosted on HTTPS. On desktop and Android devices I'm able to pay and enter my credit card information. On iPhone however, the input fields do not even appear. How do I fix this?

js

<!--stripe--> 
 <script>
  //stripe checkout with elements
  // Create a Stripe client.
  var app_mode = 0;//0 = dev 1=prod

  if(app_mode===0){
  var stripe = Stripe('pk_test_xxxxx');
  }else{
  var stripe = Stripe('pk_live_xxxxx');
  }
  // Create an instance of Elements.
  var elements = stripe.elements();

  // Custom styling can be passed to options when creating an Element.
  // (Note that this demo uses a wider set of styles than the guide below.)
  var style = {
    base: {
      color: '#32325d',
      fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
      fontSmoothing: 'antialiased',
      fontSize: '16px',
      '::placeholder': {
        color: '#aab7c4'
      }
    },
    invalid: {
      color: '#fa755a',
      iconColor: '#fa755a'
    }
  };

  // Create an instance of the card Element.
  var card = elements.create('card', {style: style});

  // Add an instance of the card Element into the `card-element` <div>.
  card.mount('#card-element');

  // Handle real-time validation errors from the card Element.
  card.addEventListener('change', function(event) {
    var displayError = document.getElementById('card-errors');
    if (event.error) {
      displayError.textContent = event.error.message;
    } else {
      displayError.textContent = '';
    }
  });

  // Handle form submission.
  var form = document.getElementById('book_cleaning_button');
  form.addEventListener('click', function(event) {
    event.preventDefault();

    stripe.createToken(card).then(function(result) {
      if (result.error) {
        // Inform the user if there was an error.
        var errorElement = document.getElementById('card-errors');
        errorElement.textContent = result.error.message;
      } else {
        // Send the token to your server.
        stripeTokenHandler(result.token);
      }
    });
  });

  // Submit the form with the token ID.
  function stripeTokenHandler(token) {
    // Insert the token ID into the form so it gets submitted to the server
    var form = document.getElementById('payment-form');
    var hiddenInput = document.createElement('input');
    hiddenInput.setAttribute('type', 'hidden');
    hiddenInput.setAttribute('name', 'stripeToken');
    hiddenInput.setAttribute('value', token.id);
    form.appendChild(hiddenInput);

    // Submit the form
    //form.submit();
  }
  </script>

Screenshot from iPhone :

Share Improve this question edited Feb 4, 2020 at 3:43 technophyle 9,2077 gold badges33 silver badges52 bronze badges asked Feb 4, 2020 at 3:33 GroguGrogu 2,5251 gold badge22 silver badges45 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Found the solution. I need to mention the app I created was built with PhoneGap Build. I don't have an iphone but the client I work for does. So we jumped on a conference call and had him activate remote debugging on his phone and his laptop so that I could see the errors in web inspector in Safari. You do need an iphone and a mac to at least be able to see the errors.

Here the steps I followed to fix this : - First activate remote debugging

In Safari's Web Inspector Error message was :

Unable to post message to https://js.stripe.. Recipient has origin file://

The issue is basically triggered by WebView. To fix this, I had to whitelist https access to stripe in config.xml

This is what config.xml looks like :

<plugin name="cordova-plugin-whitelist" spec="1" />
  <access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <!-- White list https access to Stripe-->
<allow-navigation href="https://*stripe./*"/>
<allow-navigation href="https://*js.stripe./*"/>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745629094a4636994.html

相关推荐

  • 2024电脑急救必备!5款亲测好用的DLL修复工具推荐

    实测分享多款适配Win10Win11的DLL修复工具&#xff0c;包含系统文件修复、注册表优化等实用功能&#xff0c;轻松解决软件报错问题 &#x1f4e3; 独家分享&#xff1a;本文所有资源下载

    17分钟前
    00
  • UIOTOS终于开源,做前端交互监控大屏甚是好用

    ‌引言&#xff1a;当“拖拉拽”撞上工业互联网‌ 2023年&#xff0c;某港口集团上演惊人一幕&#xff1a;从未写过代码的设备科工程师&#xff0c;仅用UIOTOS拖拽3小时&#xff0c

    16分钟前
    00
  • 查看IP地址Ping 命令

    Windows使用终端:按下 Win + R 键,打开“运行”对话框,输入 cmd 并按 Enter。在命令提示符中输入 ipconfig,按 Enter。系统会显示网络适配器的详细信息,包括 IPv4 地址、子网掩码和默认网关Linux使

    15分钟前
    00
  • 数据传输的基本概念

    带宽作用:带宽决定了通信链路的最大传输能力,是衡量网络性能的关键指标之一。举例:一条带宽为1 Gbps(1吉位每秒)的网络链路,理论上每秒最多可以传输1,000,000,000位数据。区别与数据传输速率:带宽是链路的最大传输能力,而数据

    12分钟前
    00
  • [VMware] Windows 7 X64 虚拟机无法安装WMware Tools解决方法

    VMware Workstation 17的Windows 7安装VMware Tools时会直接报错“Windows无法验证此驱动程序软件的发布者”&#xff0c;继续往下操作都无法安装VMware Tools.按照其它教程操

    10分钟前
    00
  • 网络层常见的协议

    IP(Internet Protocol,网际协议)专业讲解IP是网络层的核心协议,用于在不同网络之间实现数据包的传输和路由选择。它将数据分为一个个数据包,并为每个数据包添加头部信息,包括源IP地址、目的IP地址等,以确保数据包能够被正确地

    10分钟前
    00
  • Google Chrome x64 Stable 109.0.5414.120 for Windows 7

    Google Chrome x64 Stable 109.0.5414.120 for Windows 7 GoogleChromex64Stable109.0.5414.120Win7.zip项目地址:https:gitcodeop

    10分钟前
    00
  • 传输层常见协议详解

    TCP(传输控制协议)专业讲解TCP是一种面向连接的、可靠的、基于字节流的传输层通信协议。它通过三次握手建立连接,通信结束后通过四次挥手释放连接。TCP采用确认重传机制(ARQ)、数据校验、序号和流量控制等技术,确保数据的可靠传输。通俗讲解

    8分钟前
    00
  • 应用层常见的协议

    应用层协议是网络通信中用于实现各种网络服务功能的协议,位于OSI七层模型中的最顶层,直接为用户提供各种网络服务。常见的应用层协议包括HTTP、FTP、SMTP、POP3、IMAP、Telnet、SSH、DNS、DHCP、SNMP等。HTTP

    7分钟前
    00
  • Windows7任务栏程序找不到历史记录

    Windows7下&#xff0c;用户账户登录&#xff0c;任务栏右击程序名称&#xff0c;弹出的菜单中找不到历史记录检查此目录下是否有大于1M的文件&#xff0c;如果有&#xff0c;那

    6分钟前
    00
  • 计算机网络TCPIP四层模型

    网络接口层网络接口层是TCPIP模型的最底层,相当于OSI模型的物理层和数据链路层的组合,负责处理与物理网络的接口。负责将IP数据报封装成帧,并通过物理网络传输。处理与物理网络相关的硬件设备,如网卡、电缆、集线器、交换机等。提供数据帧的同

    5分钟前
    00
  • Windows SDK下载安装指南

    1. 访问下载页面 打开浏览器&#xff0c;访问Windows SDK 官方下载页面&#xff08;文章末尾所有下载地址都有整理&#xff09; 2. 选择版本 在页面上找到适合你需求的 Windows SDK

    4分钟前
    00
  • 解决python3.8版本在windows 7下无法安装的问题

    一、问题现象: 目前win7系统在学校机房中使用还是非常广泛的,由于较多的机房不安装windows补丁,会导致部分新出来的软件会安装失败.其中Python就是一个非常出名的编程软件,在中小学的机房里面也广泛见到.目前新出的3.8和之后的版

    4分钟前
    00
  • 计算机网络OSI七层模型

    物理层: 负责比特流的传输。数据链路层: 负责帧的传输。网络层: 负责数据包的传输和路由。传输层: 负责端到端的可靠传输。会话层: 负责会话的建立和管理。表示层: 负责数据的格式转换和加密。应用层: 负责提供网络服务。物理层(Physica

    3分钟前
    00
  • win7计算机用户配置文件存储路径,Windows下的用户配置文件管理(一)

    用户配置文件定义保存了用户的工作环境。根据工作环境的不同&#xff0c;Windows支持三种类型配置文件&#xff1a; 本地用户配置文件 漫游用户配置文件 强制用户配置文件 另外&#xff0c;系统还提供了默认本

    2分钟前
    00
  • windows查看密码工具

    windows查看密码工具 windows 前言 本篇介绍几款优秀的Windows上的密码抓取工具&#xff0c;每个工具都有自己的特点非常实用&#xff0c;欢迎补充。 0x01 Mimikatz 个人点评&#xf

    1分钟前
    00
  • windows 10 安装Python 3.10版

    一、查找官网 1.python官网需要VPN(建立一个临时的、安全的连接&#xff0c;是一条穿过混乱的公用网络的安全、稳定的隧道。)&#xff0c;打开VPN进行代理之后&#xff0c;打开网址&#xff1

    50秒前
    00
  • Python文件打包:一站式指南

    在Python开发中,文件打包是将项目或应用程序的文件和依赖项组合成一个可分发的单一文件或目录的过程。本文将深入探讨Python文件打包的各种方法,从简单到复杂,提供一站式的指南。将覆盖常见的打包工具和技术,以及在实际应用中的示例代码。基础

    44秒前
    00
  • 安装Windows 7时整数分区的注意事项

    Windows 7在安装时与Vista略有不同&#xff0c;Windows 7将所有的核心启动文件放在了一个大小仅为100MB的小分区当中&#xff0c;在安装Windows 7并新建分区时会有提示信息&#xff0

    28秒前
    00
  • Windows7-8-10安装部署hadoop-2.7.5(最详细的步骤,不需要cygwin)

    如果你不想在linux上搭建&#xff0c;又不想安装cygwin。那就继续往下看啦~ 目前大数据生态主要部分是Hadoop软件框架和Spark内存级计算引擎。Hadoop包含四个项目&#xff1a;Hadoop comm

    12秒前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信