Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header class="w3-container w3-teal">
		<h1>GreenPay Widget Example</h1>
	</header>

	<div class="w3-container w3-blue">
		<h2> 1- Widget no modal</h2>
		<article class="w3-container" id= "widgetNoModal"> 
		</article>
		<h2> 2- Widget modal</h2>
		</div>
			<div class="modal fade" id="myModal" role="dialog">
			<div class="modal-dialog">

				<!-- Modal content-->
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">&times;</button>
						<h4 class="modal-title">GreenPay Payment</h4>
					</div>
					<div class="modal-body" id="AreaPagoGreenPay">
						<!-- <div gpsession="" gptoken="" environment="production or sandbox"></div> -->
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					</div>
			</div>

		</div>
	</div>
	<button type="button" class="btn btn-success btn-md" id="myBtn">Show Widget Modal (show:true)</button>
	</body>

              
            
!

CSS

              
                .cardform{
	background: #efefef;
	width: auto;
}

.btnPay{
	background: gray;
	color: white;
}

.cardform input{
	background-color: white;
	border: 1px solid #ccc;
}
              
            
!

JS

              
                $(document).ready(function () {
			var order = {
    secret: "NTJFRDE2RThFMUZCQTQ1MTJGNzIwMjUxNTdDMUMwNkI3MDJBQ0Y0QkIzQkNBNEVENUY0RTU2NjI0OTExOTFBQ0QxMjc5QzZDMzcxOTdDOEE5OUVGNENFNTU4QTFFNkUzOERDOTAwMEI3NjZDMEU1RjY5RTU2MjBBNjEzNEE5QzA=",
    merchantId: "f22c73c3-dd85-4827-be65-66225aa1907f",
    terminal: "PluginsDev-BNCR-Colones",
    amount: Math.floor(Math.random() * (+100000 - +1000)) + +100,
    currency: "CRC",
    description: "Modal checkout example",
    orderReference: "MCE-" + Math.floor(Math.random() * (+100000 - +1000)) + +100,
    additional: {
        customer: {
            name: "User Example",
            email: "TEST@DECLINE.COM",
            billingAddress: {
                country: "CR",
                province: "San José",
                city: "Curridabat",
                street1: "Freses"
            },
            shippingAddress: {
                country: "CR",
                province: "San José",
                city: "Curridabat",
                street1: "Frese"
            }
        },
        products: [{
            description: "Descripción de producto",
            skuId: "Identificador único en el comercio",
            quantity: 1,
            price: 100.00,
            type: "Tipo de producto"
        }]
    }
}
			//Show widget no modal
			postData("#widgetNoModal", order)

			// Show modal
			$("#myBtn").on("click", function () {
				postData("#AreaPagoGreenPay", order)
			});
		});

		//Add the div element with the checkout order data
function insertHtml(elementId, data) {
	console.log(data);
	$(elementId).html(
		`<div id="gpSecuurity" gpsession=${data.session} gptoken=${data.token} environment="sandbox"></div >`
	);
}

		//Creates the checkout order (This must be executed from backend to prevent expose your GreenPay API credentials)
		const postData = (elementId, order) => {
			return axios.post("https://sandbox-merchant.greenpay.me", order, {
				headers: {
					'Accept': 'application/json',
					'Content-Type': 'application/json'
				}
			}).then((data) => {
				//console.log("data",data.data);

				insertHtml(elementId, data.data);

				if (elementId === "#AreaPagoGreenPay") {
					$("#myModal").modal({
						show: true
					});
				}

				loadWidget();
			}).catch(error => console.error(error));
		}

		//Loads the widget code
		function loadWidget() {
			//TODO
			/**
			 * Make a call to your backed to create a payment order
			 * Wait to get the response obtained in your backenk.
			 * Update gpsession and gptoken element values with the response got it in your backend
			*/
			var script = document.createElement("script");
			script.src = "https://widget.greenpay.me/1.4.1/gpwidget.min.js";
			script.type = "text/javascript";
			document.body.parentNode.appendChild(script);

		}

		//Shows in the console the checkout response received
		function greenPayResponse(id, res) {
			//Add your logic
			if (res.status == "200") {
				//Response is OK, someting payed
				console.log("payed", JSON.stringify(res, null, 2))
			} else {
				//An ERROR ocurred
				console.log("error", JSON.stringify(res))
			}
		}

              
            
!
999px

Console