forked from Adyen/adyen-cse-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adyen.encrypt.nodom.html
121 lines (90 loc) · 5.22 KB
/
adyen.encrypt.nodom.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example Payment Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/cse-example-form.css" type="text/css" />
</head>
<body>
<div id="adyen-encrypted-form">
<input type="button" onclick="addCardNumberField()" value="Create / monitor card number field" />
<input type="button" onclick="encryptExample()" value="Encrypt" />
<input type="button" onclick="validateExample()" value="Validate" />
</div>
<!-- How to use the Adyen encryption client-side JS library -->
<!-- N.B. Make sure the library is *NOT* loaded in the "head" of the HTML document -->
<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_24"></script>
<script type="text/javascript">
// the public key
var key = "10001|80C7821C961865FB4AD23F172E220F819A5CC7B9956BC3458E2788"
+ "F9D725B07536E297B89243081916AAF29E26B7624453FC84CB10FC7DF386"
+ "31B3FA0C2C01765D884B0DA90145FCE217335BCDCE4771E30E6E5630E797"
+ "EE289D3A712F93C676994D2746CBCD0BEDD6D29618AF45FA6230C1D41FE1"
+ "DB0193B8FA6613F1BD145EA339DAC449603096A40DC4BF8FACD84A5D2CA5"
+ "ECFC59B90B928F31715A7034E7B674E221F1EB1D696CC8B734DF7DE2E309"
+ "E6E8CF94156686558522629E8AF59620CBDE58327E9D84F29965E4CD0FAF"
+ "A38C632B244287EA1F7F70DAA445D81C216D3286B09205F6650262CAB415"
+ "5F024B3294A933F4DC514DE0B5686F6C2A6A2D";
var options = {};
// Enable basic field validation (default is true)
// The submit button will be disabled when fields
// proof to be invalid. The form submission will be
// prevented as well.
// options.enableValidations = true;
// Ignore non-numeric characters in the card number field (default
// is true)
// The payment handling ignores non-numeric characters for the card
// field.
// By default non-numeric characters will also be ignored while
// validating
// the card number field. This can be disabled for UX reasons.
// options.numberIgnoreNonNumeric = true;
// Ignore CVC validations for certain bins. Supply a comma separated
// list.
// options.cvcIgnoreBins = '6703'; // Ignore CVC for BCMC
// Use 4digit cvc for certain bins. Supply a comma separated list.
// options.fourDigitCvcForBins = '34,37'; // Set 4 digit CVC for Amex
var cseInstance = adyen.encrypt.createEncryption(key, options);
function getEncryptedFormData(cardNumber, cvc, holderName, expiryMonth, expiryYear, generationtime) {
var postData = {};
var cardData = {
number : cardNumber,
cvc : cvc,
holderName : holderName,
expiryMonth : expiryMonth,
expiryYear : expiryYear,
generationtime : generationtime
};
postData['adyen-encrypted-data'] = cseInstance.encrypt(cardData);
return postData;
}
function addCardNumberField ( ) {
var field = addCardNumberField.__field;
if ( field ) {
return;
}
field = document.createElement('input');
field.type = 'text';
field.placeHolder = "XXXX-XXXX-XXXX-XXXX";
document.body.appendChild ( field );
addCardNumberField.__field = field;
cseInstance.monitor ( "number", field );
}
function encryptExample() {
var generationTime = new Date().toISOString(); // Note:
// Generate this
// serverside!
var postData = getEncryptedFormData("5555 4444 3333 1111", "737", "John Doe", "06", "2016", generationTime);
var p = document.createElement("p");
p.innerHTML = "Post data: " + JSON.stringify(postData);
document.body.appendChild(p);
}
function validateExample() {
var valid = cseInstance.validate({"number": "5555 4444 3333 1111", "cvc" : "737", "month": "06", "year": "2016"});
var p = document.createElement("p");
p.innerHTML = "Validation response: " + JSON.stringify(valid);
document.body.appendChild(p);
}
</script>
</body>
</html>