mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-05 18:42:55 +00:00
bug5773: fixed not working cancelation of already covered subscriptions.
This commit is contained in:
1 parent
8bb08de666
commit
f21e823a65
4 files changed
+16
-37
No files matched your search
-2
@@ -6,7 +6,6 @@ import java.util.logging.Logger;
|
||||
import com.chargebee.Result;
|
||||
import com.chargebee.models.Subscription;
|
||||
import com.chargebee.models.Subscription.CancelForItemsRequest;
|
||||
import com.chargebee.models.enums.AccountReceivablesHandling;
|
||||
import com.chargebee.models.enums.CreditOptionForCurrentTermCharges;
|
||||
import com.chargebee.models.enums.RefundableCreditsHandling;
|
||||
import com.sap.sse.security.subscription.SubscriptionApiBaseService;
|
||||
@@ -37,7 +36,6 @@ public class ChargebeeCancelSubscriptionRequest extends ChargebeeApiRequest {
|
||||
logger.info(() -> "Cancel Chargebee subscription, subscription id: " + subscriptionId);
|
||||
CancelForItemsRequest request = Subscription.cancelForItems(subscriptionId)
|
||||
.creditOptionForCurrentTermCharges(CreditOptionForCurrentTermCharges.PRORATE)
|
||||
.accountReceivablesHandling(AccountReceivablesHandling.SCHEDULE_PAYMENT_COLLECTION)
|
||||
.refundableCreditsHandling(RefundableCreditsHandling.SCHEDULE_REFUND)
|
||||
.endOfTerm(false);
|
||||
return new ChargebeeInternalApiRequestWrapper(request);
|
||||
|
||||
+11
-30
@@ -12,7 +12,7 @@ import com.sap.sse.security.subscription.SubscriptionCancelResult;
|
||||
* Task to perform canceling a subscription by subscription id
|
||||
*/
|
||||
public class ChargebeeCancelSubscriptionTask
|
||||
implements ChargebeeSubscriptionRequest.OnResultListener, ChargebeeCancelSubscriptionRequest.OnResultListener {
|
||||
implements ChargebeeCancelSubscriptionRequest.OnResultListener {
|
||||
private static final Logger logger = Logger.getLogger(ChargebeeCancelSubscriptionTask.class.getName());
|
||||
|
||||
/**
|
||||
@@ -38,44 +38,25 @@ public class ChargebeeCancelSubscriptionTask
|
||||
|
||||
public void run() {
|
||||
logger.info(() -> "Schedule cancel Chargebee subscription, id: " + subscriptionId);
|
||||
requestProcessor.addRequest(new ChargebeeSubscriptionRequest(subscriptionId, this, requestProcessor, chargebeeApiServiceParams));
|
||||
requestProcessor.addRequest(new ChargebeeCancelSubscriptionRequest(subscriptionId, this, requestProcessor, chargebeeApiServiceParams));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscriptionResult(com.chargebee.models.Subscription subscription) {
|
||||
if (subscription != null) {
|
||||
Subscription sub = new ChargebeeApiSubscriptionData(subscription, /* invoice */null, /* transaction */ null)
|
||||
.toSubscription(chargebeeApiServiceParams.getSubscriptionPlanProvider());
|
||||
String status = subscription.status().name();
|
||||
if (status != null) {
|
||||
status = status.toLowerCase();
|
||||
}
|
||||
if (sub.getSubscriptionStatus().equals(ChargebeeSubscription.SUBSCRIPTION_STATUS_CANCELLED)
|
||||
|| sub.getSubscriptionStatus().equals(ChargebeeSubscription.SUBSCRIPTION_NON_RENEWING)) {
|
||||
onDone(new SubscriptionCancelResult(/* success */ true, sub));
|
||||
} else {
|
||||
requestProcessor.addRequest(new ChargebeeCancelSubscriptionRequest(subscriptionId, this,
|
||||
requestProcessor, chargebeeApiServiceParams));
|
||||
}
|
||||
} else {
|
||||
onDone(new SubscriptionCancelResult(/* success */false, /* subscription */null, /* deleted */true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscriptionCancelResult(com.chargebee.models.Subscription subscription) {
|
||||
if (subscription != null) {
|
||||
Subscription sub = (new ChargebeeApiSubscriptionData(subscription, null, null))
|
||||
.toSubscription(chargebeeApiServiceParams.getSubscriptionPlanProvider());
|
||||
boolean success = sub.getSubscriptionStatus().equals(ChargebeeSubscription.SUBSCRIPTION_STATUS_CANCELLED)
|
||||
|| sub.getSubscriptionStatus().equals(ChargebeeSubscription.SUBSCRIPTION_NON_RENEWING);
|
||||
onDone(new SubscriptionCancelResult(success, sub, /* deleted */ false));
|
||||
public void onSubscriptionCancelResult(com.chargebee.models.Subscription subscriptionModel) {
|
||||
if (subscriptionModel != null) {
|
||||
ChargebeeApiSubscriptionData apiSubscriptionData = new ChargebeeApiSubscriptionData(subscriptionModel, null, null);
|
||||
Subscription subscription = apiSubscriptionData.toSubscription(chargebeeApiServiceParams.getSubscriptionPlanProvider());
|
||||
boolean success = subscription.getSubscriptionStatus().equals(ChargebeeSubscription.SUBSCRIPTION_STATUS_CANCELLED);
|
||||
onDone(new SubscriptionCancelResult(success, subscription, /* deleted */ false));
|
||||
} else {
|
||||
onDone(new SubscriptionCancelResult(/* success */false, /* subscription */null, /* deleted */true));
|
||||
}
|
||||
}
|
||||
|
||||
private void onDone(SubscriptionCancelResult result) {
|
||||
logger.info("Subscription cancelation is done with success = " + result.isSuccess() +
|
||||
", deleted = " + result.isDeleted() +
|
||||
", subscription = " + result.getSubscription());
|
||||
if (listener != null) {
|
||||
listener.onCancelResult(result);
|
||||
}
|
||||
|
||||
+3
@@ -74,6 +74,9 @@ public class ChargebeeNonRenewingSubscriptionTask
|
||||
}
|
||||
|
||||
private void onDone(SubscriptionNonRenewingResult result) {
|
||||
logger.info("Setting subscription to non renewing is done with success = " + result.isSuccess() +
|
||||
", deleted = " + result.isDeleted() +
|
||||
", subscription = " + result.getSubscription());
|
||||
if (listener != null) {
|
||||
listener.onNonRenewingResult(result);
|
||||
}
|
||||
|
||||
@@ -119,16 +119,13 @@ This is only done after the new plan is subscribed successfully. It will cancel
|
||||
|
||||
end_of_term = false (1)
|
||||
credit_option_for_current_term_charges = PRORATE (2)
|
||||
account_receivables_handling = SCHEDULE_PAYMENT_COLLECTION (3)
|
||||
refundable_credits_handling = SCHEDULE_REFUND (4)
|
||||
refundable_credits_handling = SCHEDULE_REFUND (3)
|
||||
|
||||
1. The contract will be canceled immediately
|
||||
[chargebee docu](https://apidocs.chargebee.com/docs/api/subscriptions#cancel_subscription_for_items_end_of_term)
|
||||
2. The refund will be calculated out of the remaining days
|
||||
[chargebee docu](https://apidocs.chargebee.com/docs/api/subscriptions#cancel_subscription_for_items_credit_option_for_current_term_charges)
|
||||
3. All credits will be refunded on the available payment method
|
||||
[chargebee docu](https://apidocs.chargebee.com/docs/api/subscriptions#cancel_subscription_for_items_account_receivables_handling)
|
||||
4. Remaining refundable credits will be refunded asynchronously
|
||||
3Remaining refundable credits will be refunded asynchronously
|
||||
[chargebee docu](https://apidocs.chargebee.com/docs/api/subscriptions#cancel_subscription_for_items_refundable_credits_handling)
|
||||
|
||||
The result is that the old subscription state is set to `cancel`
|
||||
|
||||
Reference in new issue
Block a user