पाठ 23 / 30
Payment API
आधुनिक payment methods के साथ Payment Request API से भुगतान लें, और उसकी browser सीमाएँ जानें।
Payment Processing
Payment Request API browsers को मानक payment sheet देता है। पुराना basic-card method हटा दिया गया है; payment handler या Google Pay, Apple Pay, Stripe जैसे provider उपयोग करें और server पर पुष्टि करें।
User से payment request करें
समर्थित method के साथ PaymentRequest बनाएँ, फिर complete करने से पहले अपने server पर verify और charge करें।
// Use a real payment method identifier, e.g. Google Pay
const methods = [{
supportedMethods: 'https://google.com/pay',
data: { /* merchant config from your provider */ }
}];
const details = { total: { label: 'Total', amount: { currency: 'USD', value: '9.99' } } };
if ('PaymentRequest' in window) {
const pr = new PaymentRequest(methods, details);
const response = await pr.show();
// send response.details to your server to verify and charge
await response.complete('success');
}
Output:
Secure payment collection via system-integrated payment interface.