cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="message error no-payment-request-api">
  Unfortunately, your browser does not support <span>PaymentRequest API</span>. Please refer <a href="https://www.chromestatus.com/feature/5639348045217792">this link</a> for browser support.
</div>

<div class="container">
  <div class="message warning should-not-be-iframe show">
    <p>CodePen uses iframes to run demos. And <span>PaymentRequest API</span> returns DOMException in iframes. Feel free to read more about this issue <a href="https://w3c.github.io/browser-payment-api/#paymentrequest-and-iframe-elements">here</a> and how to bypass it.</p>
    <p>But you can go to the debug page to run this <a target="_blank" href="https://s.codepen.io/prateekjadhwani/debug/QgVxMN/jVkpogRPybDA">demo in full screen by clicking here.</a>
  </div>
  <div class="button-container">
    <button class="pay1">Donane $0.0 with Any Card</button>
    <button class="pay2">Donate $0.0 with Visa or MasterCard</button>
    <button class="pay3">Ship stickers to an address and pay $0.0</button>
  </div>
</div>
            
          
!
            
              .message {
  
  padding: 20px;
  
  display: none;
  
  &.error {
    border: 1px solid #e60000;
    background: #ffb3b3;
    color: #e60000;
  }
  
  &.warning {
    border: 1px solid #b36b00;
    background: #ffcc80;
    color: #b36b00;
  }
  
  a {
    text-decoration: none;
    color: white;
    font-weight: bold;
  }
  
  span {
    border: 1px solid white;
    border-radius: 5px;
    padding: 5px;
    background: #f2f2f2;
  }
}

.show {
  display: block;
}

.hide {
  display: none;
}

.container {
  padding: 50px;
  
  .button-container {
    border: 1px solid #c2c2a3;
    padding: 50px;
    margin-top: 20px;
    
    button {
      display: block;
      width: 50%;
      height: 50px;
      margin: 20px auto;
      background:  #99ff99;
      border: 1px solid #00e600;
      color: #008000;
      cursor: pointer;
    }
  }
}
            
          
!
            
              if (!window.PaymentRequest) {
  // handle browser support
  document.querySelector('.no-payment-request-api')
    .classList.add('show');
  document.querySelector('.container')
    .classList.add('hide');
}

// type of payment methods supported
// https://w3c.github.io/browser-payment-api/#paymentmethoddata-dictionary
const supportedPaymentMethodsOne = [
  {
    supportedMethods: ['basic-card']
  }
];

const supportedPaymentMethodsTwo = [
  {
    supportedMethods: ['basic-card'],
    data: {  
      supportedNetworks: ['visa', 'mastercard'],  
      supportedTypes: ['credit'],  
    }, 
  }
];

// Amount details
// https://w3c.github.io/browser-payment-api/#paymentcurrencyamount-dictionary
const paymentDetails = {
  total: {
    label: 'Total',
    amount: {
      currency: 'USD',
      value: 0
    }
  }
};

const paymentDetailsThree = {
  total: {
    label: 'Total',
    amount: {
      currency: 'USD',
      value: 0
    }
  },
  displayItems: [
    {
      label: 'Shipping Cost',
      amount: {
        currency: 'USD',
        value: 5.75
      }
    },
    {
      label: 'Tax',
      amount: {
        currency: 'USD',
        value: 0.75
      }
    },
  ]
};

// extra options
const options = {};

const optionsThree = {
  requestShipping: true
};

const request1 = new PaymentRequest(
  supportedPaymentMethodsOne,
  paymentDetails,
  options
);

const request2 = new PaymentRequest(
  supportedPaymentMethodsTwo,
  paymentDetails,
  options
);

const request3 = new PaymentRequest(
  supportedPaymentMethodsTwo,
  paymentDetailsThree,
  optionsThree
);

document.querySelector('.pay1').addEventListener('click', () => {
  request1.show()
  .then((response) => {
    // do backend stuff
    console.log(response);
    
    //close the payment ui
    return response.complete()
  })
  .catch((e) => {
    console.log(e);
  });
});

document.querySelector('.pay2').addEventListener('click', () => {
  request2.show()
  .then((response) => {
    // do backend stuff
    console.log(response);
    
    //close the payment ui
    return response.complete()
  })
  .catch((e) => {
    console.log(e);
  });
});

document.querySelector('.pay3').addEventListener('click', () => {
  request3.show()
  .then((response) => {
    // do backend stuff
    console.log(response);
    
    //close the payment ui
    return response.complete()
  })
  .catch((e) => {
    console.log(e);
  });
});
            
          
!
999px
Loading ..................

Console