Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing features relating to premium app subscriptions #2667

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
46fe370
Add missing features relating to premium app subscriptions
Tobias123567 Apr 27, 2024
d456ca7
Add missing documentations
Tobias123567 Apr 27, 2024
a8291b4
Add range check for percent off
Tobias123567 Apr 27, 2024
5310011
Remove Store endpoints as they are discontinued
Tobias123567 Apr 27, 2024
dbbb12e
Remove sku retrieval
Tobias123567 May 4, 2024
fab28ca
Add string id overrides
Tobias123567 May 4, 2024
034a514
Add missing nullability annotation
Tobias123567 May 4, 2024
cef74d9
Remove payment data from entitlements
Tobias123567 May 4, 2024
49034ad
Return TestEntitlementCreateAction instead of void
Tobias123567 May 4, 2024
42c45c8
Do not use import of implementation class
Tobias123567 May 4, 2024
621742e
Remove UNKNOWN OwnerType
Tobias123567 May 4, 2024
e8206d0
Add documentation for OwnerType
Tobias123567 May 4, 2024
ac314cb
Rename wasConsumed method to isConsumed
Tobias123567 May 4, 2024
d123470
Do not throw exception instead return completed rest action
Tobias123567 May 4, 2024
c8d50d6
Do not change the entitlement state
Tobias123567 May 4, 2024
aaddf0f
Add copyright headers
Tobias123567 May 4, 2024
245cc83
Fix coding style
Tobias123567 May 5, 2024
244458e
Add nonnull checks
Tobias123567 May 5, 2024
5b92b07
Use Long.unsignedLong instead of String.valueOf
Tobias123567 May 5, 2024
a5b52c6
Fix route names
Tobias123567 May 5, 2024
d4f6c58
Fix docs
Tobias123567 May 5, 2024
c08f4bb
Add missing string id overload
Tobias123567 May 5, 2024
0aeba3d
Use constructor values
Tobias123567 May 5, 2024
6522797
Fix docs
Tobias123567 May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.dv8tion.jda.internal.requests.CompletedRestAction;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.requests.restaction.TestEntitlementCreateActionImpl;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.EntityString;
import net.dv8tion.jda.internal.utils.Helpers;
Expand Down Expand Up @@ -1884,6 +1885,15 @@ default List<RichCustomEmoji> getEmojisByName(@Nonnull String name, boolean igno
@CheckReturnValue
RestAction<ApplicationInfo> retrieveApplicationInfo();

/**
* Retrieves the list of {@link Sku SKUs}.
*
* @return {@link RestAction} - Type: {@link List} of {@link Sku}
*/
@Nonnull
@CheckReturnValue
RestAction<List<Sku>> retrieveSkus();
Tobias123567 marked this conversation as resolved.
Show resolved Hide resolved

/**
* A {@link net.dv8tion.jda.api.requests.restaction.pagination.PaginationAction PaginationAction} implementation
* which allows you to {@link Iterable iterate} over {@link Entitlement}s that are applicable to the logged in application.
Expand All @@ -1894,6 +1904,47 @@ default List<RichCustomEmoji> getEmojisByName(@Nonnull String name, boolean igno
@CheckReturnValue
EntitlementPaginationAction retrieveEntitlements();

/**
* Retrieves an {@link Entitlement} by its id.
*
* @param entitlementId
* The id of the entitlement to retrieve
*
* @return {@link EntitlementAction EntitlementAction}
* <br>Allows to also get payment details for the entitlement
*/
@Nonnull
@CheckReturnValue
EntitlementAction retrieveEntitlementById(long entitlementId);
Tobias123567 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Constructs a new {@link Entitlement Entitlement} with the skuId and the type.
* <br>Use the returned {@link GuildAction GuildAction} to provide
* further details in the future
* <br>Right now discord does not have more details to provide.
Tobias123567 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param skuId
* The id of the SKU the entitlement is for
*
* @return {@link TestEntitlementCreateAction TestEntitlementCreateAction}
* <br>Allows for setting various details for the resulting Entitlement
*/
@Nonnull
@CheckReturnValue
TestEntitlementCreateAction createTestEntitlement(long skuId, long ownerId, TestEntitlementCreateActionImpl.OwnerType ownerType);
Tobias123567 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes a test entitlement by its id.
*
* @param entitlementId
* The id of the entitlement to delete
*
* @return {@link RestAction} - Type: Void
*/
@Nonnull
@CheckReturnValue
RestAction<Void> deleteTestEntitlement(long entitlementId);

/**
* Configures the required scopes applied to the {@link #getInviteUrl(Permission...)} and similar methods.
* <br>To use slash commands you must add {@code "applications.commands"} to these scopes. The scope {@code "bot"} is always applied.
Expand Down
146 changes: 144 additions & 2 deletions src/main/java/net/dv8tion/jda/api/entities/Entitlement.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.api.utils.data.SerializableData;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -104,8 +109,6 @@ default String getGuildId()

/**
* The type of the Entitlement
* <br>The only possible type of Entitlement currently is {@link EntitlementType#APPLICATION_SUBSCRIPTION}
* <br>Discord doesn't currently support other types for entitlements.
MinnDevelopment marked this conversation as resolved.
Show resolved Hide resolved
*
* @return the {@link Entitlement Entitlement} type
*/
Expand Down Expand Up @@ -137,11 +140,69 @@ default String getGuildId()
@Nullable
OffsetDateTime getTimeEnding();

/**
* The payment data for this {@link Entitlement Entitlement}
*
* @return The payment data for this {@link Entitlement Entitlement}
*/
@Nullable
PaymentData getPaymentData();

/**
* Whether the {@link Entitlement Entitlement} was consumed or not.
*
* @return True if the {@link Entitlement Entitlement} was consumed, False otherwise
*/
boolean wasConsumed();
Tobias123567 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Consumes the {@link Entitlement Entitlement} if it has not already been consumed.
Tobias123567 marked this conversation as resolved.
Show resolved Hide resolved
*
* @throws IllegalStateException
* If the {@link Entitlement Entitlement} has already been consumed
*
* @return A {@link RestAction} that will consume the {@link Entitlement Entitlement}
*/
@Nonnull
@CheckReturnValue
RestAction<Void> consume();

/**
* Represents the type of this Entitlement
*/
enum EntitlementType
{
/**
* Entitlement was purchased by user
*/
PURCHASE(1),
MinnDevelopment marked this conversation as resolved.
Show resolved Hide resolved
/**
* Entitlement for Discord Nitro subscription
*/
PREMIUM_SUBSCRIPTION(2),
/**
* Entitlement was gifted by developer
*/
DEVELOPER_GIFT(3),
/**
* Entitlement was purchased by a dev in application test mode
*/
TEST_MODE_PURCHASE(4),
/**
* Entitlement was granted when the SKU was free
*/
FREE_PURCHASE(5),
/**
* Entitlement was gifted by another user
*/
USER_GIFT(6),
/**
* Entitlement was claimed by user for free as a Nitro Subscriber
*/
PREMIUM_PURCHASE(7),
/**
* Entitlement was purchased as an app subscription
*/
APPLICATION_SUBSCRIPTION(8),
/**
* Placeholder for unsupported types.
Expand Down Expand Up @@ -185,4 +246,85 @@ public static EntitlementType fromKey(int key)
return UNKNOWN;
}
}

class PaymentData implements SerializableData
Tobias123567 marked this conversation as resolved.
Show resolved Hide resolved
{

private final String id;
private final String currency;
private final int amount;
private final int tax;
private final boolean taxInclusive;

public PaymentData(String id, String currency, int amount, int tax, boolean taxInclusive) {
this.id = id;
this.currency = currency;
this.amount = amount;
this.tax = tax;
this.taxInclusive = taxInclusive;
}

/**
* unique ID of the payment
*
* @return The unique ID of the payment
*/
public String getId()
{
return id;
}

/**
* The currency the payment was made in
*
* @return The currency the payment was made in
*/
public String getCurrency()
{
return currency;
}

/**
* The amount paid
*
* @return The amount paid
*/
public int getAmount()
{
return amount;
}

/**
* The amount of tax
*
* @return The amount of tax
*/
public int getTax()
{
return tax;
}

/**
* Whether the amount is tax-inclusive
*
* @return True if the amount is tax-inclusive, False otherwise
*/
public boolean isTaxInclusive()
{
return taxInclusive;
}

@Nonnull
@Override
public DataObject toData()
{
DataObject object = DataObject.empty();
object.put("id", id);
object.put("currency", currency);
object.put("amount", amount);
object.put("tax", tax);
object.put("tax_inclusive", taxInclusive);
return object;
}
}
}
Loading