0

So, i was wondering if there was any possible way to integrate the PayPal invoicing API with my discord.js bot. I am new to API's in discord.js and i am trying to figure this out. A simple request is suppose to look like this,

curl -v -X POST https://api.sandbox.paypal.com/v1/invoicing/invoices/ \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token" \
-d '{
  "merchant_info": {
    "email": "merchant@example.com",
    "first_name": "David",
    "last_name": "Larusso",
    "business_name": "Mitchell & Murray",
    "phone": {
      "country_code": "001",
      "national_number": "4085551234"
    },
    "address": {
      "line1": "1234 First Street",
      "city": "Anytown",
      "state": "CA",
      "postal_code": "98765",
      "country_code": "US"
    }
  },
  "billing_info": [
    {
      "email": "bill-me@example.com",
      "first_name": "Stephanie",
      "last_name": "Meyers"
    }
  ],
  "shipping_info": {
    "first_name": "Stephanie",
    "last_name": "Meyers",
    "address": {
      "line1": "1234 Main Street",
      "city": "Anytown",
      "state": "CA",
      "postal_code": "98765",
      "country_code": "US"
    }
  },
  "items": [
    {
      "name": "Zoom System wireless headphones",
      "quantity": 2,
      "unit_price": {
        "currency": "USD",
        "value": "120"
      },
      "tax": {
        "name": "Tax",
        "percent": 8
      }
    },
    {
      "name": "Bluetooth speaker",
      "quantity": 1,
      "unit_price": {
        "currency": "USD",
        "value": "145"
      },
      "tax": {
        "name": "Tax",
        "percent": 8
      }
    }
  ],
  "discount": {
    "percent": 1
  },
  "shipping_cost": {
    "amount": {
      "currency": "USD",
      "value": "10"
    }
  },
  "note": "Thank you for your business.",
  "terms": "No refunds after 30 days."
}'

However i am not sure how to request this in the first place. Thanks for your help.

Checksum
  • 317
  • 1
  • 5
  • 18
  • That's just a JSON POST: https://stackoverflow.com/questions/6158933/how-to-make-an-http-post-request-in-node-js – Rup Feb 24 '19 at 09:58
  • 1
    And there are plenty of PayPal integration libraries you can search for on NPM already. I'd be surprised if there wasn't one that gave you a simple interface to the invoicing API but I can't see it at first glance. – Rup Feb 24 '19 at 09:59
  • @Rup Thanks for that, now i am having a problem pulling the payment url from the response. If i cant fix this i will post a separate question. – Checksum Feb 24 '19 at 19:30

1 Answers1

1

So, i ended up using the paypal-rest-sdk (Thanks @rup) and ditched the invoicing idea because it was easier to do payments.

I am running into another problem where i cant grab the approval url and put it in a discord embed.Paypal Checkout

If i cant fix this on my own i will post a question about it.

Checksum
  • 317
  • 1
  • 5
  • 18