The code example is written in Java. It describes the steps required to perform authentication with the CCBill API and the payment token obtained using the CCBill API Payment Widget to perform the charge by payment token action (non-3DSecure and 3DSecure versions). This script covers the backend portion of the integration with the CCBill's RESTful Transaction API.
1. Install Dependencies
Add the dependencies for building and importing the libraries. For example, if using Maven, you need a pom.xml file that lists all the dependencies with version numbers you want to use:
The endpoints section defines the API endpoints you will use throughout the process.
The example uses three endpoints to demonstrate the charge flow:
1. getAuthToken allows requesting the CCBill Auth (Bearer) token required for authentication in subsequent operations.
2. createTransactionallows performing a non-3DSecured charge transaction using the payment token.
3. createThreedsTransactionallows performing a 3DSecured charge transaction using the payment token and previously obtained SCA parameters.
3. Provide Client Credentials
Set your Merchant Application ID as the value of username, and the Merchant Secret as the value of password.
The example code will set theaccess_tokenvalue when the script executes.
4. Add Data
Provide the appropriate data for the request. To create a charge, the following parameters are obtained using the payment widget:
1. The paymentToken previously obtained using the payment widget. Ensure the client's IP address is added as a payload (ipAddress) or header (X-Origin-IP) parameter.
2. TransactionRequestParams, including the client account number, subaccount, the initial price, and period.
3. If using 3DS, provide the ThreedsTransactionRequestParams previously obtained using the payment widget.
5. Generate OAuth Token
Create a function to fetch the OAuth token (getAuthToken). The function requires the username, password, and token endpoint to request the token.
The token helps authenticate the payment requests.
6. Charge Transaction and Handle Response
ThecreateTransactionand createThreedsTransaction functions perform the charge based on the provided endpoint, data, payment token, and generated access token.
If calling the functions throws no errors, the response is passed to the TransactionResponse function.
In this case, it only logs the response data. In a realistic scenario, it would allow you to continue processing the transaction and return the response to your client.
7. Test Transaction
The code fetches the OAuth token based on the previously provided data.
If the access token is generated successfully, the code performs a non-3DS transaction and then a 3DSecure transaction using the previously obtained SCA and other transaction data.