去年,我创建了一个示例应用程序,可以使用REST API创建,发送和检查PayPal发票。一切都像一个魅力,发票出现在我的沙箱卖家后端,它只是起作用。
今天我使用完全相同的未经修改的应用程序来创建发票草稿。答案还可以,我甚至可以“发送”发票(除了没有人收到任何电子邮件的事实......),我可以获得它的状态(例如DRAFT或SENT) - 一切似乎都很好。< / p>
只有在卖家的沙盒帐户的新式后端而不是草稿列表中,我收到一条错误消息,说明发生了错误,我应该重新加载页面(当然这根本没有帮助)。当我删除上面创建的草稿时,一切都恢复正常,我可以看到去年的旧草稿。我创建了一个新草稿,我再次收到错误,等等。
同样的事情也发生在实时页面上,因此它似乎不是沙盒问题。
我将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:哦,我应该提一下,我当然可以在网页上手动创建发票吗?
答案 0 :(得分:0)
好的,回到最小的发票,然后工作,我能够挑出日期值作为问题的根源。显然可以通过DateTime.MinValue
,但PayPal网站不能正确处理它。
为未使用的日期传递null
而非DateTime.MinValue
可解决问题。应该注意的是,通过DateTime.MinValue
过去了。
案件结案。