PageSourceSearch

https://tmtrd.org/wp-content/plugins/give-2checkout//assets/js/give-twocheckout.js?ver=7.0.7

js tmtrd.org collected 2026-10-09 03:46:24 UTC 3,720 bytes, 147 lines download raw bytes

1/**
2 * Give 2Checkout Gateway
3 *
4 * @description: Tokenizes credit card data for 2Checkout
5 */
6
7var give_twocheckout_js;
8
9jQuery( document ).ready(
10	function ($) {
11
12		// Pull in the public key for the environment (sandbox or production).
13		TCO.loadPubKey( give_twocheckout_js.env );
14
15		// On gateway change.
16		$( document ).on(
17			'give_gateway_loaded', function () {
18
19				$( '.give-form' ).each(
20					function () {
21						give2Checkout( $( this ) );
22					}
23				);
24
25			}
26		);
27
28		// Loop through donation forms on page and initialize 2Checkout.
29		$( '.give-form' ).each(
30			function () {
31				give2Checkout( $( this ) );
32			}
33		);
34
35		/**
36		 * Process gateway payments and errors upon donation button click.
37		 *
38		 * @param form
39		 */
40		function give2Checkout(form) {
41
42			var form_submit_btn = form.find( '.give-submit' ),
43				form_loader     = form.find( '.give-loading-animation' );
44
45			/**
46			 * Set per form submission
47			 */
48			form.submit(
49				function (e) {
50
51					// Prevent multiple requests.
52					form_submit_btn.attr( 'disabled', 'disabled' );
53
54					// Make sure the proper gateway is set.
55					if ('twocheckout' === form.find( 'input[name="give-gateway"]' ).val()) {
56						if (give_twocheckout_js.sellerId && give_twocheckout_js.publishableKey) {
57							// Call our token request function
58							tokenRequest();
59							return false;
60						} else {
61							// Missing credentials
62							give2CheckoutError( give_twocheckout_js.keys_error );
63							return false;
64						}
65					}
66				}
67			);
68
69			/**
70			 * 2Checkout Error
71			 *
72			 * @param message
73			 */
74			function give2CheckoutError(message) {
75
76				var html = '';
77				html    += '<div class="give_notices give_errors">';
78				html    += '<div class="give_error give_notice"';
79				html    += '<p><strong>' + give_twocheckout_js.error + '</strong>: ';
80				html    += message;
81				html    += '</p></div></div>';
82
83				form_loader.hide();
84				form_submit_btn.attr( 'disabled', false );
85				form_submit_btn.val( form_submit_btn.data( 'before-validation-label' ) );
86				form_submit_btn.before( html );
87			}
88
89			/**
90			 * 2Checkout Success Callback
91			 *
92			 * @param data
93			 */
94			var successCallback = function (data) {
95				// Set the token as the value for the token input
96				form.find( '.twocheckout-token' ).val( data.response.token.token );
97				// IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
98				form.unbind( 'submit' ).submit();
99			};
100
101			/**
102			 * Error Callback
103			 *
104			 * Called when token creation fails.
105			 *
106			 * @param data
107			 */
108			var errorCallback = function (data) {
109
110				var errorcode = parseInt( data.errorCode );
111
112				if (200 === errorcode) {
113					// Ajax failed
114					give2CheckoutError( give_twocheckout_js.api_error );
115				} else if ('Unauthorized' === data.errorMsg) {
116					// Incorrect credentials
117					give2CheckoutError( give_twocheckout_js.keys_error );
118				} else if (401 === errorcode) {
119					// Incorrect credit card details.
120					give2CheckoutError( give_twocheckout_js.card_details_error );
121				} else {
122					// Other errors
123					give2CheckoutError( data.errorMsg );
124				}
125			};
126
127			/**
128			 * Token Request
129			 */
130			var tokenRequest = function () {
131				// Setup token request arguments
132				var args = {
133					sellerId: give_twocheckout_js.sellerId,
134					publishableKey: give_twocheckout_js.publishableKey,
135					ccNo: form.find( '.card-number' ).val(),
136					cvv: form.find( '.card-cvc' ).val(),
137					expMonth: form.find( '.card-expiry' ).val().substring( 0, 2 ),
138					expYear: form.find( '.card-expiry' ).val().substring( 5, 7 )
139				};
140				// Make the token request
141				TCO.requestToken( successCallback, errorCallback, args );
142			};
143
144		}
145
146	}
147);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.