Git Product home page Git Product logo

openpay-java's Introduction

Openpay JavaBuild Status

Java client for Openpay services

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

Installation

To install, add the following dependency to your pom.xml:

<dependency>
	<groupId>mx.openpay</groupId>
	<artifactId>openpay-api-client</artifactId>
	<version>1.7.0</version>
</dependency>

Compatibility

As of now Java 6 is required.

Examples

#### Starting the API ####

OpenpayAPI api = new OpenpayAPI("https://sandbox-api.openpay.mx", privateKey, merchantId);

#### Creating a customer ####

Address address = new Address()
		.line1("Calle Morelos #12 - 11")
		.line2("Colonia Centro")             // Optional
		.line3("Cuauhtémoc")                 // Optional
		.city("Distrito Federal")
		.postalCode("12345")	
		.state("Queretaro")
		.countryCode("MX");                  // ISO 3166-1 two-letter code
		    
Customer customer = api.customers().create(new Customer()
        .name("John")
        .lastName("Doe")
        .email("[email protected]")
        .phoneNumber("554-170-3567")
        .address(address));

#### Charging ####

Charging a credit card:

Card card = new Card()
		.cardNumber("5555555555554444")          // No dashes or spaces
		.holderName("Juan Pérez Nuñez")         
		.cvv2("422")            
		.expirationMonth(9)
		.expirationYear(14);

Charge charge = api.charges().create(customer.getId(), new CreateCardChargeParams()
		.description("Service charge")
		.amount(new BigDecimal("200.00"))       // Amount is in MXN
		.orderId("Charge0001")                  // Optional transaction identifier
		.card(card));

Refunding a card charge:

Charge refundedCharge = api.charges().refund(customer.getId(), new RefundParams()
		.chargeId(charge.getId()));

Create a charge to be paid by bank transfer:

Charge charge = api.charges().create(customer.getId(), new CreateBankChargeParams()
		.description("Service charge")
		.amount(new BigDecimal("100.00"))
		.orderId("Charge0002"));

#### Payout ####

Currently Payouts are only allowed to accounts in Mexico.

Bank payout:

BankAccount bankAccount = new BankAccount()
		.clabe("032180000118359719")            // CLABE
		.holderName("Juan Pérez")
		.alias("Juan's deposit account");       // Optional

Payout payout = api.payouts().create(customer.getId(), new CreateBankPayoutParams()
	    .bankAccount(bankAccount)
	    .amount(new BigDecimal("150.00"))
	    .description("Payment to Juan")
	    .orderId("Payout00001"));               // Optional transaction identifier

Debit card payout:

Card card = new Card()
        .cardNumber("4111111111111111")         // No dashes or spaces
        .holderName("Juan Pérez Nuñez")
        .bankCode("012");

Payout payout = api.payouts().create(customer.getId(), new CreateCardPayoutParams()
        .card(card)
        .amount(new BigDecimal("150.00"))
        .description("Payment to Juan")
        .orderId("Payout00002"));               // Optional transaction identifier

Subscriptions

Subscriptions allow you to make recurrent charges to your customers. First you need to define a subscription plan:

Plan plan = api.plans().create(new Plan()
		.name("Premium Subscriptions")
		.amount(new BigDecimal("1200.00"))       // Amount is in MXN
		.repeatEvery(1, PlanRepeatUnit.MONTH)           
		.retryTimes(100)
		.statusAfterRetry(PlanStatusAfterRetry.UNPAID));

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

Card card = new Card()
		.cardNumber("5555555555554444")         
		.holderName("Juan Pérez Nuñez")
		.cvv2("422")
		.expirationMonth(9)                  
		.expirationYear(14);

Subscription subscription = api.subscriptions().create(customer.getId(), new Subscription()
		.planId(plan.getId())
		.card(card));      // You can also use withCardId to use a pre-registered card.

To cancel the subscription at the end of the current period, you can update its cancelAtPeriodEnd property to true:

subscription.setCancelAtPeriodEnd(true);
api.subscriptions().update(subscription);

You can also cancel the subscription immediately:

api.subscriptions().delete(customer.getId(), subscription.getId());

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.