Obtain a reference/id/number/something when onAuthorize (good payment on API REST)

movaj
Contributor
Contributor

Hello,

I'm using the API-REST for paypal checkout and all is working fine.

Now, I want to know that kind of information can I load into my website when "onAuthorize".

For example, obtain a reference, number or somethig to save into my db and use it to mix between my database and paypal action list.

 

Is there a documentation or something? Thanks!

 

Here the simply code I'm using:

<!DOCTYPE html>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>

<body>
    <div id="paypal-button"></div>

<script>
  
    paypal.Button.render({

    env: 'sandbox',

    locale: 'es_ES',

    style: {
        size: 'medium',
        color: 'silver',
        shape: 'pill',
        label: 'checkout'
    },

    // Pass all other options that the button requires here
    });

    paypal.Button.render({

        env: 'sandbox', 

        client: {
            sandbox:    'xxxx',
            production: 'xxxx'
        },

        commit: true, 

        payment: function(data, actions) {
            return actions.payment.create({
                payment: {
                    transactions: [
                        {
                            amount: { total: '75.00', currency: 'EUR' }
                        }
                    ]
                }
            });
        },

        onCancel: function(data, actions) {

            window.alert('Has cancelado el pago.');
        },

        onAuthorize: function(data, actions) {
            return actions.payment.execute().then(function(payment) {

                window.alert('Pago completado correctamente.');
                

            });
        }


    }, '#paypal-button');
</script>
</body>
Login to Me Too
1 REPLY 1

MTS_Jennifer
Moderator
Moderator

PayPal Rest API variables can be used for this integration.

 

Rest API PayPal Payments Reference

 

From the PayPal Payment's Reference here is an example of some information you can send in the request. Notice the custom variable can be where you store your own custom information. It will be returned in the Response.

 

"transactions": [
    {
      "amount": {
        "total": "30.11",
        "currency": "USD",
        "details": {
          "subtotal": "30.00",
          "tax": "0.07",
          "shipping": "0.03",
          "handling_fee": "1.00",
          "insurance": "0.01",
          "shipping_discount": "-1.00"
        }
      },
      "description": "This is the payment transaction description.",
      "custom": "EBAY_EMS_90048630024435",
      "invoice_number": "48787589673",
      "item_list": {
        "items": [
          {
            "name": "hat",
            "sku": "1",
            "price": "3.00",
            "currency": "USD",
            "quantity": "5",
            "description": "Brown color hat",
            "tax": "0.01"
          },
          {
            "name": "handbag",
            "sku": "product34",
            "price": "15.00",
            "currency": "USD",
            "quantity": "1",
            "description": "Black color handbag",
            "tax": "0.02"
          }

 

Sample PayPal Rest API Code

 

You can also request payment details from a completed payment:

Sample PayPal Rest API Requesting Payment Details

 

Thanks,

Jennifer

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.