Skip to content

Instantly share code, notes, and snippets.

View A-pZ's full-sized avatar

A-pZ A-pZ

  • Capybara(Oni-Tenjiku-nezumi)
  • Tokyo, shinagawa
View GitHub Profile
@A-pZ
A-pZ / SalesforceConfig.java
Created August 6, 2023 07:47
Salesforce接続用WebClientの設定
package com.github.apz.salesforcesample.config;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
@Configuration
@AllArgsConstructor
public class SalesforceConfig {
package com.github.apz.salesforcesample.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "salesforce")
@Getter @Setter
salesforce:
url: "https://test.salesforce.com/services/oauth2/token"
grant-type: "password"
consumer-key: "コンシューマー鍵の値"
consumer-secret: "コンシューマー秘密の値"
mail-address: "登録したユーザのメールアドレス"
password: "登録したユーザのパスワード"
security-token: "ユーザのセキュリティトークン"
application-url: "アプリケーション接続ドメイン" # 認証後に取得できます
application-path: "/services/data/v53.0"
@A-pZ
A-pZ / build.gradle
Created August 6, 2023 07:17
Salesforce連携用アプリケーションのbuild.properties
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'groovy'
}
group = 'com.github.apz'
version = '1.0.0'
@A-pZ
A-pZ / ParameterBindingInterceptor.java
Created December 15, 2022 04:26
パラメータのバインド前後を確認する設定
package com.github.apz.sample.config.mybatis;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import java.sql.PreparedStatement;
@A-pZ
A-pZ / Item.java
Created December 15, 2022 04:03
マッパー定義例
package com.github.apz.sample.repository;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@NoArgsConstructor @Getter
public class Item {
private Long id;
@A-pZ
A-pZ / SqlIdLoggingInterceptor.java
Last active December 15, 2022 04:05
MyBatis Plugin(クエリ発行時にSQL-IDを出力)
package com.github.apz.sample.config.mybatis;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
@A-pZ
A-pZ / UpdateDefaultPaymentMethod.java
Created October 28, 2022 10:42
決済手段のデフォルトを登録
Customer customer = Customer.retrieve(paymentCustomer.id()); // 決済利用者のカスタマIDを指定
CustomerUpdateParams customerUpdateParams = CustomerUpdateParams.builder()
.setInvoiceSettings(
// 決済したPaymentMethodのIDを InvoiceSettingを経由して指定する
CustomerUpdateParams.InvoiceSettings.builder().setDefaultPaymentMethod(paymentMethodId.value()).build()
).build();
customer.update(customerUpdateParams);
@A-pZ
A-pZ / PaymentIntentTransfer.java
Last active October 28, 2022 05:12
決済のキャプチャ
public PaymentIntent capturePaymentIntent(PaymentIntentId paymentIntentId) {
try {
PaymentIntent target = PaymentIntent.retrieve(paymentIntentId.value());
PaymentStatus paymentStatus = PaymentStatus.of(target.getStatus());
if (paymentStatus.requireThreeDSecure()) {
String message = String.format("3DS認証が必要です: %s", paymentIntentId.value());
throw new PaymentRuntimeException(message);
}
if (paymentStatus.alreadyCaptured()) {
@A-pZ
A-pZ / PaymentIntentTransfer.java
Last active October 28, 2022 01:47
PaymentIntentの作成(オーソリとキャプチャ分離)
public class PaymentIntentTransfer
/**
* @param request 決済情報の作成に必要なパラメータを格納。決済金額や過去Stripeを利用した際のカスタマIDが入る。
*/
public PaymentIntent createPaymentIntent(PaymentIntentCreateRequest request) {
PaymentIntentCreateParams params = createPaymentIntentCreateParams(request);
try {
return PaymentIntent.create(params);
} catch(StripeException e) {
throw new PaymentRuntimeException(e);