歐盟支付服務準則修正案 (PSD2)

使用 SDK 讓遵守 PSD2 EEA 法規更簡便。

支付服務準則修正案 (Payment Services Directive 2,PSD2) 是歐洲經濟區 (EEA) 的法規,要求對於使用由 EEA 成員國核發的信用卡進行的各項交易,必須變更結帳與預訂流程以符合法規。想進一步了解 PSD2,請參閱這裡

1. 購物

取得供應情況

GetAvailabilityOperationParams getAvailabilityOperationParams = GetAvailabilityOperationParams.builder()
    .checkin("YYYY-MM-DD")
    .checkout("YYYY-MM-DD")
    .currency("USD")
    .language("en_US")
    .countryCode("US")
    .occupancy(List.of("OCCUPANCY"))
    .propertyId(List.of("PROPERTY ID"))
    .customerIp("127.0.0.1")
    .ratePlanCount(BigDecimal.ONE)
    .salesChannel("SALES CHANNEL")
    .salesEnvironment("SALES ENVIRONMENT")
    .build();

GetAvailabilityOperation getAvailabilityOperation = new GetAvailabilityOperation(getAvailabilityOperationParams);
Response<List<Property>> propertiesResponse = rapidClient.execute(getAvailabilityOperation);

查看房價

Property property = propertiesResponse.getData().get(0);

if (!(property instanceof PropertyAvailability)) {
    return;
}

PropertyAvailability propertyAvailability = (PropertyAvailability) property;
Link propertyAvailabilityLink = propertyAvailability.getRooms().get(0).getRates().get(0).getBedGroups().entrySet().stream().findFirst().get().getValue().getLinks().getPriceCheck(); // selecting the first rate for the first room
PriceCheckOperation priceCheckOperation = new PriceCheckOperation(propertyAvailabilityLink);
Response<RoomPriceCheck> response = rapidClient.execute(priceCheckOperation);
RoomPriceCheck roomPriceCheck = response.getData();

2. 預訂

建立付款工作階段要求 Helper 方法

PaymentSessionsRequest createPaymentSessionRequest() {
    PaymentSessionsRequestCustomerAccountDetails customerAccountDetails =
            PaymentSessionsRequestCustomerAccountDetails.builder()
                    .authenticationMethod(PaymentSessionsRequestCustomerAccountDetails.AuthenticationMethod.GUEST)
                    .authenticationTimestamp("YYYY-MM-DDTHH:mm:00.000Z")
                    .createDate("YYYY-MM-DD")
                    .changeDate("YYYY-MM-DD")
                    .passwordChangeDate("YYYY-MM-DD")
                    .addCardAttempts(BigDecimal.ONE)
                    .accountPurchases(BigDecimal.ONE)
                    .build();

    BillingContactRequestAddress address =
            BillingContactRequestAddress.builder()
                    .line1("LINE 1")
                    .line2("LINE 2")
                    .line3("LINE 3")
                    .city("CITY")
                    .stateProvinceCode("STATE CODE")
                    .countryCode("COUNTRY CODE")
                    .postalCode("POSTAL CODE")
                    .build();

    BillingContactRequest billingContact =
            BillingContactRequest.builder()
                    .givenName("John")
                    .familyName("Smith")
                    .address(address)
                    .build();

    List<PaymentRequest> payments = List.of(
            PaymentRequest.builder()
                    .type(PaymentRequest.Type.CUSTOMER_CARD)
                    .number("NUMBER")
                    .securityCode("SECURITY CODE")
                    .expirationMonth("EXPIRATION MONTH")
                    .expirationYear("EXPIRATION YEAR")
                    .billingContact(billingContact)
                    .enrollmentDate("ENTROLLMET DATE")
                    .build()
    );

    return PaymentSessionsRequest.builder()
            .version("VERSION")
            .browserAcceptHeader("*/*")
            .encodedBrowserMetadata("BROWSER METADATA")
            .preferredChallengeWindowSize(PaymentSessionsRequest.PreferredChallengeWindowSize.MEDIUM)
            .merchantUrl("MERCHANT URL")
            .customerAccountDetails(customerAccountDetails)
            .payments(payments)
            .build();
}

建立付款工作階段

Link paymentSessionLink = roomPriceCheck.getLinks().getPaymentSession();
PostPaymentSessionsOperationContext postPaymentSessionsOperationContext = PostPaymentSessionsOperationContext.builder().customerIp("1.2.3.4").customerSessionId("12345").build(); // fill the context as needed
PostPaymentSessionsOperation paymentSessionsOperation = new PostPaymentSessionsOperation(paymentSessionLink, postPaymentSessionsOperationContext, createPaymentSessionRequest());
Response<PaymentSessions> paymentSessionsResponse = rapidClient.execute(paymentSessionsOperation);
PaymentSessions paymentSessions = paymentSessionsResponse.getData();

通過 JavaScript 挑戰

如果需要 2FA,則回應會包含 encodedChallengeConfigencodedChallengeConfigpaymentSessionId 的回傳內容必須以參數傳入 JavaScript 挑戰方法。

建立行程要求 Helper 方法

CreateItineraryRequest createItineraryRequest(boolean hold) {
        PhoneRequest phone =
                PhoneRequest.builder()
                        .countryCode("COUNTRY CODE")
                        .areaCode("AREA CODE")
                        .number("NUMBER")
                        .build();

        List<CreateItineraryRequestRoom> rooms = List.of(
                CreateItineraryRequestRoom.builder()
                        .givenName("John")
                        .familyName("Smith")
                        .smoking(false)
                        .specialRequest("SPECIAL REQUEST")
                        .build()
        );

        BillingContactRequestAddress address =
                BillingContactRequestAddress.builder()
                        .line1("LINE 1")
                        .line2("LINE 2")
                        .line3("LINE 3")
                        .city("CITY")
                        .stateProvinceCode("STATE CODE")
                        .countryCode("COUNTRY CODE")
                        .postalCode("POSTAL CODE")
                        .build();

        BillingContactRequest billingContact =
                BillingContactRequest.builder()
                        .givenName("John")
                        .familyName("Smith")
                        .address(address)
                        .build();

        List<PaymentRequest> payments = List.of(
                PaymentRequest.builder()
                        .type(PaymentRequest.Type.CUSTOMER_CARD)
                        .number("NUMBER")
                        .securityCode("SECURITY CODE")
                        .expirationMonth("MONTH")
                        .expirationYear("YEAR")
                        .billingContact(billingContact)
                        .enrollmentDate("ENROLLMENT_DATE")
                        .build()
        );

        return CreateItineraryRequest.builder()
                .affiliateReferenceId(UUID.randomUUID().toString().substring(0, 28))
                .hold(hold)
                .email("john@example.com")
                .phone(phone)
                .rooms(rooms)
                .payments(payments)
                .affiliateMetadata("AFFILIATE METADATA")
                .taxRegistrationNumber("TAX NUMBER")
                .travelerHandlingInstructions("INSTRUCTIONS")
                .build();
}

建立行程

Link postItineraryLink = roomPriceCheck.getLinks().getBook(); // from the first step
PostItineraryOperationContext postItineraryOperationContext = PostItineraryOperationContext.builder().customerIp("1.2.3.4").customerSessionId("12345").build(); // fill the context as needed
PostItineraryOperation itineraryCreationOperation = new PostItineraryOperation(postItineraryLink, postItineraryOperationContext, createItineraryRequest(true));
Response<ItineraryCreation> response = rapidClient.execute(itineraryCreationOperation);
ItineraryCreation itineraryCreation = response.getData();

完成付款工作階段

Link completePaymentSessionLink = itineraryCreation.getLinks().getCompletePaymentSession();
PutCompletePaymentSessionOperationContext putCompletePaymentSessionOperationContext = PutCompletePaymentSessionOperationContext.builder().customerIp("1.2.3.4").customerSessionId("12345").build(); // fill the context as needed
PutCompletePaymentSessionOperation completePaymentSessionOperation = new PutCompletePaymentSessionOperation(completePaymentSessionLink, putCompletePaymentSessionOperationContext);
Response<CompletePaymentSession> completePaymentSessionResponse = rapidClient.execute(completePaymentSessionOperation);
CompletePaymentSession completePaymentSession = completePaymentSessionResponse.getData();

繼續處理暫停預訂

Link resumeLink = itineraryCreation.getLinks().getResume();
PutResumeBookingOperationContext putResumeBookingOperationContext = PutResumeBookingOperationContext.builder().customerIp("1.2.3.4").customerSessionId("12345").build(); // fill the context as needed
PutResumeBookingOperation putResumeBookingOperation = new PutResumeBookingOperation(resumeLink, putResumeBookingOperationContext);
rapidClient.execute(putResumeBookingOperation);
這個頁面有幫助嗎?
我們能如何改善內容?
感謝您協助我們進行改善!