通过 REST API 创建的发票导致 PayPal 后端出错

托尔斯滕·迪特玛

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

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

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

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

我将 NuGet 包用于 PayPal REST API 和其中的类。我现在发现我可以查看发送到 PayPal 的 JSON。请求看起来像这样(匿名买家和卖家电子邮件 - 所有其他字段都保持不变,并使用去年相同的值):

{
    "number": "RE2017072701",
    "merchant_info": {
        "email": "[email protected]",
        "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": "[email protected]",
        "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": "[email protected]",
        "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": "[email protected]",
        "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:哦,我要不要提一下,我当然可以在网页上成功地手动创建发票?

托尔斯滕·迪特玛

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

传递null而不是DateTime.MinValue未使用的日期解决了这个问题。应该注意的是,传递DateTime.MinValue用于工作。

案件结案。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章