Last active
June 15, 2020 16:58
-
-
Save PhillipSenn/367c7d8788f50d09ad17 to your computer and use it in GitHub Desktop.
Stripe Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfoutput> | |
<cfinclude template="/Inc/header.cfm"> | |
<h1> Accepting Online Payments With Stripe </h1> | |
<form method="post" action="Stripe2.cfm"> | |
<label for="PersonName">Name:</label> | |
<input id="PersonName" name="PersonName" value="Phillip Senn"> | |
<label for="Email">Email:</label> | |
<input type="email" id="Email" name="Email" value="PhillipSenn@gmail.com"> | |
<label for="amount">amount:</label> | |
<select id="amount" name="amount"> | |
<option value="100">$1.00</option> | |
<option value="200">$2.00</option> | |
<option value="300">$3.00</option> | |
<option value="400">$4.00</option> | |
<option value="500">$5.00</option> | |
</select> | |
<label>Credit Card: | |
<input data-stripe="number" value="4242424242424242"> | |
</label> | |
<label>Expiration: | |
<input data-stripe="exp-month" size="2" value="12"> | |
<input data-stripe="exp-year" size="4" value="2015"> <em>(MM/YYYY)</em> | |
</label> | |
<label>Security Code: | |
<input data-stripe="cvc" value="1234"> | |
</label> | |
<p> | |
<button type="button" name="Save">Purchase!</button> | |
</p> | |
</form> | |
<script src="https://js.stripe.com/v2/"></script> | |
<cfinclude template="/Passwords/Stripe.cfm"> | |
<p hidden id="PublishableKey">#Stripe.PublishableKey#</p> | |
<cfinclude template="/Inc/footer.cfm"> | |
</cfoutput> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stripe.setPublishableKey($('#PublishableKey').text()) | |
dom = {} | |
dom.form = $('form') | |
dom.Save = $('[name=Save]') | |
;(function() { | |
$(document).on('click','[name=Save]',clicked) | |
function clicked() { | |
$(this).prop('disabled',true) | |
Stripe.card.createToken(dom.form,done) // Ask Stripe to create a one time token before truly submitting the form. | |
} | |
function done(status, response) { | |
if (response.error) { | |
dom.form.find('[name=Save]').removeAttr('disabled') // Enabled | |
dom.msg.text(response.error.message).addClass('label-danger') // You must supply either a card, customer, or bank account to create a token. | |
return | |
} | |
dom.form.append($('<input type="hidden" name="card">').val(response.id)) // This returns "tok_..." | |
dom.form.submit() | |
} | |
})(); | |
;(function() { | |
$(document).on('change','[name=PersonName]',changed) | |
function changed() { | |
dom.msg.removeClass('label-info').empty() | |
if ($(this).val().length === 0) { | |
dom.msg.text('Please enter a name').addClass('label-info') | |
dom.Save.prop('disabled',true) | |
} else { | |
dom.Save.prop('disabled',false) | |
} | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
if (!Len(form.PersonName)) { | |
request.msg = 'Custom msg: Please enter your name.'; | |
} | |
if (!isValid('email', form.email)) { | |
request.msg = 'Custom msg: Please enter a valid Email.'; | |
} | |
if (form.amount < 1) { | |
request.msg = 'Custom msg: Please select an amount.'; | |
} | |
if (isDefined('form.card')) { | |
if (NOT Len(form.card)) { | |
request.msg = 'Custom msg: Something went wrong with your credit card information. Please double-check it.'; | |
} | |
} else { | |
request.msg = 'Custom msg: Missing form.card.'; | |
} | |
include '/Passwords/Stripe.cfm'; | |
</cfscript> | |
<cfif (request.msg EQ '')> | |
<cfoutput> | |
#Left(Stripe.mySecretKey,10)#<br> | |
<cfhttp | |
method="post" | |
url="https://api.stripe.com/v1/charges" | |
username="#Stripe.mySecretKey#"> | |
<cfhttpparam type="formfield" name="amount" value="#form.amount#"> <!--- in cents ---> | |
<cfhttpparam type="formfield" name="currency" value="usd"> | |
<cfhttpparam type="formfield" name="card" value="#form.card#"> <!--- This was populated by JavaScript ---> | |
<!--- | |
A description of the transaction to show up in OUR records for tracking purposes. | |
It is considered a good practice to add the Email address here in order to follow up if necessary. | |
---> | |
<cfhttpparam type="formfield" name="description" value="Whatever you want goes here. (Example: #form.email#)"> | |
</cfhttp> | |
</cfoutput> | |
<cfdump var="#cfhttp.fileContent#"> | |
<cfabort> | |
<cfset response = deserializeJSON(cfhttp.fileContent)> | |
</cfif> | |
<cfscript> | |
if (isDefined('response.error')) { | |
request.msg = response.error.message; | |
} | |
if (request.msg != '') { | |
request.mod = 'label-danger'; | |
} | |
</cfscript> | |
<cfoutput> | |
<cfinclude template="/Inc/header.cfm"> | |
<cfif isDefined('response.id')> | |
<table> | |
<tr> | |
<td>response.id</td> | |
<td>#response.id#</td> | |
</tr> | |
<tr> | |
<td>response.object</td> | |
<td>#response.object#</td> | |
</tr> | |
<tr> | |
<td>response.created</td> | |
<td>#response.created#</td> | |
</tr> | |
<tr> | |
<td>response.livemode</td> | |
<td>#response.livemode#</td> | |
</tr> | |
<tr> | |
<td>response.paid</td> | |
<td>#response.paid#</td> | |
</tr> | |
<tr> | |
<td>response.amount</td> | |
<td>#response.amount#</td> | |
</tr> | |
<tr> | |
<td>response.currency</td> | |
<td>#response.currency#</td> | |
</tr> | |
<tr> | |
<td>response.refunded</td> | |
<td>#response.refunded#</td> | |
</tr> | |
<tr> | |
<td>response.captured</td> | |
<td>#response.captured#</td> | |
</tr> | |
<tr> | |
<td>response.balance_transaction</td> | |
<td>#response.balance_transaction#</td> | |
</tr> | |
<tr> | |
<td>response.failure_code</td> | |
<td>#response.failure_code#</td> | |
</tr> | |
<tr> | |
<td>response.description</td> | |
<td>#response.description#</td> | |
</tr> | |
<tr> | |
<td>response.dispute</td> | |
<td>#response.dispute#</td> | |
</tr> | |
<tr> | |
<td colspan="2">response.metadata</td> | |
</tr> | |
<tr> | |
<td>response.receipt_email</td> | |
<td>#response.receipt_email#</td> | |
</tr> | |
<tr> | |
<td>response.receipt_number</td> | |
<td>#response.receipt_number#</td> | |
</tr> | |
</table> | |
<!--- | |
<table> | |
<cfloop from="1" to="#ArrayLen(response.fee_details)#" index="i"> | |
<tr> | |
<td>response.fee_details[#i#].amount</td> | |
<td>#response.fee_details[i].amount#</td> | |
</tr> | |
<tr> | |
<td>response.fee_details[#i#].currency</td> | |
<td>#response.fee_details[i].currency#</td> | |
</tr> | |
<tr> | |
<td>response.fee_details[#i#].type</td> | |
<td>#response.fee_details[i].type#</td> | |
</tr> | |
<tr> | |
<td>response.fee_details[#i#].description</td> | |
<td>#response.fee_details[i].description#</td> | |
</tr> | |
<tr> | |
<td>response.fee_details[#i#].application</td> | |
<td>#response.fee_details[i].application#</td> | |
</tr> | |
<tr> | |
<td>response.fee_details[#i#].amount_refunded</td> | |
<td>#response.fee_details[i].amount_refunded#</td> | |
</tr> | |
</cfloop> | |
</table> | |
---> | |
<table> | |
<tr> | |
<td>response.card.id</td> | |
<td>#response.card.id#</td> | |
</tr> | |
<tr> | |
<td>response.card.object</td> | |
<td>#response.card.object#</td> | |
</tr> | |
<tr> | |
<td>response.card.last4</td> | |
<td>#response.card.last4#</td> | |
</tr> | |
<tr> | |
<td>response.card.brand</td> | |
<td>#response.card.brand#</td> | |
</tr> | |
<tr> | |
<td>response.card.funding</td> | |
<td>#response.card.funding#</td> | |
</tr> | |
<tr> | |
<td>response.card.exp_month</td> | |
<td>#response.card.exp_month#</td> | |
</tr> | |
<tr> | |
<td>response.card.exp_year</td> | |
<td>#response.card.exp_year#</td> | |
</tr> | |
<tr> | |
<td>response.card.fingerprint</td> | |
<td>#response.card.fingerprint#</td> | |
</tr> | |
<tr> | |
<td>response.card.country</td> | |
<td>#response.card.country#</td> | |
</tr> | |
<tr> | |
<td>response.card.address_city</td> | |
<td>#response.card.address_city#</td> | |
</tr> | |
<tr> | |
<td>response.card.cvc_check</td> | |
<td>#response.card.cvc_check#</td> | |
</tr> | |
<tr> | |
<td>response.card.customer</td> | |
<td>#response.card.customer#</td> | |
</tr> | |
</table> | |
</cfif> | |
<cfinclude template="/Inc/footer.cfm"> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment