Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
56bb9d7c
提交
56bb9d7c
authored
11月 07, 2020
作者:
Whispa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit commit
上级
efab0723
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
242 行增加
和
134 行删除
+242
-134
CardCharge.java
src/main/java/com/example/afrishop_v3/config/CardCharge.java
+178
-131
Charge.java
src/main/java/com/example/afrishop_v3/config/Charge.java
+2
-2
Endpoints.java
src/main/java/com/example/afrishop_v3/config/Endpoints.java
+9
-1
FlutterWaveController.java
...xample/afrishop_v3/controllers/FlutterWaveController.java
+53
-0
没有找到文件。
src/main/java/com/example/afrishop_v3/config/CardCharge.java
浏览文件 @
56bb9d7c
...
@@ -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
;
}
}
...
...
src/main/java/com/example/afrishop_v3/config/Charge.java
浏览文件 @
56bb9d7c
...
@@ -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
(
e
d
.
getChargeEndPoint
()
);
this
.
apiConnection
=
new
ApiConnection
(
e
ndpoint
);
String
alg
=
"3DES-24"
;
String
alg
=
"3DES-24"
;
...
...
src/main/java/com/example/afrishop_v3/config/Endpoints.java
浏览文件 @
56bb9d7c
...
@@ -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
;
...
...
src/main/java/com/example/afrishop_v3/controllers/FlutterWaveController.java
浏览文件 @
56bb9d7c
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论