å®å ¨ãªã³ã³ããã¹ãç¨: ãã®æ©è½ã¯ä¸é¨ã¾ãã¯ãã¹ã¦ã®å¯¾å¿ãã¦ãããã©ã¦ã¶ã¼ã«ããã¦ãå®å ¨ãªã³ã³ããã¹ã (HTTPS) ã§ã®ã¿å©ç¨ã§ãã¾ãã
決æ¸ãªã¯ã¨ã¹ã API ã¯ãã¦ã¼ã¶ã¼ã¨ã¦ã¼ã¶ã¼ãå¥½ãæ±ºæ¸ã·ã¹ãã ããã³ãã©ãããã©ã¼ã ããååããµã¼ãã¹ã®ä»£éãæ¯æããã販売è ã«æ¥ç¶ããããã®ãã©ã¦ã¶ã¼ãã¼ã¹ã®ä»çµã¿ãæä¾ãã¾ãããã®è¨äºã¯ã決æ¸ãªã¯ã¨ã¹ã API ã使ç¨ããããã®ã¬ã¤ãã§ããã ä¾ãææ¡ããããã¹ããã©ã¯ãã£ã¹ã示ãã¾ãã
決æ¸ã®åºæ¬çãªèãæ¹ãã®ç¯ã§ã¯ã決æ¸ãªã¯ã¨ã¹ã API ã使ç¨ãã¦æ±ºæ¸ãè¡ãããã®åºæ¬çãªæ¹æ³ã詳ãã説æãã¾ãã
ã¡ã¢: ãã®ç¯ã®ã³ã¼ãã¹ããããã¯ãFeature detect support ãã¢ããå¼ç¨ãã¦ãã¾ãã
æ°ããæ±ºæ¸ãªã¯ã¨ã¹ããªãã¸ã§ã¯ãã®ä½ææ±ºæ¸ãªã¯ã¨ã¹ãã¯ãå¸¸ã«æ°ãã PaymentRequest
ãªãã¸ã§ã¯ãã®ä½æããå§ã¾ãã¾ããããã«ã¯ PaymentRequest()
ã³ã³ã¹ãã©ã¯ã¿ã¼ã使ç¨ãã¾ããããã¯ã2 ã¤ã®å¿
é ã®å¼æ°ã1 ã¤ã®ãªãã·ã§ã³ã®å¼æ°ãåãã¾ãã
methodData
â 対å¿ãã¦ããæ±ºæ¸ææ®µãªã©ã決æ¸äºæ¥è
ã«é¢ããæ
å ±ãå«ããªãã¸ã§ã¯ããdetails
â æ¯æç·é¡ãç¨éãéæãªã©ãç¹å®ã®æ±ºæ¸ã«é¢ããæ
å ±ãæ ¼ç´ãããªãã¸ã§ã¯ããoptions
ï¼ãªãã·ã§ã³ï¼ â æ±ºæ¸ã«é¢é£ãã追å ãªãã·ã§ã³ãæ ¼ç´ãããªãã¸ã§ã¯ããä¾ ãã°ã次ã®ããã«ããã°ãæ°ãã PaymentRequest
ã¤ã³ã¹ã¿ã³ã¹ã使ãããã¨ãã§ãã¾ãã
const request = new PaymentRequest(
buildSupportedPaymentMethodData(),
buildShoppingCartDetails(),
);
ã³ã³ã¹ãã©ã¯ã¿ã¼ã®å é¨ã§å¼ã³åºããã颿°ã¯ãå¿ è¦ãªãªãã¸ã§ã¯ã弿°ãè¿ãã¾ãã
function buildSupportedPaymentMethodData() {
// Example supported payment methods:
return [{ supportedMethods: "https://example.com/pay" }];
}
function buildShoppingCartDetails() {
// Hardcoded for demo purposes:
return {
id: "order-123",
displayItems: [
{
label: "Example item",
amount: { currency: "USD", value: "1.00" },
},
],
total: {
label: "Total",
amount: { currency: "USD", value: "1.00" },
},
};
}
決æ¸ããã»ã¹ã®éå§
PaymentRequest
ãªãã¸ã§ã¯ãã使ããããPaymentRequest.show()
ã¡ã½ãããå¼ã³åºãã¦ã決æ¸ãªã¯ã¨ã¹ããéå§ããã¾ããããã¯ã決æ¸ãæåããå ´åã« PaymentResponse
ãªãã¸ã§ã¯ãã§å±¥è¡ããããããã¹ãè¿ãã¾ãã
request.show().then((paymentResponse) => {
// Here we would process the payment. For this demo, simulate immediate success:
paymentResponse.complete("success").then(() => {
// For demo purposes:
introPanel.style.display = "none";
successPanel.style.display = "block";
});
});
ãã®ãªãã¸ã§ã¯ãã¯ã顧客ã«é£çµ¡ããããã®ã¡ã¼ã«ã¢ãã¬ã¹ããååãéµéããããã®é
éå
ãªã©ã決æ¸ãå®äºããå¾ã«å¿
è¦ãªè«ççæé ãå®äºããããã«ä½¿ç¨ã§ãã詳細æ
å ±ã«éçºè
ãã¢ã¯ã»ã¹ã§ããããã«ãã¾ããä¸ã®ã³ã¼ãã§ã¯ãPaymentResponse.complete()
ã¡ã½ãããå¼ã³åºãã¦ããåããå®äºãããã¨ã示ãã¦ãã¾ãããããã使ç¨ãã¦ãã¦ã¼ã¶ã¼ã¤ã³ã¿ã¼ãã§ã¤ã¹ãæ´æ°ãã¦åå¼ãå®äºãããã¨ãã¦ã¼ã¶ã¼ã«ä¼ãããªã©ãæçµã¹ããããå®è¡ãããã¨ãã§ãã¾ãã
ä»ã«ãç¥ã£ã¦ããã¨æçãªæ±ºæ¸ãªã¯ã¨ã¹ãã¡ã½ãããããã¤ãããã¾ãã
PaymentRequest.canMakePayment()
ã¯ã決æ¸å¦çãå§ããåã« PaymentRequest
ãªãã¸ã§ã¯ããæ±ºæ¸å¯è½ãã©ãã調ã¹ãããã«ä½¿ç¨ã§ãã¾ããããã¯ãåå¨ãããã©ããã示ãè«çå¤ãå±¥è¡ããããããã¹ãè¿ãã¾ããä¾ãã°æ¬¡ã®ããã«ãªãã¾ãã
// 決æ¸ãå¯è½ãã©ããã調ã¹ãããã®ããã¼æ±ºæ¸ãªã¯ã¨ã¹ã
new PaymentRequest(buildSupportedPaymentMethodData(), {
total: { label: "Stub", amount: { currency: "USD", value: "0.01" } },
})
.canMakePayment()
.then((result) => {
if (result) {
// Real payment request
const request = new PaymentRequest(
buildSupportedPaymentMethodData(),
checkoutObject,
);
request.show().then((paymentResponse) => {
// Here we would process the payment.
paymentResponse.complete("success").then(() => {
// Finish handling payment
});
});
}
});
å¿
è¦ã§ããã°ã PaymentRequest.abort()
ã§æ±ºæ¸ãªã¯ã¨ã¹ãã䏿¢ãããã¨ãã§ãã¾ãã
決æ¸ãªã¯ã¨ã¹ã API ã«å¯¾å¿ãã¦ãããã©ããã¯ãã¦ã¼ã¶ã¼ã®ãã©ã¦ã¶ã¼ã PaymentRequest
ã«å¯¾å¿ãã¦ãããã©ãããã¤ã¾ã if (window.PaymentRequest)
ã調ã¹ããã¨ã§å¹æçã«æ¤åºãããã¨ãã§ãã¾ãã
以ä¸ã®ã¹ããããã§ã¯ã販売è
ã®ãã¼ã¸ã§ãã®ãã§ãã¯ãè¡ããtrue
ãè¿ãããå ´åããã§ãã¯ã¢ã¦ããã¿ã³ãæ´æ°ãã¦å¤ãã¦ã§ããã©ã¼ã ã®ä»£ããã« PaymentRequest
ã使ç¨ããããã«ãã¦ãã¾ãã
const checkoutButton = document.getElementById("checkout-button");
if (window.PaymentRequest) {
let request = new PaymentRequest(
buildSupportedPaymentMethodNames(),
buildShoppingCartDetails(),
);
checkoutButton.addEventListener("click", () => {
request
.show()
.then((paymentResponse) => {
// Handle successful payment
})
.catch((error) => {
// Handle cancelled or failed payment. For example, redirect to
// the legacy web form checkout:
window.location.href = "/legacy-web-form-checkout";
});
// Every click on the checkout button should use a new instance of
// PaymentRequest object, because PaymentRequest.show() can be
// called only once per instance.
request = new PaymentRequest(
buildSupportedPaymentMethodNames(),
buildShoppingCartDetails(),
);
});
}
ã¡ã¢: ã³ã¼ãã®å ¨ä½ã¯ãFeature detect support ãã¢ãåç §ãã¦ãã ããã
ã¦ã¼ã¶ã¼ã決æ¸ã§ãããã調ã¹ãã¦ã¼ã¶ã¼ã決æ¸ã§ãããã©ããã調ã¹ããã¨ã¯ãå¸¸ã«æçãªãã¨ã§ããããã§ã¯ãé¢é£ã®ãã¯ããã¯ãããã¤ãç´¹ä»ãã¾ãã
決æ¸ãã¿ã³ã®ã«ã¹ã¿ãã¤ãºã¦ã¼ã¶ã¼ã決æ¸ã§ãããã©ããã«ãã£ã¦ã決æ¸ãªã¯ã¨ã¹ããã¿ã³ãã«ã¹ã¿ãã¤ãºããã®ãæçãªãã¯ããã¯ã®1ã¤ã§ãã
以ä¸ã®ã¹ããããã¯ãã¾ãã«ãããè¡ããã®ã§ããã¦ã¼ã¶ã¼ããã°ããæ±ºæ¸ã§ããããã¾ãã¯æåã«æ±ºæ¸ã®è³æ ¼æ
å ±ã追å ããå¿
è¦ããããã«ãã£ã¦ããã§ãã¯ã¢ã¦ããã¿ã³ã®ã¿ã¤ãã«ã¯ããW3C ã«ããé«éãã§ãã¯ã¢ã¦ããã¨ãW3C ãã§ãã¯ã¢ã¦ãã®ã»ããã¢ãããã®éã§å¤åãã¾ããã©ã¡ãã®å ´åãããã§ãã¯ã¢ã¦ããã¿ã³ã¯ PaymentRequest.show()
ãå¼ã³åºãã¾ãã
const checkoutButton = document.getElementById("checkout-button");
checkoutButton.innerText = "Loadingâ¦";
if (window.PaymentRequest) {
const request = new PaymentRequest(
buildSupportedPaymentMethodNames(),
buildShoppingCartDetails(),
);
request
.canMakePayment()
.then((canMakeAFastPayment) => {
checkoutButton.textContent = canMakeAFastPayment
? "Fast Checkout with W3C"
: "Setup W3C Checkout";
})
.catch((error) => {
// The user may have turned off the querying functionality in their
// privacy settings. The website does not know whether they can make
// a fast payment, so pick a generic title.
checkoutButton.textContent = "Checkout with W3C";
});
}
ã¡ã¢: ã³ã¼ãã®å ¨ä½ã¯ãCustomizing the payment button ãã¢ãåç §ãã¦ãã ããã
ä¾¡æ ¼ããã¹ã¦å¤æããåã«èª¿ã¹ããã§ãã¯ã¢ã¦ãããã¼ãããã¹ã¦ã®è¡ã¨ãã®ä¾¡æ ¼ã夿ããåã« PaymentRequest.canMakePayment()
ã true
ãè¿ããã©ãããç¥ãå¿
è¦ãããå ´åãããã¼ãã¼ã¿ã§ PaymentRequest
ãã¤ã³ã¹ã¿ã³ã¹åã㦠.canMakePayment()
ã«äºååãåããããããã¨ãã§ãã¾ãã.canMakePayment()
ãè¤æ°åå¼ã³åºãå ´åã¯ãPaymentRequest
ã³ã³ã¹ãã©ã¯ã¿ã¼ã®æåã®å¼æ°ã«åãã¡ã½ããåã¨ãã¼ã¿ãæ ¼ç´ããå¿
è¦ããããã¨ã«çæãã¦ãã ããã
// The page has loaded. Should the page use PaymentRequest?
// If PaymentRequest fails, should the page fallback to manual
// web form checkout?
const supportedPaymentMethods = [
/* supported methods */
];
let shouldCallPaymentRequest = true;
let fallbackToLegacyOnPaymentRequestFailure = false;
new PaymentRequest(supportedPaymentMethods, {
total: { label: "Stub", amount: { currency: "USD", value: "0.01" } },
})
.canMakePayment()
.then((result) => {
shouldCallPaymentRequest = result;
})
.catch((error) => {
console.error(error);
// The user may have turned off query ability in their privacy settings.
// Let's use PaymentRequest by default and fallback to legacy
// web form based checkout.
shouldCallPaymentRequest = true;
fallbackToLegacyOnPaymentRequestFailure = true;
});
// User has clicked on the checkout button. We know
// what's in the cart, but we don't have a `Checkout` object.
function onCheckoutButtonClicked(lineItems) {
callServerToRetrieveCheckoutDetails(lineItems);
}
// The server has constructed the `Checkout` object. Now we know
// all of the prices and shipping options.
function onServerCheckoutDetailsRetrieved(checkoutObject) {
if (shouldCallPaymentRequest) {
const request = new PaymentRequest(supportedPaymentMethods, checkoutObject);
request
.show()
.then((paymentResponse) => {
// Post the results to the server and call `paymeResponse.complete()`.
})
.catch((error) => {
console.error(error);
if (fallbackToLegacyOnPaymentRequestFailure) {
window.location.href = "/legacy-web-form-checkout";
} else {
showCheckoutErrorToUser();
}
});
} else {
window.location.href = "/legacy-web-form-checkout";
}
}
ã¡ã¢: ã³ã¼ãã®å ¨ä½ã¯ãChecking user can make payments before prices are known ãã¢ãåç §ãã¦ãã ããã
ã¦ã¼ã¶ã¼ãã¢ããªãæã£ã¦ããªãå ´åã«ã決æ¸ã¢ããªãæ¨è¦ãããã®è²©å£²è
ãã¼ã¸ã§ãã¢æ±ºæ¸ãããã¤ãã¼ã® BobPay ã§æ¯æããã¨ã鏿ããã¨ãNOTSUPPORTEDERR
ä¾å¤ã§ä»å
¥ãã¦ããéã«ãPaymentRequest.show()
ãå¼ã³åºããã¨ãã¾ãããã®æ±ºæ¸ææ®µã«å¯¾å¿ãã¦ããªãå ´åã¯ãBobPay ã®ãµã¤ã³ã¢ãããã¼ã¸ã«ãªãã¤ã¬ã¯ãããã¾ãã
ã³ã¼ãã¯ä»¥ä¸ã®ãããªæãã§ãã
checkoutButton.addEventListener("click", () => {
const request = new PaymentRequest(
buildSupportedPaymentMethodData(),
buildShoppingCartDetails(),
);
request
.show()
.then((paymentResponse) => {
// Here we would process the payment. For this demo, simulate immediate success:
paymentResponse.complete("success").then(() => {
// For demo purposes:
introPanel.style.display = "none";
successPanel.style.display = "block";
});
})
.catch((error) => {
if (error.code === DOMException.NOT_SUPPORTED_ERR) {
window.location.href = "https://bobpay.xyz/#download";
} else {
// Other kinds of errors; cancelled or failed payment. For demo purposes:
introPanel.style.display = "none";
legacyPanel.style.display = "block";
}
});
});
ã¡ã¢: ã³ã¼ãã®å ¨ä½ã¯ãRecommending a payment app when user has no apps ãã¢ãåç §ãã¦ãã ããã
æ±ºæ¸æåå¾ã®è¿½å ã¦ã¼ã¶ã¼ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®è¡¨ç¤ºè²©å£²è
ã API ã«å±ããªãè¿½å æ
å ±ï¼ä¾ãã°ã追å ã®é
éæç¤ºï¼ãåéãããå ´åã販売è
ã¯ãã§ãã¯ã¢ã¦ãå¾ã«è¿½å ã® <input type="text">
ãã£ã¼ã«ããæã¤ãã¼ã¸ã示ããã¨ãã§ãã¾ãã
request
.show()
.then((paymentResponse) => {
// Process payment here.
// Close the UI:
paymentResponse.complete('success').then(() => {
// Request additional shipping address details.
const additionalDetailsContainer = document.getElementById('additional-details-container');
additionalDetailsContainer.style.display = 'block';
window.scrollTo(additionalDetailsContainer.getBoundingClientRect().x, 0);
})
.catch((error) => {
// Handle error.
});
ã¡ã¢: ã³ã¼ãã®å ¨ä½ã¯ãShow additional user interface after successful payment ãã¢ãåç §ãã¦ãã ããã
ãã©ã³ã¶ã¯ã·ã§ã³ã®äºåæ¿èªç¨éã«ãã£ã¦ã¯ï¼çµ¦æ²¹æã§ã®çæã®æ±ºæ¸ãªã©ï¼ã決æ¸ã®äºåæ¿èªãå¿
è¦ãªå ´åãããã¾ãããããè¡ãããã®æ¹æ³ã®ä¸ã¤ã¨ãã¦ã決æ¸ãã³ãã©ã¼ï¼æ±ºæ¸ãã³ãã©ã¼ APIãåç
§ï¼ãéãã¦è¡ããã¨ã§ããå·çæç¹ã§ã¯ããã®ä»æ§ã¯ã決æ¸ãã³ãã©ã¼ãæ¿èªã¹ãã¼ã¿ã¹ãè¿ãããã«ä½¿ç¨ãããã¨ãã§ãã CanMakePayment
ã¤ãã³ããå«ãã§ãã¾ãã
販売è ã®ã³ã¼ãã¯æ¬¡ã®ããã«ãªãã¾ãã
const paymentRequest = new PaymentRequest(
[{ supportedMethods: "https://example.com/preauth" }],
details,
);
// Send `CanMakePayment` event to the payment handler.
paymentRequest
.canMakePayment()
.then((res) => {
if (res) {
// The payment handler has pre-authorized a transaction
// with some static amount, e.g., USD $1.00.
} else {
// Pre-authorization failed or payment handler not installed.
}
})
.catch((err) => {
// Unexpected error occurred.
});
決æ¸ãã³ãã©ã¼ã«ã¯ã以ä¸ã®ã³ã¼ããè¨è¼ãã¾ãã
self.addEventListener("canmakepayment", (evt) => {
// Pre-authorize here.
const preAuthSuccess = true;
evt.respondWith(preAuthSuccess);
});
ãã®æ±ºæ¸ãã³ãã©ã¼ã¯ãhttps://example.com/preauth
ã®ã¹ã³ã¼ãã§ãµã¼ãã¹ã¯ã¼ã«ã¼ã®ä¸ã«å¸¸é§ãããå¿
è¦ãããã¾ãã
ã¡ã¢: ã³ã¼ãã®å ¨ä½ã¯ãPre-authorizing transactions ãã¢ãåç §ãã¦ãã ããã
é¢é£æ å ±RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4