Last active
January 27, 2016 06:22
-
-
Save chalisegrogan/af65f0b9fa3842ab3fa3 to your computer and use it in GitHub Desktop.
Example v.zero Braintree and ASP.NET Webforms implementation
This file contains hidden or 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
| <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebForm1" %> | |
| <!DOCTYPE html> | |
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <head runat="server"> | |
| <title>Example Braintree + WebForms</title> | |
| <script src="https://js.braintreegateway.com/v2/braintree.js"></script> | |
| <script type="text/javascript"> | |
| $(function() { | |
| braintree.setup("<%=ProcessorToken %>", "dropin", { | |
| container: "braintree-dropin", | |
| form: "Form1" | |
| }); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <form id="form1" runat="server" clientidmode="static"> | |
| <div> | |
| <div id="braintree-dropin" clientidmode="static"></div> | |
| <asp:Button ID="btnSubmit" runat="server" Text="Pay"> | |
| </div> | |
| </form> | |
| </body> | |
| </html> |
This file contains hidden or 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
| Public Class brainz | |
| Inherits System.Web.UI.Page | |
| ' Braintree Processing Necessities | |
| Public ReadOnly Property Gateway() As BraintreeGateway | |
| Get | |
| If _gateway Is Nothing Then | |
| _gateway = New BraintreeGateway() With { _ | |
| Key .Environment = Braintree.Environment.SANDBOX, _ | |
| Key .PublicKey = "123456", _ | |
| Key .PrivateKey = "99999", _ | |
| Key .MerchantId = "ABCDEF" _ | |
| } | |
| End If | |
| Return _gateway | |
| End Get | |
| End Property | |
| Private _gateway As BraintreeGateway | |
| Protected ProcessorToken As String | |
| Protected PaymentNonce As String | |
| Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load | |
| ' Set up the Braintree processor client token | |
| ProcessorToken = Gateway.ClientToken.generate(); | |
| ' Handle Braintree Post back to the page | |
| If IsPostBack Then | |
| Validate() | |
| Pay() | |
| End If | |
| End Sub | |
| Protected Sub Pay() | |
| ' Get the Payment Nonce from the form post | |
| PaymentNonce = Request.Form("payment_method_nonce") | |
| ' Do something with the PaymentNonce | |
| End Sub | |
| Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click | |
| Pay() | |
| End Sub | |
| End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello,, I try your code on my site but it won't work.
I just saw the button pay, and after I clicked that button nothing happened and nothing changed in my sandbox account.
Do you understand how can it happened?
thanks