Really basic demo of using web payments

Tuesday, Sep 19, 2017 1 minute read Tags: No tags for this post
Hey, thanks for the interest in this post, but just letting you know that it is over 3 years old, so the content in here may not be accurate.

Click the button to simulate starting a payment flow. Don’t worry, I’m not going to actually try and submit a payment, you can see the code below 😉.

    Source

    document.getElementsByTagName("button")[0].addEventListener("click",e=>{const t={supportedMethods:["basic-card"],data:{supportedNetworks:["visa","mastercard","amex"],supportedTypes:["credit","debit"]}},n={total:{label:"You owe me",amount:{currency:"AUD",value:42}}},s={requestPayerName:!0,requestPayerPhone:!0,requestPayerEmail:!0},o=new PaymentRequest([t],n,s);o.show().then(e=>{let t=e.details;t.cardNumber="XXXX-XXXX-XXXX-"+t.cardNumber.substr(12),t.cardSecurityCode="***";const n=document.getElementsByTagName("ul")[0];n.innerHTML="",Object.keys(t).forEach(e=>{const s=document.createElement("li");s.innerHTML=`${e}: ${JSON.stringify(t[e])}`,n.appendChild(s)}),e.complete("success")}).catch(e=>{console.error(e),e.complete("error")})},!1)