提交 56bb9d7c authored 作者: Whispa's avatar Whispa

commit commit

上级 efab0723
......@@ -19,106 +19,147 @@ import static com.example.afrishop_v3.config.Encryption.getKey;
/**
*
* @author Theresa
*/
public class CardCharge {
JSONObject api=new JSONObject();
Endpoints ed=new Endpoints();
JSONObject api = new JSONObject();
Endpoints ed = new Endpoints();
ApiConnection apiConnection;
Encryption e=new Encryption();
private String cardno,cvv,expirymonth,expiryyear,currency,country,pin,suggested_auth,
amount,email,phonenumber,firstname,lastname,txRef,redirect_url,device_fingerprint,IP,
Encryption e = new Encryption();
private String cardno, cvv, expirymonth, expiryyear, currency, country, pin, suggested_auth,
amount, email, phonenumber, firstname, lastname, fullname, txRef, redirect_url, device_fingerprint, IP,
charge_type;
private String transactionreference,otp, authUrl;
private String transactionreference, otp, authUrl;
public void setFullname(String fullname) {
this.fullname = fullname;
}
/**
*
* @return JSONObject
*/
*
* @return JSONObject
*/
public JSONObject setJSON() {
JSONObject json=new JSONObject();
try{
json.put("cardno", this.getCardno());
json.put("cvv", this.getCvv());
json.put("currency", this.getCurrency());
json.put("country", this.getCountry());
json.put("amount", this.getAmount());
json.put("expiryyear", this.getExpiryyear());
json.put("expirymonth", this.getExpirymonth());
json.put("email", this.getEmail());
json.put("IP", this.getIP());
json.put("txRef", this.getTxRef());
json.put("device_fingerprint", this.getDevice_fingerprint());
// json.put("pin", this.getPin());
//json.put("suggested_auth", this.getSuggested_auth());
json.put("firstname", this.getFirstname());
json.put("lastname", this.getLastname());
json.put("redirect_url", this.getRedirect_url());
json.put("charge_type", this.getCharge_type());
}catch( JSONException ex){ex.getMessage();}
public JSONObject setJSON() {
JSONObject json = new JSONObject();
try {
json.put("cardno", this.getCardno());
json.put("cvv", this.getCvv());
json.put("currency", this.getCurrency());
json.put("country", this.getCountry());
json.put("amount", this.getAmount());
json.put("expiryyear", this.getExpiryyear());
json.put("expirymonth", this.getExpirymonth());
json.put("email", this.getEmail());
json.put("IP", this.getIP());
json.put("txRef", this.getTxRef());
json.put("device_fingerprint", this.getDevice_fingerprint());
// json.put("pin", this.getPin());
//json.put("suggested_auth", this.getSuggested_auth());
json.put("firstname", this.getFirstname());
json.put("lastname", this.getLastname());
json.put("redirect_url", this.getRedirect_url());
json.put("charge_type", this.getCharge_type());
} catch (JSONException ex) {
ex.getMessage();
}
return json;
}
}
private JSONObject getPhoneJSON() {
JSONObject json = new JSONObject();
try {
json.put("txRef", this.getTxRef());
json.put("amount", this.getAmount());
json.put("currency", this.getCurrency());
json.put("network", "MTN");
json.put("email", this.getEmail());
json.put("phone_number", this.getPhonenumber());
json.put("fullname", this.getFullname());
} catch (JSONException ex) {
ex.getMessage();
}
return json;
}
public JSONObject chargeMasterAndVerveCard() throws JSONException {
JSONObject json= setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY);
json.put("pin",this.getPin() );
json.put("suggested_auth",this.getSuggested_auth() );
JSONObject json = setJSON();
String message= json.toString();
json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("pin", this.getPin());
json.put("suggested_auth", this.getSuggested_auth());
String encrypt_secret_key=getKey(RaveConstant.SECRET_KEY);
String client= encryptData(message,encrypt_secret_key);
Charge ch=new Charge();
String message = json.toString();
String encrypt_secret_key = getKey(RaveConstant.SECRET_KEY);
String client = encryptData(message, encrypt_secret_key);
Charge ch = new Charge();
return ch.charge(client,ed.getChargeEndPoint());
return ch.charge(client);
}
public JSONObject chargeMasterAndVerveCard(boolean polling) {
JSONObject json= setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY);
json.put("pin",this.getPin() );
json.put("suggested_auth",this.getSuggested_auth() );
Polling p=new Polling();
JSONObject json = setJSON();
json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("pin", this.getPin());
json.put("suggested_auth", this.getSuggested_auth());
Polling p = new Polling();
return p.handleTimeoutCharge(json);
}
public JSONObject chargeVisaAndIntl() throws JSONException {
JSONObject json= setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url() );
JSONObject json = setJSON();
json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url());
String message= json.toString();
String message = json.toString();
String encrypt_secret_key=getKey(RaveConstant.SECRET_KEY);
String client= encryptData(message,encrypt_secret_key);
String encrypt_secret_key = getKey(RaveConstant.SECRET_KEY);
String client = encryptData(message, encrypt_secret_key);
Charge ch=new Charge();
Charge ch = new Charge();
return ch.charge(client,ed.getChargeEndPoint());
return ch.charge(client);
}
public JSONObject chargeVisaAndIntl(boolean polling) throws JSONException {
JSONObject json= setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url() );
Polling p=new Polling();
public JSONObject chargeMobileMoney() throws JSONException {
JSONObject json = getPhoneJSON();
json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url());
String message = json.toString();
String encrypt_secret_key = getKey(RaveConstant.SECRET_KEY);
String client = encryptData(message, encrypt_secret_key);
Charge ch = new Charge();
return ch.charge(client,ed.getChargeMobileEndpoint());
}
public JSONObject chargeVisaAndIntl(boolean polling) throws JSONException {
JSONObject json = setJSON();
json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url());
Polling p = new Polling();
return p.handleTimeoutCharge(json);
}
......@@ -128,33 +169,35 @@ public class CardCharge {
* @return JSONObject
*/
public JSONObject validateCardCharge(){
Charge vch= new Charge();
public JSONObject validateCardCharge() {
Charge vch = new Charge();
return vch.validateCardCharge(this.getTransactionreference(), this.getOtp());
}
//if timeout
public JSONObject validateCardCharge(boolean polling){
Polling p=new Polling();
public JSONObject validateCardCharge(boolean polling) {
Polling p = new Polling();
return p.validateCardChargeTimeout(this.getTransactionreference(), this.getOtp());
}
/*
if AuthMode::"VBSECURE"or "AVS_VBVSECURECODE"
@params authUrl This requires that you copy the authurl returned in the response
and paste it in the argument and it opens a small window for card validation
*/
public void validateCardChargeVB(){
if (Desktop.isDesktopSupported()) {
try{
Desktop.getDesktop().browse(new URI(this.getAuthUrl()));
}catch(URISyntaxException | IOException ex){}
public void validateCardChargeVB() {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI(this.getAuthUrl()));
} catch (URISyntaxException | IOException ex) {
}
}
}
/**
* @return the cardno
......@@ -165,11 +208,11 @@ public class CardCharge {
/**
* @param cardno the cardno to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setCardno(String cardno) {
this.cardno = cardno;
return this;
}
......@@ -182,11 +225,11 @@ public class CardCharge {
/**
* @param cvv the cvv to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setCvv(String cvv) {
this.cvv = cvv;
return this;
}
......@@ -199,11 +242,11 @@ public class CardCharge {
/**
* @param expirymonth the expirymonth to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setExpirymonth(String expirymonth) {
this.expirymonth = expirymonth;
return this;
}
......@@ -216,11 +259,11 @@ public class CardCharge {
/**
* @param expiryyear the expiryyear to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setExpiryyear(String expiryyear) {
this.expiryyear = expiryyear;
return this;
}
......@@ -233,11 +276,11 @@ public class CardCharge {
/**
* @param currency the currency to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setCurrency(String currency) {
this.currency = currency;
return this;
}
......@@ -250,11 +293,11 @@ public class CardCharge {
/**
* @param country the country to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setCountry(String country) {
this.country = country;
return this;
}
......@@ -267,11 +310,11 @@ public class CardCharge {
/**
* @param pin the pin to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setPin(String pin) {
this.pin = pin;
return this;
}
......@@ -284,11 +327,11 @@ public class CardCharge {
/**
* @param suggested_auth the suggested_auth to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setSuggested_auth(String suggested_auth) {
this.suggested_auth = suggested_auth;
return this;
}
......@@ -301,11 +344,11 @@ public class CardCharge {
/**
* @param amount the amount to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setAmount(String amount) {
this.amount = amount;
return this;
}
......@@ -318,11 +361,11 @@ public class CardCharge {
/**
* @param email the email to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setEmail(String email) {
this.email = email;
return this;
}
......@@ -333,13 +376,17 @@ public class CardCharge {
return phonenumber;
}
public String getFullname() {
return fullname;
}
/**
* @param phonenumber the phonenumber to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
return this;
}
......@@ -352,11 +399,11 @@ public class CardCharge {
/**
* @param firstname the firstname to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setFirstname(String firstname) {
this.firstname = firstname;
return this;
}
......@@ -369,11 +416,11 @@ public class CardCharge {
/**
* @param lastname the lastname to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setLastname(String lastname) {
this.lastname = lastname;
return this;
}
......@@ -386,11 +433,11 @@ public class CardCharge {
/**
* @param IP the IP to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setIP(String IP) {
this.IP = IP;
return this;
}
......@@ -403,11 +450,11 @@ public class CardCharge {
/**
* @param txRef the txRef to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setTxRef(String txRef) {
this.txRef = txRef;
return this;
}
......@@ -420,11 +467,11 @@ public class CardCharge {
/**
* @param redirect_url the redirect_url to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setRedirect_url(String redirect_url) {
this.redirect_url = redirect_url;
return this;
}
......@@ -437,11 +484,11 @@ public class CardCharge {
/**
* @param device_fingerprint the device_fingerprint to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setDevice_fingerprint(String device_fingerprint) {
this.device_fingerprint = device_fingerprint;
return this;
}
......@@ -454,11 +501,11 @@ public class CardCharge {
/**
* @param charge_type the charge_type to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setCharge_type(String charge_type) {
this.charge_type = charge_type;
return this;
}
......@@ -471,11 +518,11 @@ public class CardCharge {
/**
* @param transaction_reference the transaction_reference to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setTransactionreference(String transaction_reference) {
this.transactionreference= transaction_reference;
this.transactionreference = transaction_reference;
return this;
}
......@@ -488,11 +535,11 @@ public class CardCharge {
/**
* @param otp the otp to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setOtp(String otp) {
this.otp = otp;
return this;
}
......@@ -505,11 +552,11 @@ public class CardCharge {
/**
* @param authUrl the authUrl to set
* @return CardCharge
* @return CardCharge
*/
public CardCharge setAuthUrl(String authUrl) {
this.authUrl = authUrl;
return this;
}
}
......@@ -27,8 +27,8 @@ public class Charge {
//for all charges
public JSONObject charge(String client){
this.apiConnection = new ApiConnection(ed.getChargeEndPoint());
public JSONObject charge(String client,String endpoint){
this.apiConnection = new ApiConnection(endpoint);
String alg="3DES-24";
......
......@@ -16,6 +16,7 @@ public class Endpoints {
String url;
public String BANK_ENDPOINT;
public static String CHARGE_ENDPOINT;
public static String CHARGE_MOBILE_ENDPOINT;
public static String CARD_VALIDATE_ENDPOINT;
public static String ACCOUNT_VALIDATE_ENDPOINT;
public static String TIMEOUT_ENDPOINT;
......@@ -47,6 +48,7 @@ public class Endpoints {
BANK_ENDPOINT= url+"flwv3-pug/getpaidx/api/flwpbf-banks.js?json=1";
CHARGE_ENDPOINT =url+"flwv3-pug/getpaidx/api/charge";
CHARGE_MOBILE_ENDPOINT =url+"flwv3-pug/getpaidx/api/charge?type=mobile_money_rwand";
CARD_VALIDATE_ENDPOINT = url+"flwv3-pug/getpaidx/api/validatecharge";
ACCOUNT_VALIDATE_ENDPOINT=url+"flwv3-pug/getpaidx/api/validate";
TIMEOUT_ENDPOINT=url+"flwv3-pug/getpaidx/api/charge?use_polling=1";
......@@ -75,7 +77,13 @@ public class Endpoints {
return CHARGE_ENDPOINT;
}
public String getValidateCardChargeEndPoint(){
public String getChargeMobileEndpoint() {
init();
return CHARGE_MOBILE_ENDPOINT;
}
public String getValidateCardChargeEndPoint(){
init();
return CARD_VALIDATE_ENDPOINT;
......
......@@ -122,6 +122,59 @@ public class FlutterWaveController extends Controller {
}
@PostMapping("/payMobile")
public ResponseEntity<String> payForOrderByPhone(@RequestParam("orderId") String orderId, @RequestBody FlutterWaveCard flutterWaveCard) {
RaveConstant.PUBLIC_KEY = PUBLIC_KEY;
RaveConstant.SECRET_KEY = SECRET_KEY;
RaveConstant.ENVIRONMENT = Environment.LIVE; //or live
// Result result = new Result();
Optional<TbCfOrder> byId = repository.findById(orderId);
JSONObject json = new JSONObject();
if (byId.isPresent()) {
//TbCfOrderVo tbCfOrderVo = (TbCfOrderVo) orderRedisCache.get(KeyConstant.ORDER_DET + orderId);
TbCfOrder orderEntity = byId.get();
//判断这个订单是否已支付
if (OrderStatusEnum.PAID.getValue().equals(orderEntity.getPayStatus())) {
json.put("message", "Order paid!");
json.put("code", ResultCodeEnum.ORDER_PAY_ERROR.getCode());
}else {
try {
CardCharge ch = new CardCharge();
ch.setCardno(flutterWaveCard.getCard())
.setCvv(flutterWaveCard.getCvv())
.setCurrency("USD")
.setCountry("NG")
.setAmount(orderEntity.getRealityPay().toString())
.setRedirect_url(REDIRECT_URL+"/"+orderId)
.setExpiryyear(flutterWaveCard.getYear())
.setExpirymonth(flutterWaveCard.getMonth())
.setEmail(flutterWaveCard.getEmail())
.setTxRef(orderId);
JSONObject chargevisa = ch.chargeMobileMoney();
JSONObject object = chargevisa.getJSONObject("data");
boolean b = object != null && object.has("authurl");
String message = !b && object != null && object.has("message") ? object.getString("message") : ResultCodeEnum.SERVICE_ERROR.getDesc();
json.put("data", chargevisa);
json.put("code", b ? ResultCodeEnum.SUCCESS.getCode() : ResultCodeEnum.SERVICE_ERROR.getCode());
json.put("message", b ? ResultCodeEnum.SUCCESS.getDesc() : message);
} catch (Exception e) {
json.put("code", ResultCodeEnum.ORDER_PAY_ERROR.getCode()).put("message", e.getMessage());
logger.error(e.getMessage(), e);
}
}
}
return new ResponseEntity<>(json.toString(), HttpStatus.OK);
}
@GetMapping("/notify/{orderId}")
public Result verifyFromFlutter(@PathVariable("orderId") String orderId) {
return verifyPay(orderId);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论