AUTHENTICATION_FAILURE axios 发票

发布于 2025-01-14 08:15:33 字数 13622 浏览 1 评论 0原文

const headers = {
  'Authorization': `Bearer ${api.oathToken.accessToken}`,
  'Content-Type': 'application/json',

}
const body = {
  subject: "No Subject",
  note: "Please pay this within 10 days!",
}
              console.log(invoiceDraft.links[1].href)
                  await axios({
                  data : body, 
                  method: "post",
                  headers: headers,
                  url: invoiceDraft.links[1].href,
                      }).then((response) => {
                        console.log(response.data)
                      }).catch((err)=> {
                        console.log(err.response.data.details)
                        interaction.channel.send(err.toString().slice(0, 1900))
                      })

我这里有这个代码来发送创建的发票 但由于某种原因,它返回此

错误:请求失败,状态代码 422

这是来自 Axios 和 Paypal 发票的 UNPROCESSABLE_ENTITY 错误

我无法弄清楚问题是什么。 我正在使用 Node JS 和 Discord 整数来执行此操作。

Error: Request failed with status code 422
    at createError (C:\Users\AriesAsAkshay\OneDrive\Documents\GitHub\AspectServices\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\AriesAsAkshay\OneDrive\Documents\GitHub\AspectServices\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\AriesAsAkshay\OneDrive\Documents\GitHub\AspectServices\node_modules\axios\lib\adapters\http.js:269:11)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  config: {
    url: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
    method: 'post',
    data: '{"subject":"No Subject","note":"Please pay this within 10 days!","send_to_invoicer":true,"send_to_recipient":true,"additional_recipients":[]}',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      Authorization: '',
      'User-Agent': 'axios/0.21.4',
      'Content-Length': 141
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    }
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: null,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'api.sandbox.paypal.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'api.sandbox.paypal.com',
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular *1],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 933,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object],
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'POST /v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: application/json\r\n' +
      'Authorization: \r\n' +
      'User-Agent: axios/0.21.4\r\n' +
      'Content-Length: 141\r\n' +
      'Host: api.sandbox.paypal.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 422,
      statusMessage: 'Unprocessable Entity',
      client: [TLSSocket],
      _consuming: true,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 18,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'api.sandbox.paypal.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 141,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      authorization: [Array],
      'user-agent': [Array],
      'content-length': [Array],
      host: [Array]
    }
  },
  response: {
    status: 422,
    statusText: 'Unprocessable Entity',
    headers: {
      'content-type': 'application/json',
      'content-length': '377',
      connection: 'close',
      date: 'Wed, 16 Mar 2022 01:35:50 GMT',
      application_id: 'APP-80W284485P519543T',
      'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
      caller_acct_num: '7K54CC6QVVV78',
      'paypal-debug-id': 'b5b17b1cdd466',
      'strict-transport-security': 'max-age=31536000; includeSubDomains'
    },
    config: {
      url: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      method: 'post',
      data: '{"subject":"No Subject","note":"Please pay this within 10 days!","send_to_invoicer":true,"send_to_recipient":true,"additional_recipients":[]}',   
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      transitional: [Object]
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'POST /v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'Authorization: \r\n' +
        'User-Agent: axios/0.21.4\r\n' +
        'Content-Length: 141\r\n' +
        'Host: api.sandbox.paypal.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'api.sandbox.paypal.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: {
      name: 'UNPROCESSABLE_ENTITY',
      message: 'The requested action could not be performed, semantically incorrect, or failed business validation.',
      debug_id: 'b5b17b1cdd466',
      details: [Array],
      links: [Array]
    }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}

错误响应详细信息

[
  {
    issue: 'USER_NOT_FOUND',
    description: 'User is not associated with paypal based on invoicer email.'
  }
]
           const  sampleInvoice = (
                invoiceNumber,
                fromEmail = "[email protected]",
                toEmail = "[email protected]"
              ) => ({
                detail: {
                  invoice_number: invoiceNumber,
                  currency_code: "USD",
                  payment_term: { term_type: "NET_10" },
                  invoice_date: new Date().toISOString().split("T")[0],
                },
                invoicer: {
                  name: {
                    given_name: "John",
                    surname: "Doe",
                  },
                  email_address: fromEmail,
                  website: "https://www.aspecthosts.com/",
                },
                primary_recipients: [
                  {
                    billing_info: {
                      name: {
                        given_name: "John",
                        surname: "Doe",
                      },
                      email_address: toEmail,
                    },
                  },
                ],
                items: [
                  {
                    name: service,
                    description: "Hello!",
                    quantity: "1",
                    unit_amount: {
                      currency_code: "USD",
                      value: amount,
                    },
                    unit_of_measure: "QUANTITY",
                  },
                ],
              });
const headers = {
  'Authorization': `Bearer ${api.oathToken.accessToken}`,
  'Content-Type': 'application/json',

}
const body = {
  subject: "No Subject",
  note: "Please pay this within 10 days!",
}
              console.log(invoiceDraft.links[1].href)
                  await axios({
                  data : body, 
                  method: "post",
                  headers: headers,
                  url: invoiceDraft.links[1].href,
                      }).then((response) => {
                        console.log(response.data)
                      }).catch((err)=> {
                        console.log(err.response.data.details)
                        interaction.channel.send(err.toString().slice(0, 1900))
                      })

I have this code here to send a created invoice
But for some reason it returns this

Error: Request failed with status code 422

This is a UNPROCESSABLE_ENTITY error from Axios and Paypal Invoicing

Im not able to figure out what the issue is.
I am using Node JS and Discord integerations to do this.

Error: Request failed with status code 422
    at createError (C:\Users\AriesAsAkshay\OneDrive\Documents\GitHub\AspectServices\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\AriesAsAkshay\OneDrive\Documents\GitHub\AspectServices\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\AriesAsAkshay\OneDrive\Documents\GitHub\AspectServices\node_modules\axios\lib\adapters\http.js:269:11)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  config: {
    url: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
    method: 'post',
    data: '{"subject":"No Subject","note":"Please pay this within 10 days!","send_to_invoicer":true,"send_to_recipient":true,"additional_recipients":[]}',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      Authorization: '',
      'User-Agent': 'axios/0.21.4',
      'Content-Length': 141
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    }
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: null,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'api.sandbox.paypal.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'api.sandbox.paypal.com',
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular *1],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 933,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object],
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'POST /v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: application/json\r\n' +
      'Authorization: \r\n' +
      'User-Agent: axios/0.21.4\r\n' +
      'Content-Length: 141\r\n' +
      'Host: api.sandbox.paypal.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 422,
      statusMessage: 'Unprocessable Entity',
      client: [TLSSocket],
      _consuming: true,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 18,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'api.sandbox.paypal.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 141,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      authorization: [Array],
      'user-agent': [Array],
      'content-length': [Array],
      host: [Array]
    }
  },
  response: {
    status: 422,
    statusText: 'Unprocessable Entity',
    headers: {
      'content-type': 'application/json',
      'content-length': '377',
      connection: 'close',
      date: 'Wed, 16 Mar 2022 01:35:50 GMT',
      application_id: 'APP-80W284485P519543T',
      'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
      caller_acct_num: '7K54CC6QVVV78',
      'paypal-debug-id': 'b5b17b1cdd466',
      'strict-transport-security': 'max-age=31536000; includeSubDomains'
    },
    config: {
      url: 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      method: 'post',
      data: '{"subject":"No Subject","note":"Please pay this within 10 days!","send_to_invoicer":true,"send_to_recipient":true,"additional_recipients":[]}',   
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      transitional: [Object]
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'POST /v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'Authorization: \r\n' +
        'User-Agent: axios/0.21.4\r\n' +
        'Content-Length: 141\r\n' +
        'Host: api.sandbox.paypal.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/v2/invoicing/invoices/INV2-4PSV-VKBJ-AK8G-P5CL/send',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'api.sandbox.paypal.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: {
      name: 'UNPROCESSABLE_ENTITY',
      message: 'The requested action could not be performed, semantically incorrect, or failed business validation.',
      debug_id: 'b5b17b1cdd466',
      details: [Array],
      links: [Array]
    }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}

Error Response Details

[
  {
    issue: 'USER_NOT_FOUND',
    description: 'User is not associated with paypal based on invoicer email.'
  }
]
           const  sampleInvoice = (
                invoiceNumber,
                fromEmail = "[email protected]",
                toEmail = "[email protected]"
              ) => ({
                detail: {
                  invoice_number: invoiceNumber,
                  currency_code: "USD",
                  payment_term: { term_type: "NET_10" },
                  invoice_date: new Date().toISOString().split("T")[0],
                },
                invoicer: {
                  name: {
                    given_name: "John",
                    surname: "Doe",
                  },
                  email_address: fromEmail,
                  website: "https://www.aspecthosts.com/",
                },
                primary_recipients: [
                  {
                    billing_info: {
                      name: {
                        given_name: "John",
                        surname: "Doe",
                      },
                      email_address: toEmail,
                    },
                  },
                ],
                items: [
                  {
                    name: service,
                    description: "Hello!",
                    quantity: "1",
                    unit_amount: {
                      currency_code: "USD",
                      value: amount,
                    },
                    unit_of_measure: "QUANTITY",
                  },
                ],
              });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2025-01-21 08:15:33

发票草稿的原始创建很可能存在问题。显示完整的发票创建请求/响应正文。特别是,发票人帐户的沙箱电子邮件是什么?它是否对应于您可以登录的实际 www.sandbox.paypal.com PayPal 企业帐户?如果没有,请通过 开发人员仪表板 ->沙盒帐户。

Most likely there's a problem with the invoice draft's original creation. Show that invoice creation request/response bodies in their entirety. In particular, what is the sandbox email of the invoicer account ? Does it correspond to an actual www.sandbox.paypal.com PayPal business account that you can log into? If not, create it with the correct email via the developer dashboard -> sandbox accounts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文