【问题标题】:Invoice created via REST API causes error in PayPal backend通过 REST API 创建的发票导致 PayPal 后端出错
【发布时间】:2018-01-03 00:57:54
【问题描述】:

去年我创建了一个示例应用程序,它可以使用 REST API 创建、发送和检查 PayPal 发票。一切都像一个魅力,发票出现在我的沙盒卖家后端,它很有效。

今天我使用完全相同的未修改应用程序来创建发票草稿。回复是好的,我什至可以“发送”发票(除了没有人收到任何电子邮件的事实......),我可以得到它的状态(例如是 DRAFT 或 SENT) - 一切似乎都很好。

只有在卖方沙盒帐户的新型后端而不是草稿列表中,我收到一条错误消息,指出发生了错误,我应该重新加载页面(这当然没有帮助)。当我删除上面创建的草稿时,一切又恢复了正常,我可以看到我去年的旧草稿。我创建了一个新草稿,但我再次收到错误,等等。

在实时页面上也会发生同样的事情,所以这似乎不是沙盒问题。

我将 NuGet 包用于 PayPal REST API 和其中的类。我现在发现我可以查看发送到 PayPal 的 JSON。请求如下所示(匿名买家和卖家的电子邮件 - 所有其他字段均未更改,并且使用去年的相同值):

{
    "number": "RE2017072701",
    "merchant_info": {
        "email": "seller@xxxxx.de",
        "first_name": "Test",
        "last_name": "User",
        "address": {
            "phone": {
                "country_code": "49",
                "national_number": "1234595959"
            },
            "line1": "Teststraße 15",
            "line2": "Gewerbegebiet",
            "city": "Testingen",
            "country_code": "DE",
            "postal_code": "12345"
        },
        "business_name": "Testfirma GmbH",
        "website": "http://xxxxxcompany.de",
        "additional_info": "Hier steht noch weiterer Text!"
    },
    "billing_info": [{
        "email": "buyer@xxxxx.de",
        "first_name": "Kundenvorname",
        "last_name": "Kundennachname",
        "address": {
            "line1": "Kundenstr. 1",
            "city": "Kunden",
            "country_code": "DE",
            "postal_code": "99999"
        }
    }],
    "items": [{
        "name": "ITM0001",
        "description": "Ein Artikel für 199,99€",
        "quantity": 1.0,
        "unit_price": {
            "currency": "EUR",
            "value": "199.99"
        },
        "tax": {
            "name": "MwSt.",
            "percent": 19.0
        },
        "date": "0001-01-01 UTC"
    }],
    "invoice_date": "0001-01-01 UTC",
    "payment_term": {
        "term_type": "DUE_ON_RECEIPT",
        "due_date": "0001-01-01 UTC"
    },
    "tax_calculated_after_discount": false,
    "tax_inclusive": true
}

以下是 JSON 响应(我再次匿名化了电子邮件地址):

{
    "id": "INV2-LTSS-QW3C-DQS5-G8RF",
    "number": "RE2017072701",
    "template_id": "TEMP-7H507227XX2795902",
    "status": "DRAFT",
    "merchant_info": {
        "email": "seller@xxxxx.de",
        "first_name": "Test",
        "last_name": "User",
        "business_name": "Testfirma GmbH",
        "website": "http://xxxxxcompany.de",
        "address": {
            "line1": "Teststraße 15",
            "line2": "Gewerbegebiet",
            "city": "Testingen",
            "postal_code": "12345",
            "country_code": "DE",
            "phone": {
                "country_code": "49",
                "national_number": "1234595959"
            }
        },
        "additional_info": "Hier steht noch weiterer Text!"
    },
    "billing_info": [{
        "email": "buyer@xxxxx.de",
        "first_name": "Kundenvorname",
        "last_name": "Kundennachname",
        "address": {
            "line1": "Kundenstr. 1",
            "city": "Kunden",
            "postal_code": "99999",
            "country_code": "DE"
        }
    }],
    "items": [{
        "name": "ITM0001",
        "description": "Ein Artikel für 199,99€",
        "quantity": 1.0,
        "unit_price": {
            "currency": "EUR",
            "value": "199.99"
        },
        "tax": {
            "name": "MwSt.",
            "percent": 19.0,
            "amount": {
                "currency": "EUR",
                "value": "31.93"
            }
        },
        "date": "0001-12-31 PST"
    }],
    "invoice_date": "0001-12-31 PST",
    "payment_term": {
        "term_type": "DUE_ON_RECEIPT",
        "due_date": "0001-12-31 PST"
    },
    "tax_calculated_after_discount": false,
    "tax_inclusive": true,
    "total_amount": {
        "currency": "EUR",
        "value": "199.99"
    },
    "metadata": {
        "created_date": "2017-07-27 03:11:19 PDT"
    },
    "allow_tip": false,
    "links": [{
        "rel": "self",
        "href": "https://api.sandbox.paypal.com/v1/invoicing/invoices/INV2-LTSS-QW3C-DQS5-G8RF",
        "method": "GET"
    },
    {
        "rel": "send",
        "href": "https://api.sandbox.paypal.com/v1/invoicing/invoices/INV2-LTSS-QW3C-DQS5-G8RF/send",
        "method": "POST"
    },
    {
        "rel": "update",
        "href": "https://api.sandbox.paypal.com/v1/invoicing/invoices/INV2-LTSS-QW3C-DQS5-G8RF/update",
        "method": "PUT"
    },
    {
        "rel": "delete",
        "href": "https://api.sandbox.paypal.com/v1/invoicing/invoices/INV2-LTSS-QW3C-DQS5-G8RF",
        "method": "DELETE"
    }]
}

这里有什么问题?

PS:哦,我应该提一下,我当然可以在网页上成功地手动创建发票?

【问题讨论】:

    标签: c# rest api paypal invoice


    【解决方案1】:

    好的,通过返回最小发票,然后工作,我能够挑出日期值作为问题的根源。显然可以通过DateTime.MinValue,但随后 PayPal 网站无法正确处理。

    为未使用的日期传递 null 而不是 DateTime.MinValue 可以解决此问题。需要注意的是,过去传递DateTime.MinValue 是可以的。

    结案。

    【讨论】:

      猜你喜欢
      • 2014-11-09
      • 2017-10-31
      • 2014-12-17
      • 1970-01-01
      • 2014-04-27
      • 2021-09-13
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      相关资源
      最近更新 更多