Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Openpay JavaBuild Status

Java client for Openpay services

This is a client implementing the payment services for Openpay at


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



As of now Java 6 is required.


#### Starting the API ####

OpenpayAPI api = new OpenpayAPI("", 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")
		.countryCode("MX");                  // ISO 3166-1 two-letter code
Customer customer = api.customers().create(new Customer()

#### Charging ####

Charging a credit card:

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

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

Refunding a card charge:

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

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"))

#### 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()
	    .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")

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


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)           

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

Card card = new Card()
		.holderName("Juan Pérez Nuñez")

Subscription subscription = api.subscriptions().create(customer.getId(), new Subscription()
		.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:


You can also cancel the subscription immediately:

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