fill-paypal-payment.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // background/steps/fill-paypal-payment.js — Step 9: Fill PayPal checkout payment form
  2. (function attachBackgroundStep14(root, factory) {
  3. root.MultiPageBackgroundStep14 = factory();
  4. })(typeof self !== 'undefined' ? self : globalThis, function createBackgroundStep14Module() {
  5. function createStep14Executor(deps = {}) {
  6. const {
  7. addLog,
  8. fetchCheckoutAddress,
  9. generateRandomEmail,
  10. sendToContentScriptResilient,
  11. } = deps;
  12. async function executeStep14(state = {}) {
  13. await addLog('步骤 9:正在准备 PayPal 付款信息...');
  14. const card = generateLuhnVisaTestCard();
  15. await addLog(`已生成测试 VISA 卡号(Luhn):尾号 ${card.Credit_Card_Number.slice(-4)} 有效期 ${card.Expires}`);
  16. // Fetch random US address
  17. const addr = await fetchCheckoutAddress();
  18. await addLog(`已获取地址: ${addr.street}, ${addr.city}, ${addr.state} ${addr.zip}`);
  19. // Generate random credentials
  20. const email = generateRandomEmail();
  21. const password = generateRandomPassword();
  22. // The checkout-paypal content script is still active after step 8's PayPal login.
  23. // After PayPal login form submission, the tab has redirected to the checkout page.
  24. await addLog('正在向 PayPal 页面发送填表指令...');
  25. await sendToContentScriptResilient('checkout-paypal', {
  26. type: 'EXECUTE_STEP',
  27. step: 9,
  28. source: 'background',
  29. payload: {
  30. card,
  31. address: addr,
  32. email,
  33. password,
  34. phone: normalizePaypalPhoneForInput(state.paypalPhone || state.checkoutPhone || '+15822201173'),
  35. paypalPhone: state.paypalPhone || state.checkoutPhone || '+15822201173',
  36. paypalSmsApiUrl: state.paypalSmsApiUrl || 'http://a.62-us.com/api/get_sms?key=a5d3262e05efaba982aba7cfae20b8bc',
  37. },
  38. });
  39. }
  40. return { executeStep14 };
  41. }
  42. function generateRandomPassword() {
  43. const L = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  44. const D = '0123456789';
  45. const S = '!@#$%^';
  46. const A = L + D + S;
  47. let p = L[Math.floor(Math.random() * 26)]
  48. + L[26 + Math.floor(Math.random() * 26)]
  49. + D[Math.floor(Math.random() * 10)]
  50. + S[Math.floor(Math.random() * 6)];
  51. for (let i = 4; i < 14; i++) p += A[Math.floor(Math.random() * A.length)];
  52. return p.split('').sort(() => Math.random() - 0.5).join('');
  53. }
  54. function normalizePaypalPhoneForInput(value = '') {
  55. const raw = String(value || '').trim();
  56. const digits = raw.replace(/\D+/g, '');
  57. if (digits.length === 11 && digits.startsWith('1')) {
  58. return digits.slice(1);
  59. }
  60. return digits || raw;
  61. }
  62. function generateLuhnVisaTestCard() {
  63. return {
  64. Credit_Card_Type: 'Visa',
  65. Credit_Card_Number: generateVisaLuhnCardNumber(),
  66. Expires: generateFutureExpiry(),
  67. CVV2: generateNumericString(3),
  68. };
  69. }
  70. function generateVisaLuhnCardNumber() {
  71. const body = `4${generateNumericString(14)}`;
  72. return `${body}${computeLuhnCheckDigit(body)}`;
  73. }
  74. function computeLuhnCheckDigit(body) {
  75. const sumWithZero = luhnSum(`${body}0`);
  76. return String((10 - (sumWithZero % 10)) % 10);
  77. }
  78. function luhnSum(value) {
  79. let sum = 0;
  80. let shouldDouble = false;
  81. for (let index = String(value).length - 1; index >= 0; index -= 1) {
  82. let digit = Number(String(value)[index]);
  83. if (!Number.isFinite(digit)) digit = 0;
  84. if (shouldDouble) {
  85. digit *= 2;
  86. if (digit > 9) digit -= 9;
  87. }
  88. sum += digit;
  89. shouldDouble = !shouldDouble;
  90. }
  91. return sum;
  92. }
  93. function generateFutureExpiry() {
  94. const now = new Date();
  95. const month = String(Math.floor(Math.random() * 12) + 1).padStart(2, '0');
  96. const year = String((now.getFullYear() + 3 + Math.floor(Math.random() * 4)) % 100).padStart(2, '0');
  97. return `${month}/${year}`;
  98. }
  99. function generateNumericString(length) {
  100. let value = '';
  101. for (let index = 0; index < length; index += 1) {
  102. value += String(Math.floor(Math.random() * 10));
  103. }
  104. return value;
  105. }
  106. return { createStep14Executor };
  107. });