Manage customer
Submit customer information within your payment.
Customer resource allows you to send information about the customer, like name and address together with your payment. Direct Debit Secured, Unzer Invoice, and Unzer Installment payment methods require customer resource. Customer resource can be stored for using with future payments, refunds, or reversals. In Unzer payment system, a customer resource can be created, fetched, updated and deleted.
Types of customers
There are three different customer types:
- B2C customer
- registered B2B customer
- not-registered B2B customer
Go to Manage customer (API) page to learn more about customer types.
Create a customer
To create a customer:
Request
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Customer customer = new Customer("Max", "Mustermann");
unzer.createCustomer(customer);
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Address billingAddress = new Address();
billingAddress.setName(name)
.setStreet(street)
.setCity(city)
.setState(state)
.setZip(zip)
.setCountry(country);
Address shippingAddress = new Address();
shippingAddress.setName(name)
.setStreet(street)
.setCity(city)
.setState(state)
.setZip(zip)
.setCountry(country);
CompanyInfo companyInfo = new CompanyInfo();
companyInfo.setCommercialRegisterNumber(registrationNumber);
companyInfo.setRegistrationType(CompanyInfo.RegistrationType.REGISTERED);
Customer customer = new Customer("Max", "Mustermann");
customer.setCustomerId(customerId)
.setSalutation(salutation)
.setEmail(eMail)
.setMobile(mobile)
.setBirthDate(birthdate)
.setBillingAddress(billingAddress)
.setShippingAddress(shippingAddress)
.setCompanyData(companyInfo);
unzer.createCustomer(customer);
Response
A customer ID is generated that is later used for fetching transaction data related to the customer. The createCustomer method returns a customer object that contains the ID from the created customer resource. You can access the ID by calling the getId method of the customer object.
customer.getId();
Update customer details
If required, you can also update the customer details. But, the customer ID cannot be updated. To update customer details, call the updateCustomer method of the Unzer class.
Request
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Customer customer = unzer.fetchCustomer("s-cst-xxxxxxxxx");
Customer customerToUpdate = new Customer(customer.getFirstname(), customer.getLastname());
customerToUpdate.setFirstname("Max");
Customer updatedCustomer = unzer.updateCustomer(customer.getId(), customerToUpdate);
Fetch the customer to view the updated fields
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Customer customer = unzer.fetchCustomer("s-cst-xxxxxxxxx");
Delete a customer
You can delete a customer by calling the deleteCustomermethod with the customer ID.
Request
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
String customerId = unzer.deleteCustomer("s-cst-xxxxxxxxx");
When you fetch the customer with that customer ID, you will get an error that the customer does not exist. In the JAVA-SDK this will raise an UnzerApiException that needs to be handled.
Request
try {
Unzer unzer = new Unzer('s-priv-xxxxxxxxxx');
Customer customer = unzer.fetchCustomer('s-cst-xxxxxxxxx');
} catch (HttpCommunicationException e) {
// API returned error resource.
this.log(e->getClientMessage());
this.log(e->getMerchantMessage());
}
Add a customer to a payment
You must link the customer resource to the payment when creating a charge or authorization. Simply add an already existing customer resource (see creating a customer) within the resources object in a payment. For example, during an authorize request:
Request
POST {{domain}}/v1/payments/authorize
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Authorization authorization = unzer.authorize(
BigDecimal.valueOf(200.00),
Currency.getInstance("EUR"),
"s-ppl-xxxxxxxxxx",
new URL("https://your.return.url"),
"s-cst-xxxxxxxxx"
);
You should now see the customerId in the payment response and after calling GET on said payment.
Response
String customerId = authorization.getCustomerId();
After you’ve linked a customer to a payment, the payment workflow will contain the customerId in the resources object, and it is not necessary to link the customer in following transactions.
- authorize > cancel authorize
- authorize > charge > shipment
- authorize > charge > cancel charge
- charge > shipment
- charge > cancel charge
Payment methods with mandatory customer resources
There are 3 different payment methods, which require you to link a customer resource during a payment. You need the customer resource during authorization and charge.
During a charge call:
During an authorize call:
- Unzer Installment
