Enngage / ngx-paypal

Paypal integration for Angular
https://enngage.github.io/ngx-paypal/
MIT License
185 stars 68 forks source link

OnError Error: Expected an order id to be passed / order created server side #200

Closed kombasltd closed 2 years ago

kombasltd commented 2 years ago

Hi,

I use ngx-paypal with a .NET Core WebApi and create the order server side which seems to work well in general. I am using NuGet package "PayPalCheckoutSdk".

[14:49:34 INF] PAYPAL OBJECT => {"application_context":{"brand_name":"xxx","landing_page":"BILLING","shipping_preference":"SET_PROVIDED_ADDRESS","user_action":"CONTINUE"},"intent":"CAPTURE","purchase_units":[{"amount":{"breakdown":{"item_total":{"currency_code":"EUR","value":"129.95"},"tax_total":{"currency_code":"EUR","value":"0.00"}},"currency_code":"EUR","value":"129.95"},"description":"xxx","invoice_id":"20220227/5E476C2D","items":[{"category":"DIGITAL_GOODS","name":"xxx","quantity":"1","sku":"","unit_amount":{"currency_code":"EUR","value":"129.95"}}],"reference_id":"kayomo GmbH","shipping":{"address":{"address_line_1":"xxx20a","admin_area_2":"Berlin","country_code":"DE","postal_code":"xxx"},"name":{"full_name":"xxx"}}]}
[14:49:35 INF] CreatePayPalOrder::Handler::Result => {"$type": "Order"}
Status: CREATED
Order Id: 5CG80651BW039354R
Intent: CAPTURE
Links:
        self: https://api.paypal.com/v2/checkout/orders/5CG80651BW039354R       Call Type: GET
        approve: https://www.paypal.com/checkoutnow?token=5CG80651BW039354R     Call Type: GET
        update: https://api.paypal.com/v2/checkout/orders/5CG80651BW039354R     Call Type: PATCH
        capture: https://api.paypal.com/v2/checkout/orders/5CG80651BW039354R/capture    Call Type: POST
Total Amount: EUR 129.95
[14:49:35 INF] Executing OkObjectResult, writing value of type 'PayPalCheckoutSdk.Orders.Order'.
[14:49:35 INF] Executed action API.Controllers.PaymentsController.CreatePayPalOrder (API) in 1386.8263ms
[14:49:35 INF] Executed endpoint 'API.Controllers.PaymentsController.CreatePayPalOrder (API)'

But on the client side I get the error, that an order id is missing:

{
    "err": "Error: Expected an order id to be passed\n    at ...
    "timestamp": "1645969775795",
    "referer": "www.sandbox.paypal.com",
    "sdkCorrelationID": "f712697bd60f9",
    "sessionID": "uid_8123879a1c_mtm6mti6ntc",
    "clientID": "xxx",
    "env": "sandbox",
    "buttonSessionID": "uid_1607389fd2_mtm6mti6ntc",
    "buttonCorrelationID": "7b5abe6aa457",
    "time": "1645969775795",
    "user_id": "uid_1607389fd2_mtm6mti6ntc",
    "token": null
}

Edit: And in my Chrome console I see (uids differ from various tests):

b.stats.paypal.com/v2/counter.cgi?p=uid_2f912f3082_mty6nta6ndy&s=SMART_PAYMENT_BUTTONS:1 GET https://b.stats.paypal.com/v2/counter.cgi?p=uid_2f912f3082_mty6nta6ndy&s=SMART_PAYMENT_BUTTONS net::ERR_NAME_NOT_RESOLVED

I am using Angular 13:

@angular-devkit/architect       0.1301.2
@angular-devkit/build-angular   13.1.2
@angular-devkit/core            13.1.2
@angular-devkit/schematics      13.1.2
@angular/cli                    13.1.2
@schematics/angular             13.1.2
rxjs                            6.6.7
typescript                      4.5.4

Any hints please?

kombasltd commented 2 years ago

I fixed it. The server code example I used was a bit fuzzy.

Just needed to return the id as a result from the created order with the PayPal HTTP client in the same routine ;-)