Skip to content

Instantly share code, notes, and snippets.

@jsdecena
Created February 8, 2022 20:40
Show Gist options
  • Save jsdecena/89c6a2fd8fed5184bd3ed588845543b3 to your computer and use it in GitHub Desktop.
Save jsdecena/89c6a2fd8fed5184bd3ed588845543b3 to your computer and use it in GitHub Desktop.

Authenticate and Save Token

const data = JSON.stringify({
  "api_key": "ff3a4889-94d0-4b85-92af-d545607f4d77",
  "api_secret": "79b1a302-8409-46a9-ba6e-8c5c30c11d2f",
  "grant_type": "client_credentials"
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    const response = this.responseText;
    
    // Save the token
    localStorage.setItem('token', response.token);
  }
});

xhr.open("POST", "https://aggreg82r.com/customer/auth");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.send(data);

Push transaction in our server

const data = JSON.stringify({
  "payment_gateway": "Stripe", // Your preferred gateway
  "amount": "10.50",
  "currency": "usd",
  "card": {
    "number": "4242424242424242",
    "expiryMonth": "6",
    "expiryYear": "2030",
    "cvv": "123"
  }
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    
    // PROCESS THE RESPONSE DATA IN YOUR APPLICATION
    const response = this.responseText;
  }
});

xhr.open("POST", "https://aggreg82r.com/customer/checkout");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer <TOKEN>");

xhr.send(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment