基本Web Payments Request API示例

时间:2017-12-23 12:26:01

标签: javascript api web payment

我试图让基本的Web Payments Request API演示工作。据我了解,当我运行此代码时,会弹出一个弹出窗口,询问我想使用哪张信用卡:

<html>
    <head>
    </head>
    <body>
        <h1>Pay here</h1>
        <script>
            if(window.PaymentRequest){
                alert("Payment request exists!");

                const supportedPaymentMethods = [ {
                        supportedMethods: ["basic-card"]
                    }
                ];

                const paymentDetails = {
                    total: {
                        label: "Total Cost",
                        amount: {
                            currency: "GBP",
                            value: 1
                        }
                    }
                };

                const options = {};

                const paymentRequest =  new PaymentRequest(
                    supportedMethods, paymentDetails, options
                );

                paymentRequest.show();
            }
        </script>
    </body>
</html>

但没有太多事情发生。发生的是警报消息出现的情况。我只是想让基础工作起作用。我不相信此代码会向任何人汇款,因为没有提到帐户。我希望下一步。请帮忙!谢谢。

1 个答案:

答案 0 :(得分:1)

我终于找到了一个有效的演示版。它会将您的信用卡详细信息保存在浏览器中,并以易于使用的格式显示(无表单字段)。它不会将信用卡详细信息发送到支付系统,它只是准备它:

$scope.cdate = $filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss');
console.log("current time........",$scope.cdate);

                     $scope.Mydata=Data.timestamp;  //I am Getting this data from response

                        this.getDateDiff = function(cdate, Mydata) {
                        let d1 = new Date($scope.cdate);
                        let d2 = new Date($scope.Mydata);
                        let diff = Math.abs(d1.getTime() - d2.getTime());
                        let diffDate = new Date(0, 0, 0);
                            diffDate.setMilliseconds(diff);
                        let dayMills = ((60**2) * 24) * 1000;
                        let days = Math.round(diff / dayMills);

                            function formatNumberString(number) {
                                return ('0' + number).slice(-2);
                                    }
                            return  {
                                    days: formatNumberString(days),
                                    hours: formatNumberString(diffDate.getHours()),
                                    minutes: formatNumberString(diffDate.getMinutes()),
                                    seconds: formatNumberString(diffDate.getSeconds())
                                    }
                        }
                        $scope.dateDiff = this.getDateDiff($scope.cdate, $scope.Mydata);
                        console.log("days diff.........",$scope.dateDiff);

您可以复制/粘贴上面的代码并保存为HTML并从本地驱动器加载它(不需要像我想的那样从安全的https URL加载它等任何花哨的东西。)