Skip to content
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

sample app - add note and warning message #36

Merged
merged 4 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add note and warning message
  • Loading branch information
omarxp committed Sep 17, 2021
commit 196b9a31df2e2576198d48fc6aac77a8e8f3be23
13 changes: 10 additions & 3 deletions examples/coreApi/coreApiCreditCardExample.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const midtransClient = require('./../../index.js');
// const midtransClient = require('midtrans-client'); // use this if installed via NPM

// This is just for very basic implementation reference, in production, you should validate the incoming requests and implement your backend more securely.

// initialize core api client object
// can find in Merchant Portal -> Settings -> Access keys
rizdaprasetya marked this conversation as resolved.
Show resolved Hide resolved
let core = new midtransClient.CoreApi({
isProduction : false,
serverKey : 'YOUR_SERVER_KEY',
Expand All @@ -22,10 +25,13 @@ let core = new midtransClient.CoreApi({
// core.apiConfig.serverKey = 'YOUR_SERVER_KEY';
// core.apiConfig.clientKey = 'YOUR_CLIENT_KEY';

// IMPORTANT NOTE: You should do credit card get token via frontend using `midtrans.min.js`, to avoid card data breach risks on your backend
// ( refer to: https://api-docs.midtrans.com )
// IMPORTANT NOTE: You should do credit card get token via frontend using `midtrans-new-3ds.min.js`, to avoid card data breach risks on your backend
// ( refer to: https://docs.midtrans.com/en/core-api/credit-card?id=_1-getting-the-card-token )
// For full example on Credit Card 3DS transaction refer to:
// (/examples/expressApp) that implement Snap & Core Api

// prepare Core API parameter ( refer to: https://api-docs.midtrans.com ) minimum parameter example:
// prepare CORE API parameter to get credit card token
// another sample of card number can refer to https://docs.midtrans.com/en/technical-reference/sandbox-test?id=card-payments
let parameter = {
'card_number': '5264 2210 3887 4659',
'card_exp_month': '12',
Expand All @@ -35,6 +41,7 @@ let parameter = {
};
core.cardToken(parameter)
.then((cardTokenResponse)=>{
// prepare CORE API parameter to charge credit card ( refer to: https://docs.midtrans.com/en/core-api/credit-card?id=_2-sending-transaction-data-to-charge-api )
let cardToken = cardTokenResponse.token_id;
let parameter = {
"payment_type": "credit_card",
Expand Down
5 changes: 4 additions & 1 deletion examples/coreApi/coreApiSimpleExample.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const midtransClient = require('./../../index.js');
// const midtransClient = require('midtrans-client'); // use this if installed via NPM

// This is just for very basic implementation reference, in production, you should validate the incoming requests and implement your backend more securely.

// initialize core api client object
// can find in Merchant Portal -> Settings -> Access keys
let core = new midtransClient.CoreApi({
isProduction : false,
serverKey : 'YOUR_SERVER_KEY',
clientKey : 'YOUR_CLIENT_KEY'
});

// prepare Core API parameter ( refer to: https://api-docs.midtrans.com ) minimum parameter example:
// prepare CORE API parameter ( refer to: https://docs.midtrans.com/en/core-api/bank-transfer?id=sample-request-and-request-body ) charge bank_transfer parameter example
let parameter = {
"payment_type": "bank_transfer",
"transaction_details": {
Expand Down
32 changes: 27 additions & 5 deletions examples/expressApp/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// This is just for very basic implementation reference, in production, you should validate the incoming requests and implement your backend more securely.

const express = require('express');
const midtransClient = require('midtrans-client');

// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
const SERVER_KEY = '';
const CLIENT_KEY = '';

// Express setup
let app = express();
app.set('views', 'views');
Expand All @@ -20,8 +27,8 @@ app.get('/simple_checkout', function (req, res) {
// initialize snap client object
let snap = new midtransClient.Snap({
isProduction : false,
serverKey : 'SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA',
clientKey : 'SB-Mid-client-61XuGAwQ8Bj8LxSS'
serverKey : SERVER_KEY,
clientKey : CLIENT_KEY
rizdaprasetya marked this conversation as resolved.
Show resolved Hide resolved
});
let parameter = {
"transaction_details": {
Expand Down Expand Up @@ -51,8 +58,8 @@ app.get('/simple_checkout', function (req, res) {
// [0] Setup API client and config
let core = new midtransClient.CoreApi({
isProduction : false,
serverKey : 'SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA',
clientKey : 'SB-Mid-client-61XuGAwQ8Bj8LxSS'
serverKey : SERVER_KEY,
clientKey : CLIENT_KEY
});

// [1] Render HTML+JS web page to get card token_id and [3] 3DS authentication
Expand Down Expand Up @@ -194,10 +201,25 @@ app.get('/simple_core_api_checkout_permata', function (req, res) {
*/
// homepage
app.get('/', function (req, res) {
if (!SERVER_KEY || !CLIENT_KEY) {
// non-relevant function only used for demo/example purpose
res.send(printExampleWarningMessage());
}
res.render('index');
})

function printExampleWarningMessage() {
// pathfile = os.path.abspath("web.py")
message = "<code><h4>Please set your server key and client key from sandbox</h4>In file: " + __filename
message += "<br><br># Set Your server key"
message += "<br># can find in Merchant Portal -> Settings -> Access keys"
message += "<br>SERVER_KEY = ''"
message += "<br>CLIENT_KEY = ''</code>"
return message
}

// credit card frontend demo
app.get('/core_api_credit_card_frontend_sample', function (req, res) {
res.render('core_api_credit_card_frontend_sample',{ clientKey: core.apiConfig.clientKey });
})
app.listen(3000, () => console.log(`ExpressApp listening on localhost port 3000!`))
app.listen(3000, () => console.log(`ExpressApp listening on localhost port 3000!`))
Loading