SHASHANGKA SHEKHAR'S BLOG

Author, TechWriter

BraintreePayment-ASP.Net Core2.1

Hits: 910

In this post, we are going to implement braintree payment gateway with Asp.net Core 2.1. Based on previous post this article is extended to implement payment gateway. We are going to modify/extend existing sample application by downloading full source code from github.

Let’s get started by opening the existing application, first of all we are going to add Braintree package. Go to NuGet to install Braintree .NET Client Library which is supported by both .NET Framework, .NET Core.

Configuration: This is where we configured the environment, merchant with API key for Braintree.

Payments Controller: 

Generate Client-Token: Initially HttpGet method named GenerateToken get called to generate client-token for authorization to initialize client UI.

Create Transaction: Finally transaction is done with Amount and PaymentMethodNonce which is payment authorization for customer generated by client script.

Finally the full Payments Controller.

Html View:

In index.html we need to add drop-in library reference.

Below code snippet is where(<div id=”dropin”></div>) to render Drop-in UI in payment.html where user can input card information. After providing valid card information, checkout action is performed by clicking on Checkout button.

AngularJS Controller:

Get client token:  To create dropin UI we need to provide client-token generated by server for authorization.

Request Payment Method: This is where client request for payment method information(PaymentMethodNonce), later PaymentMethodNonce will use in server to charge a card.

Finally the full Client Script.

Testing:  Ready-made payment Drop-in UI

Test Card No: 378282246310005 or 4111111111111111

After successful transaction below screen will appear.

Braintree: As we can see the list of transaction in Braintree.

Downloads: 

I’ve uploaded the full source code to download/clone @github, Thanks 🙂

References:

  • https://developers.braintreepayments.com/start/hello-client/javascript/v3
  • https://developers.braintreepayments.com/start/hello-server/dotnet
  • https://github.com/braintree/braintree_aspnet_example

Post a comment