通过 REST API 创建的发票导致 PayPal 后端出错
Invoice created via REST API causes error in PayPal backend
去年我创建了一个示例应用程序,它可以使用 REST API 创建、发送和检查 PayPal 发票。一切都很顺利,发票出现在我的沙盒卖家后端,而且一切正常。
今天我使用完全相同的未修改应用程序来创建发票草稿。回复没问题,我什至可以 "send" 发票(除了没有人收到任何电子邮件......),我可以得到它的状态(例如 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:哦,我要说当然可以在网页上手动创建发票吗?
好的,通过回到最小发票,然后工作,我能够挑出日期值作为问题的根源。明明可以通过DateTime.MinValue
,但是PayPal WebSite没有正确处理它。
为未使用的日期传递 null
而不是 DateTime.MinValue
可以解决此问题。应该注意的是,传递 DateTime.MinValue
曾经有效。
案件结案。
去年我创建了一个示例应用程序,它可以使用 REST API 创建、发送和检查 PayPal 发票。一切都很顺利,发票出现在我的沙盒卖家后端,而且一切正常。
今天我使用完全相同的未修改应用程序来创建发票草稿。回复没问题,我什至可以 "send" 发票(除了没有人收到任何电子邮件......),我可以得到它的状态(例如 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:哦,我要说当然可以在网页上手动创建发票吗?
好的,通过回到最小发票,然后工作,我能够挑出日期值作为问题的根源。明明可以通过DateTime.MinValue
,但是PayPal WebSite没有正确处理它。
为未使用的日期传递 null
而不是 DateTime.MinValue
可以解决此问题。应该注意的是,传递 DateTime.MinValue
曾经有效。
案件结案。