Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
e06c27d7
提交
e06c27d7
authored
3月 01, 2021
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Braintree支付
上级
f062e533
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
117 行增加
和
1 行删除
+117
-1
pom.xml
pom.xml
+6
-0
BraintreeController.java
.../example/afrishop_v3/controllers/BraintreeController.java
+84
-0
TbCfOrder.java
src/main/java/com/example/afrishop_v3/models/TbCfOrder.java
+4
-1
GatewayFactory.java
...ain/java/com/example/afrishop_v3/util/GatewayFactory.java
+23
-0
没有找到文件。
pom.xml
浏览文件 @
e06c27d7
...
...
@@ -32,6 +32,12 @@
<dependencies>
<dependency>
<groupId>
com.braintreepayments.gateway
</groupId>
<artifactId>
braintree-java
</artifactId>
<version>
2.87.0
</version>
</dependency>
<dependency>
<groupId>
net.coobird
</groupId>
<artifactId>
thumbnailator
</artifactId>
...
...
src/main/java/com/example/afrishop_v3/controllers/BraintreeController.java
0 → 100644
浏览文件 @
e06c27d7
package
com
.
example
.
afrishop_v3
.
controllers
;
import
com.braintreegateway.*
;
import
com.example.afrishop_v3.models.TbCfOrder
;
import
com.example.afrishop_v3.repository.TbCfOrderRepository
;
import
com.example.afrishop_v3.util.GatewayFactory
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.util.Map
;
import
java.util.Optional
;
/**
* @Auther: wudepeng
* @Date: 2021/02/27
* @Description:Braintree支付
*/
@RestController
public
class
BraintreeController
{
private
static
BraintreeGateway
gateway
=
GatewayFactory
.
getlisiGateway
();
private
final
TbCfOrderRepository
orderRepository
;
@Value
(
"${paypal.success_page}"
)
private
String
PAYPAL_SUCCESS_PAGE
;
@Value
(
"${paypal.failed_page}"
)
private
String
PAYPAL_FAILED_PAGE
;
public
BraintreeController
(
TbCfOrderRepository
orderRepository
)
{
this
.
orderRepository
=
orderRepository
;
}
@PostMapping
(
"/getToken"
)
public
String
getToken
()
{
//官方写new ClientTokenRequest().customerId("customerId")可以不要。
ClientTokenRequest
clientTokenRequest
=
new
ClientTokenRequest
();
String
clientToken
=
gateway
.
clientToken
().
generate
(
clientTokenRequest
);
return
clientToken
;
}
@PostMapping
(
"/pay"
)
public
void
pay
(
@RequestParam
String
orderId
,
@RequestParam
String
nonce
,
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
IOException
{
Optional
<
TbCfOrder
>
byId
=
orderRepository
.
findById
(
orderId
);
if
(
StringUtils
.
isBlank
(
orderId
)
||
StringUtils
.
isBlank
(
nonce
)
||
!
byId
.
isPresent
())
{
resp
.
sendRedirect
(
PAYPAL_FAILED_PAGE
);
}
TbCfOrder
order
=
byId
.
get
();
BigDecimal
orderPrice
=
order
.
getRealityPay
();
String
orderInfo
=
order
.
getDeliveryName
()
+
"'s payment information"
;
TransactionRequest
request
=
new
TransactionRequest
()
.
amount
(
orderPrice
)
.
paymentMethodNonce
(
nonce
)
.
deviceData
(
orderInfo
)
.
options
()
.
submitForSettlement
(
true
)
.
done
();
Result
<
Transaction
>
result
=
gateway
.
transaction
().
sale
(
request
);
if
(
result
.
isSuccess
())
{
resp
.
sendRedirect
(
PAYPAL_SUCCESS_PAGE
);
}
else
{
resp
.
sendRedirect
(
PAYPAL_FAILED_PAGE
);
}
}
}
src/main/java/com/example/afrishop_v3/models/TbCfOrder.java
浏览文件 @
e06c27d7
...
...
@@ -373,7 +373,10 @@ public class TbCfOrder {
* 使用类型 1:全场 2:分类商品 3:特定商品(use_type)
*/
boolean
fullAct
=
activityRepository
.
existsByUseType
(
1
);
if
(
this
.
open
&&
fullAct
)
{
/**
* 之前app没有接活动,所以要和mobile端区分,才设置一个开关(open)
*/
if
(
/*this.open && */
fullAct
)
{
Activity
act
=
null
;
List
<
Activity
>
alist
=
activityRepository
.
findAllByUseType
(
1
);
...
...
src/main/java/com/example/afrishop_v3/util/GatewayFactory.java
0 → 100644
浏览文件 @
e06c27d7
package
com
.
example
.
afrishop_v3
.
util
;
import
com.braintreegateway.BraintreeGateway
;
import
com.braintreegateway.Environment
;
/**
* @Auther: wudepeng
* @Date: 2021/02/27
* @Description:
*/
public
class
GatewayFactory
{
public
static
BraintreeGateway
getlisiGateway
()
{
BraintreeGateway
gateway
=
new
BraintreeGateway
(
Environment
.
SANDBOX
,
"g24p4hdqckyqfx37"
,
"4c2sxyqntc4k5967"
,
"cda52df9ab396a52ed0302fdeda081cb"
);
return
gateway
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论