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.

```javascript
    //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
                Z29pbmcgb3V0IHlvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9h
                ZCwgYW5kIGlmIHlvdSBkb24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXi
                gJlzIG5vIGtub3dpbmcgd2hlcmUgeW91IG1pZ2h0IGJlIHN3ZXB0IG9m
                ZiB0by4",
            "protected": "eyJhbGciOiJFUzUxMiIsImtpZCI6ImJpbGJvLmJhZ2dpbn
                NAaG9iYml0b24uZXhhbXBsZSJ9",
            "signature": "AE_R_YZCChjn4791jSQCrdPZCNYqHXCTZH0-JZGYNlaAjP
                2kqaluUIIUnC9qvbu9Plon7KRTzoNEuT4Va2cmL1eJAQy3mtPBu_u_sD
                DyYjnAMDxXPn7XrT0lw-kvAD890jl8e2puQens_IEKBpHABlsbEPX6sF
                Y8OcGDqoRuBomu9xQ2"
        },
        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
                        break;
                    
                    case "https://bitcoin.org/":
                        //Process Bitcoin response
                        break;
                };
            });
```
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.

```javascript
navigator.payments.getShippingAddress().then(
            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
                navigator.payments.closeDialogue();

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

---
Reply to this email directly or view it on GitHub:
https://github.com/WICG/paymentrequest/issues/42
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