カテゴリー
投資

stripeアクセス

@PostMapping("/hello2")
private String stripeAccess() throws StripeException {
    // This is your test secret API key.
    Stripe.apiKey = "sk_test_51LG9wvEbZcPb8qcKSD7pJKgdgeg9sSXJutIPL2VlbQWYp8T3EUTKEj1WIFRfQEINGOwWTOFQUoseMiHmzSeH2BQ300BSZeAfj9";

    staticFiles.externalLocation(
        Paths.get("public").toAbsolutePath().toString());

    String YOUR_DOMAIN = "http://localhost:8080";

    //商品(product)設定
    Map<String, Object> product_data1 = new HashMap<>();
    product_data1.put("name","商品A");
    product_data1.put("description","A商品の説明");
    product_data1.put("tax_code","txcd_99999999");

    //商品(product)メタデータ設定
    Map<String, Object> meta = new HashMap<>();
    meta.put("商品コード","111100011");
    meta.put("商品カタログ","xxxxx");
    product_data1.put("metadata",meta);

    Map<String, Object> product_data2 = new HashMap<>();
    product_data2.put("name","商品B");
    product_data2.put("description","B商品の説明");
    product_data2.put("tax_code","txcd_99999999");      

    //値段(price)設定
    Map<String, Object> price_data1 = new HashMap<>();
    price_data1.put("product_data",product_data1);
    price_data1.put("currency","JPY");
    price_data1.put("unit_amount_decimal",400);

// price_data1.put(“tax_behavior”,”inclusive”);

    Map<String, Object> price_data2 = new HashMap<>();
    price_data2.put("product_data",product_data2);
    price_data2.put("currency","JPY");
    price_data2.put("unit_amount_decimal",700);
    price_data2.put("tax_behavior","inclusive");


    //明細(line)設定
    Map<String, Object> lineItem1 = new HashMap<>();
    lineItem1.put("quantity", 2);
    lineItem1.put("price_data",price_data1);

    Map<String, Object> lineItem2 = new HashMap<>();
    lineItem2.put("quantity", 3);
    lineItem2.put("price_data",price_data2);

    //Item設定
    List<Object> lineItems = new ArrayList<>();
    lineItems.add(lineItem1);
    lineItems.add(lineItem2);

    //可能な支払い方法
    List<Object> paymentmethod = new ArrayList<>();
    paymentmethod.add("card");
    paymentmethod.add("alipay");

    //checkOutSessionパラメタ
    Map<String, Object> params = new HashMap<>();
    params.put(
      "success_url",
      YOUR_DOMAIN + "/success"
    );
    params.put(
      "cancel_url",
      YOUR_DOMAIN + "/cancel"
    );
    params.put("customer","cus_MI5Yu1Mriu7zXN");
    params.put("line_items", lineItems);
    params.put("client_reference_id","cus_MI4kKPMyy4jnVh");
    params.put("mode", "payment");
    params.put("payment_method_types",paymentmethod);

  Session session = Session.create(params);

  System.out.println(session);
  System.out.println("endendend");

  return "redirect:" + session.getUrl();
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です