| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Free Shipping Test</title> | |
| 5 <meta charset="utf-8"> | |
| 6 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 7 <style> | |
| 8 button { | |
| 9 width: 100%; | |
| 10 height: 5em; | |
| 11 font-size: 3em; | |
| 12 } | |
| 13 </style> | |
| 14 </head> | |
| 15 <body> | |
| 16 <button onclick="buy()" id="buy">Buy</button> | |
| 17 <script> | |
| 18 function print(msg) { | |
| 19 document.open(); | |
| 20 document.write('<pre id="result" style="font-size: 2em;">' + msg + '</pre>'); | |
| 21 document.close(); | |
| 22 } | |
| 23 function toDictionary(addr) { | |
| 24 var dict = {}; | |
| 25 dict.regionCode = addr.regionCode; | |
| 26 dict.administrativeArea = addr.administrativeArea; | |
| 27 dict.locality = addr.locality; | |
| 28 dict.dependentLocality = addr.dependentLocality; | |
| 29 dict.addressLine = addr.addressLine; | |
| 30 dict.postalCode = addr.postalCode; | |
| 31 dict.sortingCode = addr.sortingCode; | |
| 32 dict.languageCode = addr.languageCode; | |
| 33 dict.organization = addr.organization; | |
| 34 dict.recipient = addr.recipient; | |
| 35 return dict; | |
| 36 } | |
| 37 function buy() { | |
| 38 try { | |
| 39 var request = new PaymentRequest(['visa'], { | |
| 40 'items' : [ { | |
| 41 'id' : 'total', | |
| 42 'label' : 'Total', | |
| 43 'amount' : {'currencyCode' : 'USD', 'value' : '5.00'} | |
| 44 } ], | |
| 45 'shippingOptions' : [ { | |
| 46 'id' : 'freeShippingOption', | |
| 47 'label' : 'Free global shipping', | |
| 48 'amount' : {'currencyCode' : 'USD', 'value' : '0'} | |
| 49 } ] | |
| 50 }, | |
| 51 {'requestShipping' : true}); | |
| 52 request.show() | |
| 53 .then(function(resp) { | |
| 54 resp.complete(true) | |
| 55 .then(function() { | |
| 56 print(request.shippingOption + '<br>' + | |
| 57 JSON.stringify(toDictionary(request.shippingAddress), | |
| 58 undefined, 2) + | |
| 59 '<br>' + resp.methodName + '<br>' + | |
| 60 JSON.stringify(resp.details, undefined, 2)); | |
| 61 }) | |
| 62 .catch(function(error) { print(error.message); }); | |
| 63 }) | |
| 64 .catch(function(error) { print(error.message); }); | |
| 65 } catch (error) { | |
| 66 print(error.message); | |
| 67 } | |
| 68 } | |
| 69 </script> | |
| 70 </body> | |
| 71 </html> | |
| OLD | NEW |