Last year I created a sample appliation that could create, send and check PayPal Invoices using the REST API. Everything worked like a charm, the invoices showed up in my sandbox seller backend and it just worked.
Today I use the exact same unmodified application to create an invoice draft. The response is OK, I can even "send" the invoice (apart from the fact that nobody's getting any emails...), I can get its status (which is DRAFT or SENT for example) - everything seems to be fine.
Only that in the new-style backend for the seller's sandbox account instead of a list of drafts I get an error message saying that an error occurred and I should reload the page (which of course doesn't help at all). When I delete the above created draft, everything is back to normal again and I can see my old drafts from last year. I create a new draft, I get the error again, and so forth.
The same thing happens on the live page as well, so it doesn't seem to be a sandbox issue.
I use the NuGet packages for the PayPal REST API and the classes therein. I now found that I can view the JSON that's being sent to PayPal. The request looks like this (anonymized the buyer and seller emails - all other fields are unchanged and worked with the same values last year):
{
"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
}
The following is the JSON response (again, I anonymized the email addresses):
{
"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"
}]
}
What is wrong here?
PS: Oh, and should I mention that of course I can manually create invoices on the web page successfully?
Ok, by going back to a minimal invoice, which then worked, I was able to single out the date values as the source of the problem. Obviously it is OK to pass DateTime.MinValue
, but then the PayPal WebSite doesn't handle it properly.
Passing null
instead of DateTime.MinValue
for unused dates fixes the issue. It should be noted that passing DateTime.MinValue
used to work.
Case closed.