0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PayPay API Springbootで配置 爆速

Posted at

1.Mavenで配置

<dependency>
    <groupId>jp.ne.paypay</groupId>
    <artifactId>paypayopa</artifactId>
    <version>1.0.8</version>
</dependency>

2.ユーザー認証

private static final String YOUR_API_KEY = "";
private static final String YOUR_API_SECRET = "";
private static final String YOUR_MERCHANT_KEY = "";
private static final ApiClient apiClient;
static {
    try {
        apiClient = new Configuration().getDefaultApiClient();
        apiClient.setProductionMode(false);
        apiClient.setApiKey(YOUR_API_KEY);
        apiClient.setApiSecretKey(YOUR_API_SECRET);
        apiClient.setAssumeMerchant(YOUR_MERCHANT_KEY);
    } catch (ApiException e) {
        throw new RuntimeException(e);
    }
}

3.1 CreateQRCode

	/**
     * CreateQRCode
     *
     * @param merchantPaymentId 
     * @param payAmount 
     * @param orderDescription 
     * @return 
     */
    public static QRCodeResponse getQrCode(String merchantPaymentId, Integer payAmount, String orderDescription) throws ApiException {
        QRCode qrCode = new QRCode();
        qrCode.setAmount(new MoneyAmount().amount(payAmount).currency(MoneyAmount.CurrencyEnum.JPY));
        qrCode.setMerchantPaymentId(merchantPaymentId);
        qrCode.setCodeType("ORDER_QR");
        qrCode.setOrderDescription(orderDescription);
        qrCode.isAuthorization(false);
        PaymentApi apiInstance = new PaymentApi(apiClient);
        QRCodeDetails response = apiInstance.createQRCode(qrCode);
        QRCodeResponse responseData = null;
        if (PAY_SUCCESS.equals(response.getResultInfo().getCode())) {
            responseData = response.getData();
        } else {
            log.info("バーコード生成,Error code : {}", response.getResultInfo().getCode());
            throw new RuntimeException((response.getResultInfo().getMessage()));
        }
        return responseData;
    }

3.1.1 Test result

private static final String PRODUCT_PAY_PAY = "PayOr";

@Test
public void createPaymentTest() {
    String orderNo = IdUtil.getSnowflake(0, 0).nextIdStr();
    System.out.println("注文番号をランダムに生成する" + orderNo);
    QRCodeResponse QRCodeResponse = new QRCodeResponse();
    try {
        String merchantPaymentId = PRODUCT_PAY_PAY + orderNo;
        String orderDescription = "テスト";
        Integer paAmount = 1;
        QRCodeResponse = getQrCode(merchantPaymentId, paAmount, orderDescription);
    } catch (ApiException e) {
        System.out.println("Error code : " + e.getMessage());
        throw new RuntimeException(e);
    }
    System.out.println(QRCodeResponse);
    System.out.println(QRCodeResponse.getUrl());
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?