Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
token-market
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bitsoko services
token-market
Commits
23274481
Unverified
Commit
23274481
authored
Jul 17, 2018
by
bitsoko
Committed by
GitHub
Jul 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create credit-card.js
parent
60a56ead
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
131 additions
and
0 deletions
+131
-0
credit-card.js
js/credit-card.js
+131
-0
No files found.
js/credit-card.js
0 → 100644
View file @
23274481
/**
* Builds PaymentRequest for credit cards, but does not show any UI yet.
*
* @return {PaymentRequest} The PaymentRequest oject.
*/
function
initPaymentRequest
(
oid
,
amount
)
{
let
networks
=
[
'amex'
,
'diners'
,
'discover'
,
'jcb'
,
'mastercard'
,
'unionpay'
,
'visa'
,
'mir'
];
let
types
=
[
'debit'
,
'credit'
,
'prepaid'
];
let
supportedInstruments
=
[{
supportedMethods
:
networks
,
},
{
supportedMethods
:
[
'basic-card'
],
data
:
{
supportedNetworks
:
networks
,
supportedTypes
:
types
},
}];
let
details
=
{
total
:
{
label
:
'Total'
,
amount
:
{
currency
:
baseCd
.
toUpperCase
(),
value
:
amount
}
},
displayItems
:
[
{
label
:
'TID-'
+
oid
,
amount
:
{
currency
:
baseCd
.
toUpperCase
(),
value
:
amount
},
},
],
};
return
new
PaymentRequest
(
supportedInstruments
,
details
);
}
/**
* Invokes PaymentRequest for credit cards.
*
* @param {PaymentRequest} request The PaymentRequest object.
*/
function
onBuyClicked
(
request
)
{
request
.
show
().
then
(
function
(
instrumentResponse
)
{
sendPaymentToServer
(
instrumentResponse
);
})
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
$
(
'#tradeOrder'
).
modal
(
'close'
);
});
}
/**
* Simulates processing the payment data on the server.
*
* @param {PaymentResponse} instrumentResponse The payment information to
* process.
*/
function
sendPaymentToServer
(
instrumentResponse
)
{
// There's no server-side component of these samples. No transactions are
// processed and no money exchanged hands. Instantaneous transactions are not
// realistic. Add a 2 second delay to make it seem more real.
window
.
setTimeout
(
function
()
{
instrumentResponse
.
complete
(
'success'
)
.
then
(
function
()
{
document
.
getElementById
(
'result'
).
innerHTML
=
instrumentToJsonString
(
instrumentResponse
);
})
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
});
},
2000
);
}
/*
//Open User Account
$(document).on("click", "#topUpToken", function () {
$("#tradeOrder").modal({
onCloseStart: starting(),
onCloseEnd: $("#userAccount").modal("open")
}).modal("close")
setTimeout(function () {
$("#userAccount").modal("open");
}, 2000);
})
*/
/**
* Converts the payment instrument into a JSON string.
*
* @private
* @param {PaymentResponse} instrument The instrument to convert.
* @return {string} The JSON string representation of the instrument.
*/
function
instrumentToJsonString
(
instrument
)
{
let
details
=
instrument
.
details
;
details
.
cardNumber
=
'XXXX-XXXX-XXXX-'
+
details
.
cardNumber
.
substr
(
12
);
details
.
cardSecurityCode
=
'***'
;
return
JSON
.
stringify
({
methodName
:
instrument
.
methodName
,
details
:
details
,
},
undefined
,
2
);
}
const
payButton
=
document
.
getElementById
(
'buyTokenButton'
);
payButton
.
setAttribute
(
'style'
,
'display: none;'
);
if
(
window
.
PaymentRequest
)
{
let
request
;
payButton
.
setAttribute
(
'style'
,
'display: inline;'
);
payButton
.
addEventListener
(
'click'
,
function
()
{
var
oid
=
document
.
querySelector
(
'#buyTokenButton'
).
getAttribute
(
"oid"
);
var
amount
=
document
.
querySelector
(
'#buyTokenButton'
).
getAttribute
(
"amount"
);
request
=
initPaymentRequest
(
oid
,
amount
);
onBuyClicked
(
request
);
});
}
else
{
console
.
log
(
'This browser does not support web payments'
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment