Connect2pay Java Client

This is the Java implementation of the PayXpert Connect2pay Payment Page API.

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.payxpert
ArtifactId

ArtifactId

connect2pay-client
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Connect2pay Java Client
This is the Java implementation of the PayXpert Connect2pay Payment Page API.
Project URL

Project URL

https://www.payxpert.com/
Source Code Management

Source Code Management

https://github.com/PayXpert/connect2pay-java-client/tree/master

Download connect2pay-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.payxpert/connect2pay-client/ -->
<dependency>
    <groupId>com.payxpert</groupId>
    <artifactId>connect2pay-client</artifactId>
    <version>2.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.payxpert/connect2pay-client/
implementation 'com.payxpert:connect2pay-client:2.0.1'
// https://jarcasting.com/artifacts/com.payxpert/connect2pay-client/
implementation ("com.payxpert:connect2pay-client:2.0.1")
'com.payxpert:connect2pay-client:jar:2.0.1'
<dependency org="com.payxpert" name="connect2pay-client" rev="2.0.1">
  <artifact name="connect2pay-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.payxpert', module='connect2pay-client', version='2.0.1')
)
libraryDependencies += "com.payxpert" % "connect2pay-client" % "2.0.1"
[com.payxpert/connect2pay-client "2.0.1"]

Dependencies

compile (6)

Group / Artifact Type Version
commons-codec : commons-codec jar 1.15
ch.qos.logback : logback-classic jar 1.2.3
com.ning : async-http-client jar 1.9.40
com.fasterxml.jackson.core : jackson-core jar 2.11.2
com.fasterxml.jackson.core : jackson-databind jar 2.11.2
net.sf.oval : oval jar 1.90

test (4)

Group / Artifact Type Version
junit : junit jar 4.13
com.sun.activation : javax.activation jar 1.2.0
org.mockito : mockito-core jar 2.28.2
org.jsoup : jsoup jar 1.12.1

Project Modules

There are no modules declared in this project.

Connect2Pay Payment Page Java Client

This is the Java implementation of the Connect2pay Payment Page API.

The main class to use is Connect2payClient that implements all the API calls.
It requires request object as entries and returns response objects.

Example of a payment creation with user redirection:

import com.payxpert.connect2pay.client.containers.Account;
import com.payxpert.connect2pay.client.containers.Order;
import com.payxpert.connect2pay.client.containers.Shipping;
import com.payxpert.connect2pay.client.containers.Shopper;
import com.payxpert.connect2pay.client.requests.PaymentRequest;
import com.payxpert.connect2pay.constants.PaymentMode;
import com.payxpert.connect2pay.constants.sca.ShippingType;
import com.payxpert.connect2pay.constants.sca.ShopperAccountAge;
import com.payxpert.connect2pay.constants.sca.ShopperAccountLastChange;

class TestPayment {
  public void processPayment() {
    // Process a payment of €39.99
    PaymentRequest request = new PaymentRequest();
    request.setCurrency("EUR").setAmount(3999);
    request.setPaymentMode(PaymentMode.SINGLE);
    // User will be redirected here when clicking on "Go back to merchant" button
    request.setCtrlRedirectURL("http://my.website/somewhere");
    // The payment page will do a callback on this URL after the payment is processed
    request.setCtrlCallbackURL("http://my.website/payment-callback");

    Order order = new Order();
    order.setId("1234ABCD").setShippingType(ShippingType.DIGITAL_GOODS);
    Shopper shopper = new Shopper();
    shopper.setEmail("[email protected]").setFirstName("John").setLastName("Doe")
        .setHomePhonePrefix("47").setHomePhone("123456789").setAddress1("Main Street 41")
        .setZipcode("123456").setCity("London").setCountryCode("GB");
    Account account = new Account();
    account.setAge(ShopperAccountAge.BETWEEN_30_60_DAYS).setSuspicious(false)
        .setLastChange(ShopperAccountLastChange.BETWEEN_30_60_DAYS);
    shopper.setAccount(account);
    Shipping shipping = new Shipping();
    shipping.setName("Jane Doe").setAddress1("Other Street, 54").setCity("London")
        .setZipcode("654321").setCountryCode("GB");

    request.setOrder(order);
    request.setShopper(shopper);
    request.setShipping(shipping);

    // Validate the request
    try {
      request.validate();
    } catch (BadRequestException e) {
      logger.error("Ooops, an error occurred validating the payment request: " + e.getMessage());
      // Handle the error...
    }

    // Instantiate the client and send the prepare request
    // Second argument is the originator ID, third one is the associated API key
    Connect2payClient c2p = new Connect2payClient("https://provided.url", "123456", "GreatP4ssw0rd");
    PaymentResponse response = null;
    try {
      response = c2p.preparePayment(request);
    } catch (Exception e) {
      logger.error("Ooops, an error occurred preparing the payment: " + e.getMessage());
      // Handle the error...
    }

    if (response != null && ResultCode.SUCCESS.equals(response.getCode())) {
      // Get the URL to redirect the user to
      String redirectURL = response.getCustomerRedirectURL();
      if (redirectURL != null) {
        // Redirect the user towards this URL, this will display the payment page
      }
    } else {
      // Handle the failure
    }
  }
}

Example of the payment callback handling:

import java.io.OutputStream;

class TestPayment {
  private OutputStream out;

  public void handleCallback(String request) {
    // Instantiate the client and handle the callback
    Connect2payClient c2p = new Connect2payClient("https://provided.url", "123456", "GreatP4ssw0rd");
    PaymentStatusResponse response = null;
    try {
      // Request is either the body of the received request as a string or an InputStream pointing to the received body
      response = c2p.handleCallbackStatus(request);
    } catch (Exception e) {
      logger.error("Ooops, an error occurred handling the callback: " + e.getMessage());
      // Handle the error...
    }

    if (response != null && ResultCode.SUCCESS.equals(response.getCode())) {
      // Check the payment status: 000 means success
      if ("000".equals(response.getErrorCode())) {
        // Handle the payment success case
        // ...
        // Access the payment mean information
        CreditCardPaymentMeanInfo pmInfo = response.getCCPaymentMeanInfo();
        logger.info("Successful payment done by " + pmInfo.getCardHolderName() + "with card " + pmInfo.getCardNumber());
      } else {
        // Handle the payment failure case
      }

      if (handledSuccessfully) {
        this.out.write(CallbackStatusResponse.getDefaultSuccessResponse().toJson()); // out is the output stream
      } else {
        this.out.write(CallbackStatusResponse.getDefaultFailureResponse().toJson()); // out is the output stream
      }
    } else {
      // Handle the failure
      this.out.write(CallbackStatusResponse.getDefaultFailureResponse().toJson()); // out is the output stream
    }
  }
}
com.payxpert

PayXpert

Expert in Payment Processing solution

Versions

Version
2.0.1
2.0.0
1.0.20
1.0.19
1.0.14
1.0.13