Search code examples
angularpaypalpaypal-adaptive-payments

Pre-fill PayPal Billing details for credit card


Trying to pre-fill some details for the card payment based on https://developer.paypal.com/docs/checkout/integration-features/standard-card-fields/. But the example https://developer.paypal.com/docs/checkout/integration-features/standard-card-fields/ is not working, because the json does not fit to the types in "@paypal/paypal-js": "^4.1.0".

So I adjusted it --> https://developer.paypal.com/docs/api/orders/v2/#definition-payer See also: @paypal\paypal-js\types\apis\orders.d.ts

But now the following error accours:

{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"10a838ea45721","details":[{"field":"/payer/phone/phone_number","location":"body","issue":"MALFORMED_REQUEST_JSON","description":"The request JSON is not well formed."}]

My configuration:

 paypal
          .Buttons({
            createOrder: (data: UnknownObject, actions: CreateOrderActions) => {
              // This function sets up the details of the transaction, including the amount and line item details.
              return actions.order.create({
                application_context: {
                  shipping_preference: 'NO_SHIPPING',
                },
                payer: {
                  payer_id: '1',
                  birth_date: '2021-01-01',
                  tax_info: {
                    tax_id: '1',
                    tax_id_type: 'string',
                  },
                  email_address: '[email protected]',
                  phone: {
                    phone_number: '45465',
                  },
                  name: {
                    given_name: 'PayPal',
                    surname: 'Customer',
                  },
                  address: {
                    address_line_1: '123 ABC Street',
                    address_line_2: 'Apt 2',
                    admin_area_2: 'San Jose',
                    admin_area_1: 'CA',
                    postal_code: '95121',
                    country_code: 'US',
                  },
                },
                purchase_units: [
                  {
                    amount: {
                      value: '0.01',
                      currency_code: 'EUR',
                    },
                  },
                ],
              });
            },
...

I tried different values for phone_number, but always the same error. What is the problem?

Thanks, Maik.


Solution

  • Per the documentation, phone_number must have a national_number key. Do not include a payer_id or invalid tax_info object.

                  {
                    application_context: {
                      shipping_preference: 'NO_SHIPPING',
                    },
                    payer: {
                      birth_date: '2021-01-01',
                      email_address: '[email protected]',
                      phone: {
                        phone_number: {
                            national_number: '4543433243',
                        }
                      },
                      name: {
                        given_name: 'PayPal',
                        surname: 'Customer',
                      },
                      address: {
                        address_line_1: '123 ABC Street',
                        address_line_2: 'Apt 2',
                        admin_area_2: 'San Jose',
                        admin_area_1: 'CA',
                        postal_code: '95121',
                        country_code: 'US',
                      },
                    },
                    purchase_units: [
                      {
                        amount: {
                          value: '0.01',
                          currency_code: 'EUR',
                        },
                      },
                    ],
                  }