Java modules to create and handle payments and payment transactions in different payment integration services (providers),
like commercetools Payone Integration Service
.
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
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
Take the dependencies from Maven central
- Add JCenter repositories references in the project
pom.xml
or in common mavensettings.xml
.
- See Setting up Multiple Repositories guide for more details how to configure third party maven repositories.
- 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>
-
Add to
build.sbt
libraryDependencies ++= Seq(
"com.commercetools.payment" % "payone-adapter" % "1.0.0"
)
- 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
}
}
- Add dependencies to project/sub-project settings in
build.gradle
:
dependencies {
compile "com.commercetools.payment:payone-adapter:1.0.0"
}
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);
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))
When the customer clicks "buy" then the shop has to call the createPaymentTransaction method.
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 | ------- |