2016-06-16 2 views
0

https://www.youtube.com/watch?v=yelPlCVZLEEのようにPayment request APIの例を実行しようとしています。彼らが説明するよう 私は、プロセスを踏襲していると私はまた、次のコードを実行した:PaymentRequest APIが定義されていません

function go() { 
    console.log('Pay'); 
    var request = new PaymentRequest([{ 
      supportedMethods:['urn:payment:visa','urn:payment:mc','urn:payment:amex'] 
     }], 
     { 
      total: { 
      label: "Total due", 
      amount: { currencyCode: "USD", value: "60.00" }, // US$60.00 
     } 
    } 
    ); 

request.show() 
    .then(function(response) { 
    // process transaction response here 
    return response.complete(true); 
    }) 
    .then(function() { 
    alert("Buy!"); 
    }) 
    .catch(function(e) { 
    alert(e.name); 
    }); 
} 

を、私は次のエラーを取得:キャッチされないにReferenceError:PaymentRequestが定義されていませんが。

テストを実行した場合: http://github.adrianba.net/paymentrequest-demo/tests/payment-tests.html それは定義されています。 私は間違っていますか?

<script src="../lib/paymentrequest.js"></script> 

PaymentRequestの独自の実装を定義しています:

答えて

1

あなたは、http://github.adrianba.net/paymentrequest-demo/tests/payment-tests.htmlをリンクサイトは、ファイルを引き込む、

function PaymentRequest(methodData,details,options) { 
    // Constructor code 
    if(!Array.isArray(methodData) || methodData.length===0) throw new TypeError("methodData must be a non-empty sequence of PaymentMethodData"); 
    methodData.forEach(d => { 
    ... 

http://github.adrianba.net/paymentrequest-demo/lib/paymentrequest.js

ChromeでPaymentRequestを取得するにchrome:// flags /#enable-experimental-web-platform-featuresで有効にする必要があります

+0

ありがとうございました。私はそれをやったが、今は、https://www.w3.org/TR/payment-request/の手順を踏んで、APIを呼び出すことで働いた。 –

+0

ありがとう!私は '#web-payments'フラグを有効にしなければならないと思っていましたが、そうではありません!乾杯:) –

-1

ご回答いただきありがとうございます。私はそれをしなかったし、それが働いていたが、今、https://www.w3.org/TR/payment-request/の手順に従い、実行してAPIを呼び出した後:

var supportedMethods=["visa","mastercard"]; 

var details = { 
    "items": [ 
{ 
    "id": "basket", 
    "label": "Sub-total", 
    "amount": { "currencyCode": "GBP", "value" : "55.00" }, // US$55.00 
}, 
{ 
    "id": "tax", 
    "label": "Sales Tax", 
    "amount": { "currencyCode": "GBP", "value" : "5.00" }, // US$5.00 
}, 
{ 
    "id": "total", 
    "label": "Total due", 
    "amount": { "currencyCode": "GBP", "value" : "60.00" }, // US$60.00 
} 
    ] 
}; 

var options = { 
    requestShipping: true 
}; 


//Constructing Payment Request 
var payment = new PaymentRequest(supportedMethods, details, options); 
payment.addEventListener("shippingaddresschange", function (changeEvent) { 
// Process shipping address change 
console.log("Constructing"); 
}); 

payment.show().then(function(paymentResponse) { 
    // Process paymentResponse 
    // paymentResponse.methodName contains the selected payment method 
    // paymentResponse.details contains a payment method specific response 
    paymentResponse.complete(true); 
    }).catch(function(err) { 
     console.error("Uh oh, something bad happened", err.message); 
    }); 

を私はキャンセル要求を取得します。私は自分のローカルマシンで作業しています。それは問題ですか?それを動作させるためのhttpsプロトコルを実装する必要がありますか?私はラップトップでテストしていますが、私の電話ではテストしていません。 ありがとうございました

関連する問題