Giter Site home page Giter Site logo

openpay-dotnet's Introduction

Openpay NET Build status

This is a client implementing the payment services for Openpay at openpay.mx

Compatibility

  • .Net Framework 4.5 or later

Dependencies

Quick Start

Installation

It is recommended that you use NuGet for install this library. Or you can fork the code and build it.

Configuration

Before use the library will be necessary to set up your Merchant ID and Private key. Use:

OpenpayAPI openpayAPI = new OpenpayAPI(API_KEY, MERCHANT_ID);

Sandbox/Production Mode

By convenience and security, the sandbox mode is activated by default in the client library. This allows you to test your own code when implementing Openpay, before charging any credit card in production environment. Once you have finished your integration, create OpenpayAPI object like this:

Boolean production = true;
OpenpayAPI openpayAPI = new OpenpayAPI(API_KEY, MERCHANT_ID, production);

or use Production property:

OpenpayAPI openpayAPI = new OpenpayAPI(API_KEY, MERCHANT_ID);
openpayAPI.Production = true;

API Services

Once configured the library, you can use it to interact with Openpay API services. All the API services are properties of the OpenpayAPI class.

openpayAPI.CustomerService
openpayAPI.CardService
openpayAPI.BankAccountService
openpayAPI.ChargeService
openpayAPI.TransferService
openpayAPI.PayoutService
openpayAPI.FeeService
openpayAPI.PlanService
openpayAPI.SubscriptionService

Each service has methods to create, get, update, delete or list resources according to the documetation described on http://docs.openpay.mx

Examples

Customers

Create a customer

Customer customer = new Customer();
customer.Name = "Net Client";
customer.LastName = "C#";
customer.Email = "[email protected]";
customer.Address = new Address();
customer.Address.Line1 = "line 1";
customer.Address.PostalCode = "12355";
customer.Address.City = "Queretaro";
customer.Address.CountryCode = "MX";
customer.Address.State = "Queretaro";

Customer customerCreated = openpayAPI.CustomerService.Create(customer);

Get a customer

string customer_id = "adyytoegxm6boiusecxm";
Customer customer = openpayAPI.CustomerService.Get(customer_id);

Delete a customer

string customer_id = "adyytoegxm6boiusecxm";
openpayAPI.CustomerService.Delete(customer.Id);

Update a customer

string customer_id = "adyytoegxm6boiusecxm";
Customer customer = openpayAPI.CustomerService.Get(customer_id);
customer.Name = "My new name";

customer = openpayAPI.CustomerService.Update(customer);

List customers

SearchParams search = new SearchParams();
search.Limit = 50;

List<Customer> customers = openpayAPI.CustomerService.List(search);

Charges

Create a charge

string customer_id = "adyytoegxm6boiusecxm";

ChargeRequest request = new ChargeRequest();
request.Method = "card";
request.SourceId = "kwkoqpg6fcvfse8k8mg2";
request.Description = "Testing from .Net";
request.Amount = new Decimal(9.99);

Charge charge = openpayAPI.ChargeService.Create(customer_id, request);

Capture a charge

string customer_id = "adyytoegxm6boiusecxm";

ChargeRequest request = new ChargeRequest();
request.Method = "card";
request.SourceId = "kwkoqpg6fcvfse8k8mg2";
request.Description = "Testing from .Net";
request.Amount = new Decimal(9.99);
request.Capture = false; //false indicate that only we want capture the amount

Charge charge = openpayAPI.ChargeService.Create(customer_id, request);

Refund a charge

string customer_id = "adyytoegxm6boiusecxm";
string charge_id = "ttcg5roe2py2bur38cx2";

Charge chargeRefunded = openpayAPI.ChargeService.Refund(customer_id, charge.Id, "refund desc");

Create a charge to be paid by bank transfer

string customer_id = "adyytoegxm6boiusecxm";

ChargeRequest request = new ChargeRequest();
request.Method = "bank_account";
request.Description = "Testing from .Net [BankAccount]";
request.Amount = new Decimal(9.99);

Charge charge = openpayAPI.ChargeService.Create(customer_id, request);

Payouts

Currently payouts are only allowed to accounts in Mexico.

Payout to bank account

string customer_id = "adyytoegxm6boiusecxm";
BankAccount bankAccount = new BankAccount();
bankAccount.CLABE = "012298026516924616";
bankAccount.HolderName = "Testing";

PayoutRequest request = new PayoutRequest();
request.Method = "bank_account";
request.BankAccount = bankAccount;
request.Amount = 800.00m;
request.Description = "Payout test";

Payout payout = openpayAPI.PayoutService.Create(customer_id, request);

Payout to debit card

string customer_id = "adyytoegxm6boiusecxm";
Card card = new Card();
card.CardNumber = "4111111111111111";
card.BankCode = "002";
card.HolderName = "Payout User";

PayoutRequest request = new PayoutRequest();
request.Method = "card";
request.Card = card;
request.Amount = 500.00m;
request.Description = "Payout test";

Payout payout = openpayAPI.PayoutService.Create(customer_id, request);

Subscriptions

Create a plan first

Plan plan = new Plan();
plan.Name = "Tv";
plan.Amount = 99.99m;
plan.RepeatEvery = 1;
plan.RepeatUnit = "month";
plan.StatusAfterRetry = "unpaid";
plan.TrialDays = 0;

Plan planCreated = openpayAPI.PlanService.Create(plan);

After you have your plan created, you can subscribe customers to it

string customer_id = "adyytoegxm6boiusecxm";
Card card = new Card();
card.CardNumber = "5243385358972033";
card.HolderName = "John Doe";
card.Cvv2 = "123";
card.ExpirationMonth = "01";
card.ExpirationYear = "14";

Subscription subscription = new Subscription();
subscription.PlanId = planCreated.Id;
subscription.Card = card;
subscription = openpayAPI.SubscriptionService.Create(customer_id, subscription);

Cancel susbscription

string customer_id = "adyytoegxm6boiusecxm";
openpayAPI.SubscriptionService.Delete(customer_id, subscription.Id);

openpay-dotnet's People

Contributors

darkaz avatar eli-lopez avatar guillermo-delucio avatar ismaelem avatar m1slash avatar marcosalvarado avatar mecoronado avatar oswaldopenpay avatar pablogonzalez25 avatar sergioqopenpay avatar thyagodemorais avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.