Skip to content

cmgrey83/Merchello.Plugin.Payment.Braintree

 
 

Repository files navigation

Merchello.Plugin.Payments.Braintree

 // Author: Rusty Swayne
 // Twitter: @rustyswayne

About this package

This Merchello plugin wraps the Braintree .Net SDK library allowing the developer to interact with the Braintree API using Merchello interfaces such as ICustomer and IInvoice. Some responses are likewise returned as Merchello classes such as IPaymentResult where it made sense to do so.

Braintree .Net SDK documentation

 PM> Install-Package Braintree 

Primary Classes

BraintreeProviderSettings

 // Namespace : Merchello.Plugin.Payments.Braintree.Models

The BraintreeProviderSettings class contains the properties and configurations needed by the Braintree .Net SDK to perform requests against the Braintree API. These configurations are set in the Merchello Back Office when you "Active" the gateway provider. Alternatively, you can create a few App_Settings (or whatever) so that you can instantiate the BraintreeApiService in instances where you do not wish to use Braintree as a payment processor but would like to manage subscriptions.

Example

 internal class BraintreeHelper
 {

     public static BraintreeProviderSettings GetBraintreeProviderSettings()
        {
            return new BraintreeProviderSettings()
                            {
                                Environment = Environment.SANDBOX,
                                PublicKey = ConfigurationManager.AppSettings["publicKey"],
                                PrivateKey = ConfigurationManager.AppSettings["privateKey"],
                                MerchantId = ConfigurationManager.AppSettings["merchantId"],
                                MerchantDescriptor = new MerchantDescriptor()
                                    {
                                        Name = ConfigurationManager.AppSettings["merchantName"],
                                        Url = ConfigurationManager.AppSettings["merchantUrl"],
                                        Phone = ConfigurationManager.AppSettings["merchantPhone"]
                                    },
                                DefaultTransactionOption = (TransactionOption)Enum.Parse(typeof(TransactionOption), ConfigurationManager.AppSettings["defaultTransactionOption"])
                            };
        }
 }

BraintreePaymentGatewayProvider

 // Namespace :  Merchello.Plugin.Payments.Braintree.Provider

This is the provider class Merchello uses to process direct payment transactions in the typical checkout work flow.

BraintreeApiService

 // Namespace: Merchello.Plugin.Payments.Braintree.Services

The BraintreeApiService is internally used by the BraintreePaymentGatewayProvider methods but it can be used as a standalone object to perform operations against the Braintree API.

To instantiate the BrainTreeApiService

var braintreeApiService = new BraintreeApiService(BraintreeHelper.GetBraintreeProviderSettings());

This service lazy loads the four API Service wrappers:

Customer Management

// Customer Management
var braintreeCustomerApiService = braintreeApiService.Customer;

Payment Method Management

// Payment Method Management
var paymentMethodApiService = braintreeApiService.PaymentMethod;

Recurring Billing

// Recurring Billing
var subscriptionApiService = braintreeApiService.Subscription;

TransactionProcessing

// Transaction Processing
var transactionApiService = braintreeApiService.Transaction;

Why use the BraintreeApiService and not simply use the Braintree .Net SDK directly?

  • The service allows the developer to directly use some Merchello classes such as ICustomer, IInvoice and IPaymentResult
  • Provides some fault tolerance on API calls, usually returning Umbraco Attempt
  • Logs errors to the Umbraco Log /App_Data/Logs using Umbraco's LogHelper
  • Internally manages HttpRuntimeCache using using the ApplicationContext.Current.ApplicationCache.RuntimeCache

About

A Braintree Payment Gateway Provider for Merchello

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 96.6%
  • HTML 1.5%
  • JavaScript 1.5%
  • Batchfile 0.4%