-
Notifications
You must be signed in to change notification settings - Fork 1
Merge dev to Master #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Dependency directories | ||
| */node_modules/* | ||
| node_modules/* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,123 @@ | ||
| # NodeExampleAPI2 | ||
| # Conekta integration node.js example | ||
|
|
||
| This example shows a simple integration with Conekta API 2.0.0 | ||
|
|
||
| ## Getting Started | ||
|
|
||
| These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. | ||
|
|
||
| ### Prerequisites | ||
|
|
||
|
|
||
| You will need an actualized version of node and npm installed. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will need an updated version of node and npm installed. |
||
|
|
||
| In case you do not have the environment with node and npm, please refer to official documentation: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do not have npm installed and a ready node environment, please refer to the official documentation: |
||
|
|
||
| ``` | ||
| https://docs.npmjs.com/downloading-and-installing-node-js-and-npm | ||
|
|
||
| ``` | ||
|
|
||
| You will also need Conekta API keys | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will also need your Conekta API keys. |
||
|
|
||
| You can create a free account in minutes and use your sandbox API keys | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can create a free account in minutes and immediately access your Sandbox API keys. |
||
|
|
||
| Create your account here: | ||
|
|
||
| https://auth.conekta.com/sign_up | ||
|
|
||
| ### Set up this repo | ||
|
|
||
| A step by step series of examples that tell you how to get a development env running | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a step by step series of examples that tells you how to get a development environment up and running. |
||
|
|
||
| Step 1. Clone the repo | ||
|
|
||
| ``` | ||
| git clone https://github.com/conekta-examples/NodeExampleAPI2.git | ||
| ``` | ||
| Step 2. Install dependencies | ||
|
|
||
|
|
||
| Run the following command | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run the following command: |
||
|
|
||
| ``` | ||
| npm install | ||
|
|
||
| ``` | ||
|
|
||
| Step 3. Change your API keys | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add your API keys |
||
|
|
||
| You need | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? |
||
|
|
||
| Change your private Conekta API key | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add your private Conekta API key |
||
|
|
||
| Go to app.js file and change your private API key | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go to app.js file and add your private API key |
||
|
|
||
| ``` | ||
| var conekta = require('conekta'); | ||
| conekta.api_key = 'YOUR_PRIVATE_API_KEY'; | ||
| conekta.api_version = '2.0.0'; | ||
|
|
||
| ``` | ||
|
|
||
| Now go to views/newCard.ejs | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now go to views/newCard.ejs. |
||
|
|
||
| In line 47 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In line 47 add your public Conekta API key. |
||
|
|
||
| ``` | ||
|
|
||
| <script type="text/javascript"> | ||
| Conekta.setPublicKey('YOUR_PUBLIC_API_KEY'); | ||
|
|
||
| ``` | ||
|
|
||
| Step 4. Run the project and create charges | ||
|
|
||
| Run the following command | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run the following command: |
||
|
|
||
| ``` | ||
| node app.js | ||
| ``` | ||
|
|
||
| Follow the next URL and create a charge | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go to the following URL and create your first charge . |
||
|
|
||
| ``` | ||
| localhost:3005 | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| Edit the flow and adapt it to your business model | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit the flow and adapt it to your business model. |
||
|
|
||
| Read comments in app.js to fulfill your workflow | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Read comments in app.js to fulfill your workflow. |
||
|
|
||
| Find one of this flows on the example | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Find one of this flows on the example ¿¿no entiendo?? |
||
|
|
||
| Preauthorizations | ||
| Monthly installments | ||
| Add time of expiration to Oxxo Pay or Spei payments | ||
|
|
||
|
|
||
|
|
||
| Step 5. Deploy it in your live URL to receive Webhooks | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step 5. Deploy your project on your public URL to receive Webhook notifications |
||
|
|
||
| ## Deployment | ||
|
|
||
| Add additional notes about how to deploy this on a live system | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add additional notes about how to deploy this on a live system. |
||
|
|
||
|
|
||
|
|
||
|
|
||
| ## Authors | ||
|
|
||
| * **Santiago Campos** - *Jr Developer* - [San](https://github.com/santiagocamposenr) | ||
| * **Daniel Diner** - *Jr Developer* - [Dan](https://github.com/dinerdaniel) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| ## Acknowledgments | ||
|
|
||
| * Check out the complete documentation for Conekta API https://developers.conekta.com/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,248 @@ | ||
| var conekta = require('conekta'); | ||
| conekta.api_key = 'YOUR_API_KEY'; | ||
| conekta.api_version = '2.0.0'; | ||
|
|
||
| var express = require("express"); | ||
| var app = express(); | ||
| var request = require("request"); | ||
| var bodyParser = require("body-parser"); | ||
| // const simpleIcons = require('simple-icons'); | ||
| var oxxo = [ | ||
| {ref: "Aún no has creado una referencia"} | ||
| ]; | ||
| var spei = [ | ||
| {clabe: "Aún no has creado una Clabe de cobro"} | ||
| ]; | ||
|
|
||
|
|
||
|
|
||
| app.use(bodyParser.urlencoded({extended: true})); | ||
| app.set("view engine", "ejs"); | ||
|
|
||
| app.get("/", function(req, res){ | ||
| res.render("home"); | ||
|
|
||
| }); | ||
| /////////////////////////////////////////////////////////////////////////////////// | ||
| app.get("/card", function(req, res){ | ||
| res.render("newCard"); | ||
| }); | ||
|
|
||
| app.post("/card", function(req, res){ | ||
| var token = req.body.conektaTokenId; | ||
| order = conekta.Order.create({ | ||
| "line_items": [{ | ||
| "name": "Tacos", | ||
| "unit_price": 1000, | ||
| "quantity": 6 | ||
| }], | ||
| "shipping_lines": [{ | ||
| "amount": 1000, | ||
| "carrier": "FEDEX" | ||
| }], //shipping_lines - physical goods only | ||
| "currency": "MXN", | ||
| "customer_info": { | ||
| 'name': 'Fulanito Pérez', | ||
| 'email': 'fulanito@conekta.com', | ||
| 'phone': '+52181818181' | ||
| }, | ||
| "shipping_contact":{ | ||
| "address": { | ||
| "street1": "Calle 123, int 2", | ||
| "postal_code": "06100", | ||
| "country": "MX" | ||
| } | ||
| }, //shipping_contact - required only for physical goods | ||
| "metadata": { "description": "Compra de creditos: 300(MXN)", "reference": "1334523452345" }, | ||
| "charges":[{ | ||
| "payment_method": { | ||
| //'monthly_installments':9, | ||
| 'type': 'card', | ||
| 'token_id': token | ||
| } | ||
| }] | ||
|
|
||
| }, function(err, res) { | ||
| if(err){ | ||
| console.log(err); | ||
| return; | ||
| } | ||
| }); | ||
| res.render("orden"); | ||
| }); | ||
|
|
||
| // // UPDATE ORDER CON INFO EN METADATA | ||
| // conekta.Order.find("ord_2hFmUB1FWBrdfnMjj", function(err, order) { | ||
| // order.update({ | ||
| // "metadata": {"ref": "123abc"} | ||
| // }, function(err, res) { | ||
| // console.log(res.toObject()); | ||
| // }); | ||
| // }); | ||
|
|
||
|
|
||
| // // ANADIR CHARGE PARA COBRAR ORDER | ||
| // conekta.Order.find("ord_2hFmUB1FWBrdfnMjj", function(err, order) { | ||
| // order.createCharge({ | ||
| // "payment_method": { | ||
| // "type": "default" | ||
| // } | ||
| // }, function(err, charge) { | ||
| // console.log(charge); | ||
| // }); | ||
| // }); | ||
|
|
||
|
|
||
|
|
||
| // conekta.Order.find('ord_2hMKgYu9knTbMmiwp', function (err, order) { | ||
| // if (err) { | ||
| // console.log(err) | ||
| // return; | ||
| // } | ||
| // order.capture(function (errCapture, capture) { | ||
| // console.log('errCapture', errCapture); | ||
| // console.log('capture', capture); | ||
| // }); | ||
| // }); | ||
|
|
||
|
|
||
| //Capturar orden preautorizada | ||
| // var order = conekta.Order.find('ord_2jQMWD1N3b2RczVuX', function(err, order) { | ||
| // order.capture(function(err, res) { | ||
| // }); | ||
| // }); | ||
|
|
||
| //cancelar orden | ||
| // curl -H "Accept: application/vnd.conekta-v2.0.0+json" \ | ||
| // -H "Content-type: application/json" \ | ||
| // -u key_aFyhrz5wU7qyQfaxfy5p6g: \ | ||
| // -X POST https://api.conekta.io/orders/ord_2jQMsHaAHjFGYj9bM/void | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| app.get("/oxxo", function(req, res){ | ||
| res.render("oxxo", {oxxo:oxxo}); | ||
| }); | ||
|
|
||
| app.post("/oxxo", function(req, res){ | ||
| var name = req.body.name; | ||
| var precio = req.body.precio; | ||
| var cantidad = req.body.cantidad; | ||
| order = conekta.Order.create({ | ||
| "line_items": [{ | ||
| "name": name, | ||
| "unit_price": precio, | ||
| "quantity": cantidad | ||
| }], | ||
| "shipping_lines": [{ | ||
| "amount": 1500, | ||
| "carrier": "FEDEX" | ||
| }], //shipping_lines - phyiscal goods only | ||
| "currency": "MXN", | ||
| "customer_info": { | ||
| "name": "Fulanito Pérez", | ||
| "email": "fulanito@conekta.com", | ||
| "phone": "+5218181818181" | ||
| }, | ||
| "shipping_contact":{ | ||
| "address": { | ||
| "street1": "Calle 123, int 2", | ||
| "postal_code": "06100", | ||
| "country": "MX" | ||
| } | ||
| }, //shipping_contact - required only for physical goods | ||
| "charges":[{ | ||
| "payment_method": { | ||
| "type": "oxxo_cash" | ||
| //Utiliza este timestamp para fijar la fecha de expiracion de la orden | ||
| //"expires_at": 1668211200 | ||
| } | ||
| }] | ||
| }, function(req, ord) { | ||
| var ord = ord.toObject(); | ||
| console.log(ord.charges.data[0].payment_method.reference); | ||
| console.log(ord.charges.data[0].payment_method.reference); | ||
| var ref = ord.charges.data[0].payment_method.reference; | ||
| var newOxxo = {ref : ref}; | ||
| oxxo.push(newOxxo); | ||
| res.redirect("oxxo"); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| app.get("/oxxo/new", function(req, res){ | ||
| res.render("oxxonew"); | ||
| }); | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| app.get("/spei", function(req, res){ | ||
| res.render("spei", {spei:spei}); | ||
| }); | ||
|
|
||
| app.post("/spei", function(req, res){ | ||
| var name = req.body.name; | ||
| var precio = req.body.precio; | ||
| var cantidad = req.body.cantidad; | ||
| order = conekta.Order.create({ | ||
| "line_items": [{ | ||
| "name": name, | ||
| "unit_price": precio, | ||
| "quantity": cantidad | ||
| }], | ||
| "shipping_lines": [{ | ||
| "amount": 1500, | ||
| "carrier": "FEDEX" | ||
| }], //shipping_lines - phyiscal goods only | ||
| "currency": "MXN", | ||
| "customer_info": { | ||
| "name": "Fulanito Pérez", | ||
| "email": "fulanito@conekta.com", | ||
| "phone": "+5218181818181" | ||
| }, | ||
| "shipping_contact":{ | ||
| "address": { | ||
| "street1": "Calle 123, int 2", | ||
| "postal_code": "06100", | ||
| "country": "MX" | ||
| } | ||
| }, //shipping_contact - required only for physical goods | ||
| "charges":[{ | ||
| "payment_method": { | ||
| "type": "spei" | ||
| //Utiliza este timestamp para fijar la fecha de expiracion de la orden | ||
| //"expires_at": 1668211200 | ||
| } | ||
| }] | ||
| }, function(req, ord) { | ||
| var ord = ord.toObject(); | ||
| console.log("CLABE: " + ord.charges.data[0].payment_method.receiving_account_number); | ||
| var clabe = ord.charges.data[0].payment_method.receiving_account_number; | ||
| var newSpei = {clabe : clabe}; | ||
| spei.push(newSpei); | ||
| // console.log(spei.length) | ||
| res.redirect("spei"); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| app.get("/spei/new", function(req, res){ | ||
| res.render("speinew"); | ||
| }); | ||
|
|
||
| /////////////////////////////////// | ||
|
|
||
| //This is the webhook | ||
| //https://developers.conekta.com/resources/webhooks | ||
| app.post("/webwook", function(req, res) { | ||
| res.sendStatus(200); | ||
| // console.log(req.body); | ||
| }); | ||
|
|
||
|
|
||
| var server = app.listen(3005, function(){ | ||
| console.log("Server has started!!!", server.address().port); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tutorial will create a basic e-commerce checkout, running on your local server for development and testing purposes. Check deployment notes to see how to deploy the project on a live server.