W3C home > Mailing lists > Public > public-payments-wg@w3.org > December 2015

[paymentrequest] Use navigator.payments rather than creating a new object instance (#42)

From: Adrian Hope-Bailie <notifications@github.com>
Date: Mon, 21 Dec 2015 02:14:25 -0800
To: WICG/paymentrequest <paymentrequest@noreply.github.com>
Message-ID: <WICG/paymentrequest/issues/42@github.com>
@dlongley has provided some well thought out analysis of the API shape here: https://github.com/w3c/webpayments/issues/41#issuecomment-165487997

Based on this I would suggest changing the API to work more like the new `fetch()` API, although I'd recommend namespaces the functions under `navigator.payments`.

This is related to #41 in that it also proposes a different method signature.

    //Processing instructions for the payment mediator
    var myOptions = {
        validateRequest: true,
        requestSignature: { //Example from https://tools.ietf.org/html/rfc7520#section-4.3.3
            "payload": "SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywg
            "protected": "eyJhbGciOiJFUzUxMiIsImtpZCI6ImJpbGJvLmJhZ2dpbn
            "signature": "AE_R_YZCChjn4791jSQCrdPZCNYqHXCTZH0-JZGYNlaAjP
        encryptResponse: {
            responseEncryptionAlgorithm: "AES-CBC",
            publicKey: 'https://merchant.com/keys/12'

    //Payment request data that is passed to the payment app
    // This is an array of request variations indexed by
    // payment method identifiers
    var myRequest = [
            methods: ["https://paypal.com/"],
            details: {}, //Details of the offer
            data: {}, //Payment method specific data
            methods: ["https://bitcoin.org/"],
            details: {}, //Details of the offer
            data: {}, //Payment method specific data

    //This API shape still supports events if required
    navigator.payments.addEventListener("optionsChange", function (changeEvent) {
        if(changeEvent.optionGroup == "shipping")
            // Process shipping options change and update amounts

    //Request a payment
    navigator.payments.requestPayment(myRequest, myoptions)
            .then(function(response) {
                switch (response.method)
                    case "https://paypal.com/":
                        //Process PayPal response
                    case "https://bitcoin.org/":
                        //Process Bitcoin response
As I have suggested in https://github.com/w3c/webpayments/issues/41 you could add a `getShippingAddress()` method that could, in the long term, be a shortcut to a generic credentials request.

            function(address) {
                if (!address)
                //We'll have to get the address through the website UI
                // so close the dialogue that's currently waiting for us to
                // submit another request

                //Build request based on supplied address
                // i.e. with appropriate shipping options

Reply to this email directly or view it on GitHub:
Received on Monday, 21 December 2015 10:14:56 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:43:12 UTC