Inquiries about API SERVER Notification

Inquire the types of notifications that can occur in a SANDBOX environment

  • Hello, WWDC 2024 is trying to conduct a test to receive notifications related to ONE_TIME_CHARGE, CONNSUMPTION_REQUEST, CONMSUMPTION_INFO, REFUND, and REFUND_DECLINED as described in the example of purchasing consumables, but as a result of the continuous search, I found that it is difficult to occur except for

ONE_TIME_CHARGE.

  • So, in order to verify only the business logic as shown below, we are testing only the business logic without actually calling the API after purchasing the test and saving the signaled Payload that we received in response to ONE_TIME_CHARGE. Can we actually request a refund for the test purchase and receive the corresponding notification and actually send the response?
 public void handleSignedNotification(String signedNotification) throws Exception {
        ResponseBodyV2DecodedPayload payload = signedDataVerifier.verifyAndDecodeNotification(signedNotification);

        NotificationTypeV2 type = payload.getNotificationType();
        //For Apple Server Notification, only ONE_TIME_CHARGE notifications are enabled in the test environment, so for testing, change them as below to test whether they are running business logic

        type = NotificationTypeV2.REFUND;
        log.info("Apple NotificationType : {}", type);

        switch (type) {
            case CONSUMPTION_REQUEST:
                handleConsumptionRequest(payload);
                break;
            case REFUND:
                handleRefund(payload);
                break;
            case REFUND_DECLINED:
                handleRefundDeclined(payload);
                break;
            // For other necessary notifications, just take a log
            default:
                log.info("Unhandled notification: {}", type);
        }
    }

Regarding the call of 'CONSUMPTION_INFO', which is the response of 'CONSUMPTION_REQUEST'

    1. Is there a value that WWDC 2024 must include when sending CONMSUMPTION_INFO, which is the response to CONNSUMPTION_REQUEST described in the refund example? I'm going to call the API with only sample provision and consumption like the sample code you introduced in the video.
    1. I was told to submit my refund preference within 12 hours, but can I submit it as UNDECLARED at first and use the method to express my intention? When I receive the notification, I will save it in the DB and save it in the administrator page of the service so that the administrator can choose.
    • 2-1. Some of the materials I looked for are told that Apple can proceed with the refund even 12 hours ago, and to express your opinion as soon as I receive the notification, but I wonder if this is correct.
    1. If you get a notification as below, you should write whether you used it or not by referring to the consumption information. I think the customer said to check whether the data was provided when applying for a refund. Should I take it out of decodedTransaction, check the value, and just call it NO_PREFERENCE? I'd appreciate it if you could give me some advice.

Below is a part of the code I implemented.

 private void handleConsumptionRequest(ResponseBodyV2DecodedPayload notification) throws Exception {
 		// 1. transaction ID get
        String signedTransactionInfo = notification.getData().getSignedTransactionInfo();
        JWSTransactionDecodedPayload decodedTransaction = signedDataVerifier.verifyAndDecodeTransaction(signedTransactionInfo);
        String transactionId = decodedTransaction.getTransactionId();

        // 2. Extract the relevant transaction (The following example is an in-app payment and will be accumulated in two types of DBs, stored in one of the two)
        Sample sample = sampleService.findByAppleTransactionId(transactionId);
        Example example = exampleService.findByAppleTransactionId(transactionId);

        Boolean canRefund = false;

        // 3. Check consumption information
        if (sample != null) {
            canRefund = checkSampleStatusForApplePurchaseRefund(sample);
        } else if (example != null) {
            canRefund = checkExampleStatusForApplePurchaseRefund(example);
        }

        // 4. Create Refund Preferences
        RefundPreference refundPreference = determineRefundPreference(canRefund);

        // 5. Creating a ConsumptionRequest Object
        ConsumptionRequest request = new ConsumptionRequest()
                .refundPreference(refundPreference)
                .sampleContentProvided(true);

        log.info("forTest~ canRefund: {}", canRefund);
        log.info("forTest~ sample: {}", sample.toString());
        log.info("forTest~ example: {}", example.toString());
        log.info("forTest~ refundPreference: {}", refundPreference);
        log.info("forTest~ request: {}", request);

        // 6. Transfer to App Store (annotated with dummy requests that only confirm current business requests are going right)
        // appStoreServerAPIClient.sendConsumptionData(transactionId, request);
    }
Inquiries about API SERVER Notification
 
 
Q