H5 invoking native IOS store payment

Reference documents: http://www.html5plus.org/doc/zh_cn/payment.html

<Template> 
  <div ID = "App"> 
    <H3 = @ the Click "Pay ( 'com.diandaow.cs.cny6')"> </ H3> 
  </ div> 
</ Template> 

<Script> 
    Export default { 
      Data () { 
        return { 
           IAP: {}, 
           IDS: [ "com.diandaow.cs.cny6"], // IAP project 
        } 
      }, 
     Created () { 
         document.addEventListener ( "plusready", function () {
             / / console.log ( "all plus api should be invoked after this incident, there would be undefined IS PLUS." 
         }); 
         the Document.addEventListener("plusready",this.plusReady (), to false ); 
     }, 
     Methods: { 
      plusReady () { 
      the let _this = the this ;
       // Get payment channel 
      plus.payment.getChannels (
         function (channels) {
           for ( var I in channels) {
             var Channel = channels [I];
             // for identifying the payment channel: "alipay" - indicates Alipay; "wxpay" - indicates that the micro channel payment; "appleiap" - indicates the payment within Apple application; "qhpay" - indicates 360 polymerization payment (only 360 hand-assisted support at a flow environments). 
            IF (channel.id === "appleiap" ) { 
              _this.iap = Channel;
              _this.requestOrder (); 
            } 
          } 
        }, 
        function (E) { 
          the console.log ( "Get Failed payment channel:" + e.message); 
        } 
      ); 
    }, 
    requestOrder () { 
      the let _this = the this ; 
      plus.nativeUI. showWaiting ( "payment environment detecting ..." ); 
      _this.iap.requestOrder (_this.ids, function (E) { 
          plus.nativeUI.closeWaiting (); 
          the console.log ( "Success requestOrder:" + the JSON.stringify (E )); 
        }, function (E) { 
          the console.log ("requestOrder failed:" + the JSON.stringify (E)); 
          plus.nativeUI.closeWaiting (); 
          plus.nativeUI.confirm ( "error message:" + the JSON.stringify (E),
             function (E) {
               IF (E. == 0 index ) { 
                _this.requestOrder (); 
              } the else {
                 // Back (); 
              } 
            },
             "re-request payment" [ "OK", "cancel" ] 
          ); 
        } 
      ); 
    } 
    // paid 
    pay (ID) { 
      the let _this = the this ;
      plus.nativeUI.showWaiting("", {style: "black",background: "rgba(0,0,0,0)"});
      plus.payment.request(_this.iap,{ productid: id },function(result) {
        plus.nativeUI.closeWaiting();
          _this.fetchPayStatus(result);
        },
        function(e) {
          console.log("错误信息",e)
          plus.nativeUI.closeWaiting();
          plus.nativeUI.alert(
            "错误信息:" + e.message,
            null,
            "支付失败:" + e.code
          );
        }
      );
    },
    fetchPayStatus(result) {
      // let ordercode = window.location.href.split("ordercode=")[1];
      // console.log("ordercode", ordercode);
      axios({
        method: "post",
        url: "https://pay.52dd.cn/PayApple/applepayAction",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Accept: "application/json, text/plain, */*"
        },
        data: `transactionId=${result.transactionIdentifier}&receipt=${result.transactionReceipt}&ordercode=${ordercode}`,
      })
      // .then(res => {
      //   if(res.data.code === 1){
      //     window.location.href = `${window.location.origin}/bzjp/detail.html?ordercode=${ordercode}`;
      //   }
      // });
    },
  }
}
</script>

 

Guess you like

Origin www.cnblogs.com/tlfe/p/11224625.html