.NET

BluePay API .NET Wrapper

About

Emphasis is on easy maintenance and flexibility of code. Using this wrapper you can: process credit cards, reserve an amount (Authorize), issue refunds, void transactions, debit funds from an Authorized transaction you performed in the last ten days.


Integration

There are two pieces of information you will require from BluePay for integration: Account ID (merchant ID) and Secret Key.

All code is under Devbridge.BluePay namespace.

Imports Devbridge.BluePay

Transaction processing

There are four basic transaction types:

  • auth - This transaction type "reserves" funds on the customer's card for later capture.
  • capture - This transaction type debits the funds, reserved earlier by an auth, and causes them to be transferred to the merchant's account. Successful auth guarantees a later capture - if performed within the time limit.
  • sale - This transaction is essentially an auth and a capture in one step and is the transaction type of choice for the majority of our merchants.
  • refund - The concept of a refund is to reverse an earlier capture or sale. A refund may also be referred to as a return or credit. This means the customer's card was debited, and then a separate transaction will need to be run that transfers the money back onto the customer's card.

Every transaction starts by initializing BluePay2Request instance and setting up required values.

Dim merchantId = ConfigurationManager.AppSettings("BluePayMerchantId")
Dim serviceKey = ConfigurationManager.AppSettings("BluePayServiceKey")
Dim bpApi = New BluePay2Request(merchantId, serviceKey)
bpApi.TransactionType = "AUTH"
'Setup request values ... 

After all needed values hav been set, call process the request. Process returns BluePay2Response object that contains response values from BluePay. Returned TransactionId is a unique identifier for each transaction that is returned by BluePay and is required when processing CAPTURE or REFUND transactions.

Dim bpResponse = bpApi.Process()
Dim transactionId = bpApi.TransactionId
Dim status = bpResponse.Result & ": " & bpResponse.Message 

Process credit card - Sample Code

Private Sub ProcessCreditCard()
  Dim merchantId = ConfigurationManager.AppSettings("BluePayMerchantId")
  Dim serviceKey = ConfigurationManager.AppSettings("BluePayServiceKey")
  Dim bpApi = New BluePay2Request(merchantId, serviceKey)
  bpApi.TransactionType = "SALE"
  bpApi.Name = "John Doe"
  bpApi.CardNumber = "1111222233334444"
  bpApi.CardExpiration = "0312" 'MMYY
  bpApi.CardCvv2 = "325"
  bpApi.Address1 = "517 Nobles Rd"
  bpApi.Address2 = "Suite 302"
  bpApi.City = "Chicago"
  bpApi.State = "IL"
  bpApi.ZipCode = "60656"
  bpApi.Country = "US"
  bpApi.Phone = "8001112222"
  bpApi.Email = "jdoe@company.com"
  bpApi.OrderId = "25" 'Your internal order number
  bpApi.Amount = 10.99D
  bpApi.AmountTax = 0.98D
  bpApi.CustomId = "1" 'Internal customer ID
  'Verify if all values have been set....
  Dim bpResponse = bpApi.Process()
  Dim transactionId = bpApi.TransactionId
  Dim status = bpResponse.Result & ": " & bpResponse.Message
  If bpResponse.Approved Then
  'Transaction has been approved.
  'TODO: complete order processing
  Else
  'Transaction denied
  'TODO: notify customer by showing status
  End If
End Sub

Issue refund - Sample Code

Private Sub IssueRefund(ByVal originalTransactionId As String, ByVal amount As Decimal)
  Dim merchantId = ConfigurationManager.AppSettings("BluePayMerchantId")
  Dim serviceKey = ConfigurationManager.AppSettings("BluePayServiceKey")
  Dim bpApi = New BluePay2Request(merchantId, serviceKey)
  bpApi.TransactionType = "REFUND"
  bpApi.Amount = amount 'Amount to refund
  bpApi.TransactionId = originalTransactionId
  Dim bpResponse = bpApi.Process()
  If bpResponse.Approved Then
  'Transaction has been approved.
  'TODO: mark order as refunded.
  Else
  'Transaction denied
  'TODO: handle failure
  End If
End Sub

What is Sourcery?

All of these components are Open Source.