| 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, maximum-scal
e=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">Free Shipping Test</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 if (addr) { |
| 26 dict.regionCode = addr.regionCode; |
| 27 dict.administrativeArea = addr.administrativeArea; |
| 28 dict.locality = addr.locality; |
| 29 dict.dependentLocality = addr.dependentLocality; |
| 30 dict.addressLine = addr.addressLine; |
| 31 dict.postalCode = addr.postalCode; |
| 32 dict.sortingCode = addr.sortingCode; |
| 33 dict.languageCode = addr.languageCode; |
| 34 dict.organization = addr.organization; |
| 35 dict.recipient = addr.recipient; |
| 36 } |
| 37 return dict; |
| 38 } |
| 39 function buy() { |
| 40 try { |
| 41 var request = new PaymentRequest(['visa'], { |
| 42 'items' : [ { |
| 43 'id' : 'total', |
| 44 'label' : 'Total', |
| 45 'amount' : {'currencyCode' : 'USD', 'value' : '5.00'} |
| 46 } ], |
| 47 'shippingOptions' : [ { |
| 48 'id' : 'freeShippingOption', |
| 49 'label' : 'Free global shipping', |
| 50 'amount' : {'currencyCode' : 'USD', 'value' : '0'} |
| 51 } ] |
| 52 }, { |
| 53 'requestShipping' : true |
| 54 }); |
| 55 request.show() |
| 56 .then(function(resp) { |
| 57 resp.complete(true) |
| 58 .then(function() { |
| 59 print(request.shippingOption + '<br>' + |
| 60 JSON.stringify(toDictionary(request.shippingAddress), |
| 61 undefined, 2) + |
| 62 '<br>' + resp.methodName + '<br>' + |
| 63 JSON.stringify(resp.details, undefined, 2)); |
| 64 }) |
| 65 .catch(function(error) { print(error.message); }); |
| 66 }) |
| 67 .catch(function(error) { print(error.message); }); |
| 68 } catch (error) { |
| 69 print(error.message); |
| 70 } |
| 71 } |
| 72 </script> |
| 73 </body> |
| 74 </html> |
| OLD | NEW |