| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- // background/steps/fill-paypal-payment.js — Step 9: Fill PayPal checkout payment form
- (function attachBackgroundStep14(root, factory) {
- root.MultiPageBackgroundStep14 = factory();
- })(typeof self !== 'undefined' ? self : globalThis, function createBackgroundStep14Module() {
- function createStep14Executor(deps = {}) {
- const {
- addLog,
- fetchCheckoutAddress,
- generateRandomEmail,
- sendToContentScriptResilient,
- } = deps;
- async function executeStep14(state = {}) {
- await addLog('步骤 9:正在准备 PayPal 付款信息...');
- const card = generateLuhnVisaTestCard();
- await addLog(`已生成测试 VISA 卡号(Luhn):尾号 ${card.Credit_Card_Number.slice(-4)} 有效期 ${card.Expires}`);
- // Fetch random US address
- const addr = await fetchCheckoutAddress();
- await addLog(`已获取地址: ${addr.street}, ${addr.city}, ${addr.state} ${addr.zip}`);
- // Generate random credentials
- const email = generateRandomEmail();
- const password = generateRandomPassword();
- // The checkout-paypal content script is still active after step 8's PayPal login.
- // After PayPal login form submission, the tab has redirected to the checkout page.
- await addLog('正在向 PayPal 页面发送填表指令...');
- await sendToContentScriptResilient('checkout-paypal', {
- type: 'EXECUTE_STEP',
- step: 9,
- source: 'background',
- payload: {
- card,
- address: addr,
- email,
- password,
- phone: normalizePaypalPhoneForInput(state.paypalPhone || state.checkoutPhone || '+15822201173'),
- paypalPhone: state.paypalPhone || state.checkoutPhone || '+15822201173',
- paypalSmsApiUrl: state.paypalSmsApiUrl || 'http://a.62-us.com/api/get_sms?key=a5d3262e05efaba982aba7cfae20b8bc',
- },
- });
- }
- return { executeStep14 };
- }
- function generateRandomPassword() {
- const L = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- const D = '0123456789';
- const S = '!@#$%^';
- const A = L + D + S;
- let p = L[Math.floor(Math.random() * 26)]
- + L[26 + Math.floor(Math.random() * 26)]
- + D[Math.floor(Math.random() * 10)]
- + S[Math.floor(Math.random() * 6)];
- for (let i = 4; i < 14; i++) p += A[Math.floor(Math.random() * A.length)];
- return p.split('').sort(() => Math.random() - 0.5).join('');
- }
- function normalizePaypalPhoneForInput(value = '') {
- const raw = String(value || '').trim();
- const digits = raw.replace(/\D+/g, '');
- if (digits.length === 11 && digits.startsWith('1')) {
- return digits.slice(1);
- }
- return digits || raw;
- }
- function generateLuhnVisaTestCard() {
- return {
- Credit_Card_Type: 'Visa',
- Credit_Card_Number: generateVisaLuhnCardNumber(),
- Expires: generateFutureExpiry(),
- CVV2: generateNumericString(3),
- };
- }
- function generateVisaLuhnCardNumber() {
- const body = `4${generateNumericString(14)}`;
- return `${body}${computeLuhnCheckDigit(body)}`;
- }
- function computeLuhnCheckDigit(body) {
- const sumWithZero = luhnSum(`${body}0`);
- return String((10 - (sumWithZero % 10)) % 10);
- }
- function luhnSum(value) {
- let sum = 0;
- let shouldDouble = false;
- for (let index = String(value).length - 1; index >= 0; index -= 1) {
- let digit = Number(String(value)[index]);
- if (!Number.isFinite(digit)) digit = 0;
- if (shouldDouble) {
- digit *= 2;
- if (digit > 9) digit -= 9;
- }
- sum += digit;
- shouldDouble = !shouldDouble;
- }
- return sum;
- }
- function generateFutureExpiry() {
- const now = new Date();
- const month = String(Math.floor(Math.random() * 12) + 1).padStart(2, '0');
- const year = String((now.getFullYear() + 3 + Math.floor(Math.random() * 4)) % 100).padStart(2, '0');
- return `${month}/${year}`;
- }
- function generateNumericString(length) {
- let value = '';
- for (let index = 0; index < length; index += 1) {
- value += String(Math.floor(Math.random() * 10));
- }
- return value;
- }
- return { createStep14Executor };
- });
|