提交 101303cb authored 作者: 吴德鹏's avatar 吴德鹏

购物车批量添加

上级 92f560c7
......@@ -31,6 +31,13 @@
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.stripe/stripe-java -->
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>11.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>cn.hutool</groupId>
......
......@@ -4,8 +4,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
//@EnableAsync
@EnableScheduling
@SpringBootApplication
public class AfrishopV3Application {
......
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.base.Result;
import com.google.gson.Gson;
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Customer;
import com.stripe.model.PaymentIntent;
import com.stripe.model.PaymentMethod;
import com.stripe.model.checkout.Session;
import com.stripe.param.PaymentIntentCreateParams;
import com.stripe.param.checkout.SessionCreateParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* @Auther: wudepeng
* @Date: 2021/01/04
* @Description:Stripe支付
*/
@RestController
@RequestMapping("/stripe")
public class StripeController {
private static Logger logger = LoggerFactory.getLogger(StripeController.class);
@Value("${stripe.secret_key}")
private String SECRET_KEY;
@Value("${stripe.public_key}")
private String PUBLIC_KEY;
@Value("${stripe.success_url}")
private String SUCCESS_URL;
@Value("${stripe.cancel_url}")
private String CANCEL_URL;
@PostMapping("/payment")
public Result payment(@RequestParam Map<String, Object> paramMap) {
return new Result();
}
/* @PostMapping("/payment")
public Result payment(@RequestParam Map<String, Object> paramMap) {
Map<String, String> resultMap = new HashMap<>();
try {
Stripe.apiKey = SECRET_KEY;
Map<String, Object> params = new HashMap<String, Object>();
ArrayList<String> paymentMethodTypes = new ArrayList<>();
paymentMethodTypes.add("card");
params.put("payment_method_types", paymentMethodTypes);
ArrayList<HashMap<String, Object>> lineItems = new ArrayList<>();
HashMap<String, Object> lineItem = new HashMap<String, Object>();
lineItem.put("name", "胡鹏飞测试商品");
lineItem.put("description", "这是一个测试单描述");
lineItem.put("amount", 500); // 支付金额
lineItem.put("currency", "usd"); //支付币种
lineItem.put("quantity", 1);
lineItems.add(lineItem);
params.put("line_items", lineItems);
//TODO 必须使用https 返回的回调地址
params.put("client_reference_id", paramMap.get("orderId"));//业务系统唯一标识 即订单唯一编号
params.put("success_url", SUCCESS_URL);// 支付成功跳转页面
params.put("cancel_url", CANCEL_URL);// 支付失败跳转页面
Session session = Session.create(params);
String sessionId = session.getId();
logger.info("sessionId :{}", session.getId());
resultMap.put("sessionId", sessionId);
} catch (StripeException e) {
e.printStackTrace();
}
return new Result(resultMap);
}*/
@GetMapping("/getPublicKey")
public Result getPublicKey() {
return new Result(PUBLIC_KEY);
}
}
......@@ -70,7 +70,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests().antMatchers("/api/auth/**", "/search/image/**", "/itemStation/**", "/startPage/**",
"/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**", "/community/**", "/version/**",
"/flutterwave/notify/**", "/dpo/notify/**", "/advertisement/**", "/website/**", "/paypal/**", "/discover/bonus/**",
"/problem/**", "/cube/**","/activity/**","/attributes/**").permitAll()
"/problem/**", "/cube/**", "/activity/**", "/attributes/**", "/stripe/**").permitAll()
.antMatchers("/api/test/**").permitAll()
.anyRequest().authenticated();
......
package com.example.afrishop_v3.util;
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Charge;
import java.util.HashMap;
import java.util.Map;
/**
* stripe支付相关方法
*/
public class StripePay {
/**
* 发起支付,默认使用美元支付
* @param amount 货币的最小单位,比如美元,传入1000,就是1000美分,10美元
* @param sk
* @param token
* @return
*/
public static Charge createCharge(Integer amount, String sk, String token) throws StripeException {
Stripe.apiKey = sk;
Map<String, Object> chargeParams = new HashMap<>(16);
chargeParams.put("amount", amount);
chargeParams.put("currency", "usd");
// 会出现在付款后页面
/** chargeParams.put("description", "Charge for jenny.rosen@example.com");*/
chargeParams.put("source",token);
return Charge.create(chargeParams);
}
}
......@@ -73,7 +73,7 @@ dpo:
flutter:
pay_url: https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify
refund_url: https://api.ravepay.co/gpx/merchant/transactions/refund
redirect_url: https://www.afrieshop.com/afrishop/flutterwave/notify
redirect_url: https://app.afrieshop.com/zion/flutterwave/notify
public_key: FLWPUBK-ee0f5d653f5f33fc89e6caf9de6a4c34-X
secret_key: FLWSECK-c06cdc19526077f3855b76045ca77de3-X
......
......@@ -9,11 +9,11 @@ spring:
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
password: Diaoyunnuli.8
# secondsource:
# url: jdbc:mysql://165.22.82.105:3306/chinafrica?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
# username: root
# driver-class-name: com.mysql.cj.jdbc.Driver
# password: clement123
# secondsource:
# url: jdbc:mysql://165.22.82.105:3306/chinafrica?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
# username: root
# driver-class-name: com.mysql.cj.jdbc.Driver
# password: clement123
redis:
#Redis数据库分片索引(默认为0)
......@@ -93,3 +93,8 @@ paypal:
failed_page: https://www.afrieshop.com/payment_failed
mode: sandbox
stripe:
success_url: https://app.afrieshop.com/afrishop/stripe/success
cancel_url: https://app.afrieshop.com/afrishop/stripe/cancel
public_key: pk_test_y5dXLjyUyBD11Ta9g2DGynxN0048vnmpGz
secret_key: sk_test_tGl2q7Omxehpli7R3Z6xU6G900iL1eX32c
server.servlet.context-path=/zion
spring.jpa.hibernate.ddl-auto=update
server.port=8083
spring.profiles.active=test
spring.profiles.active=prod
#spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/afrishop_test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=root
#spring.datasource.password=Diaoyunnuli.8
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论