Add independent PayPal hosted binding mode

This commit is contained in:
QLHazyCoder
2026-05-20 09:03:40 +08:00
parent f36e0cedb3
commit 72c578b9b4
19 changed files with 1621 additions and 60 deletions
+36 -2
View File
@@ -38,7 +38,7 @@ test('plus checkout content script can be injected repeatedly on the same page',
assert.equal(context.__MULTIPAGE_PLUS_CHECKOUT_READY__, true);
});
function createPlusCheckoutMessageHarness({ checkoutSessionId = 'cs_test_123' } = {}) {
function createPlusCheckoutMessageHarness({ checkoutSessionId = 'cs_test_123', checkoutResponse = null } = {}) {
const attrs = new Map();
let listener = null;
const fetchCalls = [];
@@ -84,7 +84,7 @@ function createPlusCheckoutMessageHarness({ checkoutSessionId = 'cs_test_123' }
return {
ok: true,
status: 200,
json: async () => ({ checkout_session_id: checkoutSessionId }),
json: async () => (checkoutResponse || { checkout_session_id: checkoutSessionId }),
};
}
throw new Error(`unexpected fetch url: ${url}`);
@@ -153,6 +153,40 @@ test('CREATE_PLUS_CHECKOUT uses ID/IDR and openai_llc merchant path for GoPay',
});
});
test('CREATE_PLUS_CHECKOUT uses hosted US/USD checkout for PayPal no-card binding', async () => {
const hostedUrl = 'https://pay.openai.com/c/pay/cs_hosted_123';
const harness = createPlusCheckoutMessageHarness({
checkoutSessionId: 'cs_hosted',
checkoutResponse: {
checkout_session_id: 'cs_hosted',
next_action: {
redirect_to_url: {
url: hostedUrl,
},
},
},
});
const result = await harness.send({
type: 'CREATE_PLUS_CHECKOUT',
source: 'test',
payload: { paymentMethod: 'paypal-hosted' },
});
assert.equal(result.ok, true);
assert.equal(result.checkoutUrl, 'https://chatgpt.com/checkout/openai_llc/cs_hosted');
assert.equal(result.hostedCheckoutUrl, hostedUrl);
assert.equal(result.preferredCheckoutUrl, hostedUrl);
assert.equal(result.country, 'US');
assert.equal(result.currency, 'USD');
const checkoutCall = harness.fetchCalls.find((call) => call.url === 'https://chatgpt.com/backend-api/payments/checkout');
assert.ok(checkoutCall);
const payload = JSON.parse(checkoutCall.options.body);
assert.equal(payload.checkout_ui_mode, 'hosted');
assert.deepEqual(payload.billing_details, { country: 'US', currency: 'USD' });
});
function extractFunction(name) {
const plainStart = source.indexOf(`function ${name}(`);
const asyncStart = source.indexOf(`async function ${name}(`);