paypal/paypal-js

[Bug] CreateOrderRequestBody seems incorrectly typed

mikelpr opened this issue ยท 2 comments

๐Ÿž Describe the Bug

trying to get a grasp of what I can do I decided to use the CreateOrderRequestBody type for my body but I ran into the paypal backend actually rejecting the changes that were suggested

๐Ÿ”ฌ Minimal Reproduction

I had:

const body = {
          intent: 'CAPTURE',
          purchase_units: [
            {
              amount: {
                currency_code: 'USD',
                value: '10.00'
              }
            }
          ],
          payee: {
             email_address: '<redacted>'
          },
          payment_instruction: {
            disbursement_mode: 'INSTANT',
            platform_fees: [
              {
                amount: {
                  currency_code: 'USD',
                  value: '1.00'
                }
              }
            ]
          },
          payment_source: {
            paypal: {
              experience_context: {
                brand_name: 'brand',
                shipping_preference: 'NO_SHIPPING'
              }
            }
          }
        };

typing it with const body: CreateOrderRequestBody, it actually told me that payee and payment_instruction go in a purchase_unit object. moving payee up there I don't know what it does since it loads fine (but I didn't do the checkout), but moving payment_instruction to the purchase_unit object makes the server just reject the request, and you can see in the console Uncaught Error: Error: Expected an order id to be passed
at https://www.sandbox.paypal.com/smart/buttons?style.layout=horizontal&style.color=gold&style.shape=r

also the experience_context object is just typed for cancel_url, return_url, and user_action. totally missing brand_name and shipping_preference

๐Ÿ˜• Actual Behavior

following the typings, the server rejects the payload

๐Ÿค” Expected Behavior

the typings reflect what the paypal server wants

๐ŸŒ Environment

  • Node.js/npm: - v18.18.2
  • OS: - Fedora Linux 38
  • Browser: - Chrome 120

โž• Additional Context

Add any other context about the problem here.

Hi @mikelpr, thanks for reporting this issue. We are actively working on using the new Open API 3.0 spec for auto-generating the types for the PayPal APIs in this repo. Here is the PR to track for this work: #443