Addons for frameworks
Springboot
Source files on Github
How to use
To use this library add the jar to your project libraries (it will be added to maven when possible)
There are two ways to configure keys and secrets:
-
By providing your own configuration class like this
import ChargilyEpayClientConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static ChargilyEpayConfigParams.*;
@Configuration
public class ChargilyEpayConfiguration {
@Bean
public ChargilyEpayClientConfig configureChargily(){
ChargilyEpayClientConfig chargilyEpayClientConfig = new ChargilyEpayClientConfig();
chargilyEpayClientConfig.put(BASE_URL, "https://epay.chargily.com.dz");
chargilyEpayClientConfig.put(API_KEY, "your_api_key");
chargilyEpayClientConfig.put(SECRET, "your_secret");
return chargilyEpayClientConfig;
}
}
-
or simply adding by these properties on application.properties file
chargily.epay.apikey=your_api_key
chargily.epay.url=https://epay.chargily.com.dz
chargily.epay.secret=your_secret
then to make a payment simply inject the ChargilyClient in your service
either by constructor or field injection like this (constructor injection is preferred, but I will use field injection just for demo)
public class MyService{
@Autowired
private ChargilyEpayClient client;
public void makePayment(){
InvoiceModel invoice = new InvoiceModel(
"someClient",
"someEmail@mail.com",
"1000",
BigDecimal.valueOf(75.0),
55d,
"https://backurl.com/",
"https://webhookurl.com/",
Mode.CIB,
"a comment"
);
//handle response after you get it as a call back
client.makePayment(invoice, new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
//in case of failure
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
//in case of success
}
});
}
}
Here’s a demo