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

commit commit

上级 efab0723
...@@ -19,30 +19,33 @@ import static com.example.afrishop_v3.config.Encryption.getKey; ...@@ -19,30 +19,33 @@ import static com.example.afrishop_v3.config.Encryption.getKey;
/** /**
*
* @author Theresa * @author Theresa
*/ */
public class CardCharge { public class CardCharge {
JSONObject api=new JSONObject(); JSONObject api = new JSONObject();
Endpoints ed=new Endpoints(); Endpoints ed = new Endpoints();
ApiConnection apiConnection; ApiConnection apiConnection;
Encryption e=new Encryption(); Encryption e = new Encryption();
private String cardno,cvv,expirymonth,expiryyear,currency,country,pin,suggested_auth, private String cardno, cvv, expirymonth, expiryyear, currency, country, pin, suggested_auth,
amount,email,phonenumber,firstname,lastname,txRef,redirect_url,device_fingerprint,IP, amount, email, phonenumber, firstname, lastname, fullname, txRef, redirect_url, device_fingerprint, IP,
charge_type; 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() { public JSONObject setJSON() {
JSONObject json=new JSONObject(); JSONObject json = new JSONObject();
try{ try {
json.put("cardno", this.getCardno()); json.put("cardno", this.getCardno());
json.put("cvv", this.getCvv()); json.put("cvv", this.getCvv());
...@@ -61,61 +64,99 @@ public class CardCharge { ...@@ -61,61 +64,99 @@ public class CardCharge {
json.put("lastname", this.getLastname()); json.put("lastname", this.getLastname());
json.put("redirect_url", this.getRedirect_url()); json.put("redirect_url", this.getRedirect_url());
json.put("charge_type", this.getCharge_type()); json.put("charge_type", this.getCharge_type());
}catch( JSONException ex){ex.getMessage();} } 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; return json;
} }
public JSONObject chargeMasterAndVerveCard() throws JSONException { public JSONObject chargeMasterAndVerveCard() throws JSONException {
JSONObject json= setJSON(); JSONObject json = setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("pin",this.getPin() ); json.put("pin", this.getPin());
json.put("suggested_auth",this.getSuggested_auth() ); json.put("suggested_auth", this.getSuggested_auth());
String message= json.toString(); String message = json.toString();
String encrypt_secret_key=getKey(RaveConstant.SECRET_KEY); String encrypt_secret_key = getKey(RaveConstant.SECRET_KEY);
String client= encryptData(message,encrypt_secret_key); String client = encryptData(message, encrypt_secret_key);
Charge ch=new Charge(); Charge ch = new Charge();
return ch.charge(client); return ch.charge(client,ed.getChargeEndPoint());
} }
public JSONObject chargeMasterAndVerveCard(boolean polling) { public JSONObject chargeMasterAndVerveCard(boolean polling) {
JSONObject json= setJSON(); JSONObject json = setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("pin",this.getPin() ); json.put("pin", this.getPin());
json.put("suggested_auth",this.getSuggested_auth() ); json.put("suggested_auth", this.getSuggested_auth());
Polling p=new Polling(); Polling p = new Polling();
return p.handleTimeoutCharge(json); return p.handleTimeoutCharge(json);
} }
public JSONObject chargeVisaAndIntl() throws JSONException { public JSONObject chargeVisaAndIntl() throws JSONException {
JSONObject json= setJSON(); JSONObject json = setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url() ); 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.getChargeEndPoint());
}
String message= json.toString();
String encrypt_secret_key=getKey(RaveConstant.SECRET_KEY); public JSONObject chargeMobileMoney() throws JSONException {
String client= encryptData(message,encrypt_secret_key); JSONObject json = getPhoneJSON();
json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url());
String message = json.toString();
Charge ch=new Charge(); String encrypt_secret_key = getKey(RaveConstant.SECRET_KEY);
String client = encryptData(message, encrypt_secret_key);
return ch.charge(client); Charge ch = new Charge();
return ch.charge(client,ed.getChargeMobileEndpoint());
} }
public JSONObject chargeVisaAndIntl(boolean polling) throws JSONException { public JSONObject chargeVisaAndIntl(boolean polling) throws JSONException {
JSONObject json= setJSON(); JSONObject json = setJSON();
json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); json.put("PBFPubKey", RaveConstant.PUBLIC_KEY);
json.put("redirect_url", this.getRedirect_url() ); json.put("redirect_url", this.getRedirect_url());
Polling p=new Polling(); Polling p = new Polling();
return p.handleTimeoutCharge(json); return p.handleTimeoutCharge(json);
...@@ -128,15 +169,16 @@ public class CardCharge { ...@@ -128,15 +169,16 @@ public class CardCharge {
* @return JSONObject * @return JSONObject
*/ */
public JSONObject validateCardCharge(){ public JSONObject validateCardCharge() {
Charge vch= new Charge(); Charge vch = new Charge();
return vch.validateCardCharge(this.getTransactionreference(), this.getOtp()); return vch.validateCardCharge(this.getTransactionreference(), this.getOtp());
} }
//if timeout //if timeout
public JSONObject validateCardCharge(boolean polling){ public JSONObject validateCardCharge(boolean polling) {
Polling p=new Polling(); Polling p = new Polling();
return p.validateCardChargeTimeout(this.getTransactionreference(), this.getOtp()); return p.validateCardChargeTimeout(this.getTransactionreference(), this.getOtp());
} }
...@@ -146,12 +188,13 @@ public class CardCharge { ...@@ -146,12 +188,13 @@ public class CardCharge {
@params authUrl This requires that you copy the authurl returned in the response @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 and paste it in the argument and it opens a small window for card validation
*/ */
public void validateCardChargeVB(){ public void validateCardChargeVB() {
if (Desktop.isDesktopSupported()) { if (Desktop.isDesktopSupported()) {
try{ try {
Desktop.getDesktop().browse(new URI(this.getAuthUrl())); Desktop.getDesktop().browse(new URI(this.getAuthUrl()));
}catch(URISyntaxException | IOException ex){} } catch (URISyntaxException | IOException ex) {
}
} }
} }
...@@ -333,6 +376,10 @@ public class CardCharge { ...@@ -333,6 +376,10 @@ public class CardCharge {
return phonenumber; return phonenumber;
} }
public String getFullname() {
return fullname;
}
/** /**
* @param phonenumber the phonenumber to set * @param phonenumber the phonenumber to set
* @return CardCharge * @return CardCharge
...@@ -474,7 +521,7 @@ public class CardCharge { ...@@ -474,7 +521,7 @@ public class CardCharge {
* @return CardCharge * @return CardCharge
*/ */
public CardCharge setTransactionreference(String transaction_reference) { public CardCharge setTransactionreference(String transaction_reference) {
this.transactionreference= transaction_reference; this.transactionreference = transaction_reference;
return this; return this;
} }
......
...@@ -27,8 +27,8 @@ public class Charge { ...@@ -27,8 +27,8 @@ public class Charge {
//for all charges //for all charges
public JSONObject charge(String client){ public JSONObject charge(String client,String endpoint){
this.apiConnection = new ApiConnection(ed.getChargeEndPoint()); this.apiConnection = new ApiConnection(endpoint);
String alg="3DES-24"; String alg="3DES-24";
......
...@@ -16,6 +16,7 @@ public class Endpoints { ...@@ -16,6 +16,7 @@ public class Endpoints {
String url; String url;
public String BANK_ENDPOINT; public String BANK_ENDPOINT;
public static String CHARGE_ENDPOINT; public static String CHARGE_ENDPOINT;
public static String CHARGE_MOBILE_ENDPOINT;
public static String CARD_VALIDATE_ENDPOINT; public static String CARD_VALIDATE_ENDPOINT;
public static String ACCOUNT_VALIDATE_ENDPOINT; public static String ACCOUNT_VALIDATE_ENDPOINT;
public static String TIMEOUT_ENDPOINT; public static String TIMEOUT_ENDPOINT;
...@@ -47,6 +48,7 @@ public class Endpoints { ...@@ -47,6 +48,7 @@ public class Endpoints {
BANK_ENDPOINT= url+"flwv3-pug/getpaidx/api/flwpbf-banks.js?json=1"; BANK_ENDPOINT= url+"flwv3-pug/getpaidx/api/flwpbf-banks.js?json=1";
CHARGE_ENDPOINT =url+"flwv3-pug/getpaidx/api/charge"; 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"; CARD_VALIDATE_ENDPOINT = url+"flwv3-pug/getpaidx/api/validatecharge";
ACCOUNT_VALIDATE_ENDPOINT=url+"flwv3-pug/getpaidx/api/validate"; ACCOUNT_VALIDATE_ENDPOINT=url+"flwv3-pug/getpaidx/api/validate";
TIMEOUT_ENDPOINT=url+"flwv3-pug/getpaidx/api/charge?use_polling=1"; TIMEOUT_ENDPOINT=url+"flwv3-pug/getpaidx/api/charge?use_polling=1";
...@@ -75,6 +77,12 @@ public class Endpoints { ...@@ -75,6 +77,12 @@ public class Endpoints {
return CHARGE_ENDPOINT; return CHARGE_ENDPOINT;
} }
public String getChargeMobileEndpoint() {
init();
return CHARGE_MOBILE_ENDPOINT;
}
public String getValidateCardChargeEndPoint(){ public String getValidateCardChargeEndPoint(){
init(); init();
return CARD_VALIDATE_ENDPOINT; return CARD_VALIDATE_ENDPOINT;
......
...@@ -122,6 +122,59 @@ public class FlutterWaveController extends Controller { ...@@ -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}") @GetMapping("/notify/{orderId}")
public Result verifyFromFlutter(@PathVariable("orderId") String orderId) { public Result verifyFromFlutter(@PathVariable("orderId") String orderId) {
return verifyPay(orderId); return verifyPay(orderId);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论