|
| 1 | +<html> |
| 2 | +<head> |
| 3 | + <title>My Payment Form</title> |
| 4 | + <script type="text/javascript" src="https://js.squareup.com/v2/paymentform"></script> |
| 5 | + <script type="text/javascript"> |
| 6 | + var sqPaymentForm = new SqPaymentForm({ |
| 7 | + |
| 8 | + // Replace this value with your application's ID (available from the merchant dashboard). |
| 9 | + // If you're just testing things out, replace this with your _Sandbox_ application ID, |
| 10 | + // which is also available there. |
| 11 | + applicationId: 'REPLACE_ME', |
| 12 | + inputClass: 'sq-input', |
| 13 | + cardNumber: { |
| 14 | + elementId: 'sq-card-number', |
| 15 | + placeholder: "0000 0000 0000 0000" |
| 16 | + }, |
| 17 | + cvv: { |
| 18 | + elementId: 'sq-cvv', |
| 19 | + placeholder: 'CVV' |
| 20 | + }, |
| 21 | + expirationDate: { |
| 22 | + elementId: 'sq-expiration-date', |
| 23 | + placeholder: 'MM/YY' |
| 24 | + }, |
| 25 | + postalCode: { |
| 26 | + elementId: 'sq-postal-code', |
| 27 | + placeholder: 'Postal Code' |
| 28 | + }, |
| 29 | + inputStyles: [ |
| 30 | + |
| 31 | + // Because this object provides no value for mediaMaxWidth or mediaMinWidth, |
| 32 | + // these styles apply for screens of all sizes, unless overridden by another |
| 33 | + // input style below. |
| 34 | + { |
| 35 | + fontSize: '14px', |
| 36 | + padding: '3px' |
| 37 | + }, |
| 38 | + |
| 39 | + // These styles are applied to inputs ONLY when the screen width is 400px |
| 40 | + // or smaller. Note that because it doesn't specify a value for padding, |
| 41 | + // the padding value in the previous object is preserved. |
| 42 | + { |
| 43 | + mediaMaxWidth: '400px', |
| 44 | + fontSize: '18px', |
| 45 | + } |
| 46 | + ], |
| 47 | + callbacks: { |
| 48 | + cardNonceResponseReceived: function(errors, nonce, cardData) { |
| 49 | + if (errors) { |
| 50 | + var errorDiv = document.getElementById('errors'); |
| 51 | + errorDiv.innerHTML = ""; |
| 52 | + errors.forEach(function(error) { |
| 53 | + var p = document.createElement('p'); |
| 54 | + p.innerHTML = error.message; |
| 55 | + errorDiv.appendChild(p); |
| 56 | + }); |
| 57 | + } else { |
| 58 | + // This alert is for debugging purposes only. |
| 59 | + alert('Nonce received! ' + nonce + ' ' + JSON.stringify(cardData)); |
| 60 | + |
| 61 | + // Assign the value of the nonce to a hidden form element |
| 62 | + var nonceField = document.getElementById('card-nonce'); |
| 63 | + nonceField.value = nonce; |
| 64 | + |
| 65 | + // Submit the form |
| 66 | + document.getElementById('form').submit(); |
| 67 | + } |
| 68 | + }, |
| 69 | + unsupportedBrowserDetected: function() { |
| 70 | + // Alert the buyer that their browser is not supported |
| 71 | + } |
| 72 | + } |
| 73 | + }); |
| 74 | + function submitButtonClick() { |
| 75 | + event.preventDefault(); |
| 76 | + sqPaymentForm.requestCardNonce(); |
| 77 | + } |
| 78 | + </script> |
| 79 | + <style type="text/css"> |
| 80 | + .sq-input { |
| 81 | + border: 1px solid #CCCCCC; |
| 82 | + margin-bottom: 10px; |
| 83 | + padding: 1px; |
| 84 | + } |
| 85 | + .sq-input--focus { |
| 86 | + outline-width: 5px; |
| 87 | + outline-color: #70ACE9; |
| 88 | + outline-offset: -1px; |
| 89 | + outline-style: auto; |
| 90 | + } |
| 91 | + .sq-input--error { |
| 92 | + outline-width: 5px; |
| 93 | + outline-color: #FF9393; |
| 94 | + outline-offset: 0px; |
| 95 | + outline-style: auto; |
| 96 | + } |
| 97 | + </style> |
| 98 | +</head> |
| 99 | +<body> |
| 100 | + |
| 101 | + <h1>My Payment Form</h1> |
| 102 | + |
| 103 | + <form id="form" novalidate action="/process-card.php" method="post"> |
| 104 | + <label>Credit Card</label> |
| 105 | + <div id="sq-card-number"></div> |
| 106 | + <label>CVV</label> |
| 107 | + <div id="sq-cvv"></div> |
| 108 | + <label>Expiration Date</label> |
| 109 | + <div id="sq-expiration-date"></div> |
| 110 | + <label>Postal Code</label> |
| 111 | + <div id="sq-postal-code"></div> |
| 112 | + <input type="hidden" id="card-nonce" name="nonce"> |
| 113 | + <input type="submit" onclick="submitButtonClick()" id="card-nonce"> |
| 114 | + </form> |
| 115 | + |
| 116 | + <div id="errors"></div> |
| 117 | +</body> |
| 118 | +</html> |
0 commit comments