Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Latest commit

 

History

History
171 lines (123 loc) · 7.01 KB

File metadata and controls

171 lines (123 loc) · 7.01 KB

Commercetools Payment Integration Java

Build Status

Java modules to create and handle payments and payment transactions in different payment integration services (providers), like commercetools Payone Integration Service.

General Info

This projects provides collection of utils which supports payment integrations based on intermediary services like Payone Integration Service.

The checkout process in the shop can follow a standardized process via this module, even if different Payment Service Providers are used. At the moment only PayOne is supported

The shop has to provide a sphere client for all action this module

Build

Create JAR files: ./gradlew clean jar

Create JAR files and test: ./gradlew clean check

(Recommended) Full build with tests, but without install to maven local repo: ./gradlew clean build

Install to local maven repo: ./gradlew clean install

For more info about build and publish process see BUILD documentation

Project configuration:

Take the dependencies from Maven central

Maven

  1. Add JCenter repositories references in the project pom.xml or in common maven settings.xml.
  1. When the repositories are configure, add the payment dependencies:
  <dependencies>
    <dependency>
      <groupId>com.commercetools.payment</groupId>
      <artifactId>payone-adapter</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>

SBT

  1. Configure JCenter repositories

  2. Add to build.sbt

  libraryDependencies ++= Seq(
    "com.commercetools.payment" % "payone-adapter" % "1.0.0"
 )

Gradle

  1. Add dependencies repositories into the head of build.gradle (note, you are not obligated to add all of them):
  repositories {
    mavenCentral()
    jcenter()
    maven {
        url  "http://dl.bintray.com/commercetools/maven" // usually used only for developers to test non-stable not published versions
    }
  }
  1. Add dependencies to project/sub-project settings in build.gradle:
  dependencies {
    compile "com.commercetools.payment:payone-adapter:1.0.0"
  }

Usage

List available payment methods

Get all payment methods:

final List<PaymentMethodInfo> = paymentAdapterService.findAvailablePaymentMethods();

Get filtered payment methods: (Example to get Free and only Free if TotalPrice is zero):

final Function<List<PaymentMethodInfo>,List<PaymentMethodInfo> filter =
    list -> {
        if (cart.getTotalPrice().isZero()) {
            return list.stream().filter(pmi -> "FREE".equals(pmi.getMethod())).collect(Collectors.toList());
        } else {
            return list.stream().filter(pmi -> !"FREE".equals(pmi.getMethod())).collect(Collectors.toList());
        }
    }
final List<PaymentMethodInfo> = paymentAdapterService.findAvailablePaymentMethods(filter);

Create payment object

In order to persist selected payment method in CTP use createPayment(CreatePaymentData data) method

Different payment methods require different additional values (i.e. successUrl etc.)

Example:

private static final String REDIRECT_URL = "redirectUrl";
private static final String SUCCESS_URL = "successUrl";
private static final String CANCEL_URL = "cancelUrl";
private SphereClient sphereClient;


paymentAdapterService.createPayment(
    CreatePaymentDataBuilder.of(sphereClient, selectedPaymentMethod, cart, orderNumber)
        .configValue(SUCCESS_URL, calculateSuccessURL(cart))
        .configValue(ERROR_URL, calculateErrorURL(cart))
        .configValue(CANCEL_URL, calculateCancelURL(cart))

Creating the PaymentTransaction

When the customer clicks "buy" then the shop has to call the createPaymentTransaction method.

Supported payment methods

Following payment methods are supported

payment provider payment method explanation required parameters
PAYONE CREDIT_CARD Creditcard 3x URLs PseudoPan & TrunctatedcardPan
PAYONE WALLET-PAYPAL Paypal 3x URLs
PAYONE WALLET-PAYDIREkT Paydirekt 3x URLs
PAYONE BANK_TRANSFER-SOFORTUEBERWEISUNG Sofortüberweisung 3x URLs
PAYONE BANK_TRANSFER-IDEAL Ideal 3x URLs & bankGroupType
PAYONE BANK_TRANSFER-BANCONTACT Bancontact 3x URLs
PAYONE BANK_TRANSFER-POSTFINANCE_EFINANCE Postfinance E-Finance 3x URLs
PAYONE BANK_TRANSFER-POSTFINANCE_CARD Postfinance Card 3x URLs
PAYONE BANK_TRANSFER-ADVANCE Prepayment -------
INTERNAL FREE for zero money payments -------