站内支付
1. 设置MoneyCollect sdk
<dependency>
<groupId>com.moneycollect</groupId>
<artifactId>moneycollect-java</artifactId>
<version>{VERSION}</version>
</dependency>2. 创建支付
package com.moneycollect.sample;
import com.alibaba.fastjson.JSONObject;
import com.moneycollect.Moneycollect;
import com.moneycollect.model.Payment;
import com.moneycollect.param.PaymentCreateParams;
import lombok.Data;
import java.nio.file.Paths;
import static spark.Spark.*;
public class Server {
private static JSONObject json = new JSONObject();
@Data
static class CreatePaymentResponse {
private String id;
private String clientSecret;
public CreatePaymentResponse(String id,String clientSecret) {
this.id = id;
this.clientSecret = clientSecret;
}
}
public static void main(String[] args) {
port(5050);
staticFiles.externalLocation(Paths.get("public").toAbsolutePath().toString());
// 这是一个示例测试 API 密钥。
MoneyCollect.apiKey = "test_pr_K***";
post("/create-payment", (request, response) -> {
response.type("application/json");
PaymentCreateParams params =
PaymentCreateParams.builder()
.setAmount(14*100L)
.setCurrency("USD")
.setOrderNo("MC"+System.currentTimeMillis())
.build();
Payment payment = Payment.create(params);
CreatePaymentResponse paymentResponse = new CreatePaymentResponse(payment.getId(),payment.getClientSecret());
return json.toJSONString(paymentResponse);
});
}
}3. 在客户端构建结账页面
4. 在客户端完成支付
5. 处理支付后事件
6. 其他测试资源
号码
品牌
描述
Last updated