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());
// This is a sample test API key.
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);
});
}
}