Skip to content

Commit

Permalink
Merge pull request #32 from mushthaq33/master
Browse files Browse the repository at this point in the history
Fixing product-apim/issues/12505
  • Loading branch information
mushiR33 authored Mar 3, 2022
2 parents 4663001 + 4f2f473 commit 29c0859
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 138 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</repository>
</repositories>

<properties>
<carbon.apimgt.version>9.0.17</carbon.apimgt.version>
<carbon.apimgt.version>9.20.1</carbon.apimgt.version>
<commons.lang.version>2.6</commons.lang.version>
<stripe.version>9.8.0</stripe.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class StripeMonetizationConstants {
" INSERT" +
" INTO AM_MONETIZATION_SUBSCRIPTIONS (SUBSCRIBED_API_ID, SUBSCRIBED_APPLICATION_ID," +
" TENANT_ID, SHARED_CUSTOMER_ID, SUBSCRIPTION_ID)" +
" VALUES (?,?,?,?,?)";
" VALUES ((SELECT API_ID FROM AM_API WHERE API_UUID = ?),?,?,?,?)";

public static final String GET_BE_PLATFORM_CUSTOMER_SQL =
"SELECT" +
Expand All @@ -82,7 +82,9 @@ public class StripeMonetizationConstants {
" ID, SUBSCRIPTION_ID" +
" FROM AM_MONETIZATION_SUBSCRIPTIONS" +
" WHERE" +
" SUBSCRIBED_APPLICATION_ID=? AND SUBSCRIBED_API_ID=? AND TENANT_ID=?";
" SUBSCRIBED_APPLICATION_ID=? " +
" AND SUBSCRIBED_API_ID=(SELECT API_ID FROM AM_API WHERE API_UUID=?)" +
" AND TENANT_ID=?";

public static final String DELETE_BE_SUBSCRIPTION_SQL = "DELETE FROM AM_MONETIZATION_SUBSCRIPTIONS WHERE ID=?";

Expand Down Expand Up @@ -143,10 +145,12 @@ public class StripeMonetizationConstants {
public static final String TIME_FILTER = "timeFilter";
public static final String API_USAGE_BY_APP_FILTER = "successAPIUsageByAppFilter";
public static final String API_NAME = "apiName";
public static final String API_UUID = "apiId";
public static final String API_VERSION = "apiVersion";
public static final String TENANT_DOMAIN = "apiCreatorTenantDomain";
public static final String COUNT = "count";
public static final String APPLICATION_NAME = "applicationName";
public static final String APPLICATION_OWNER = "applicationOwner";
public static final String GET_USAGE_BY_APPLICATION = "getSuccessAPIsUsageByApplications";
public static final String AT = "@";
}
Original file line number Diff line number Diff line change
Expand Up @@ -628,29 +628,22 @@ public int addBESharedCustomer(MonetizationSharedCustomer sharedCustomer) throws
* @param tenandId Id of the tenant
* @param sharedCustomerId Id of the shared customer
* @param subscriptionId Id of the Billing Engine Subscriptions
* @param apiUuid UUID of the API
* @return Id of the customer record in the database
* @throws StripeMonetizationException If Failed To add Billing Engine Shared Customer details
*/
public void addBESubscription(APIIdentifier identifier, int applicationId, int tenandId,
int sharedCustomerId, String subscriptionId) throws StripeMonetizationException {
public void addBESubscription(APIIdentifier identifier, int applicationId, int tenandId, int sharedCustomerId,
String subscriptionId, String apiUuid) throws StripeMonetizationException {

Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
int apiId;
try {
conn = APIMgtDBUtil.getConnection();
conn.setAutoCommit(false);
try {
apiId = apiMgtDAO.getAPIID(identifier, conn);
} catch (APIManagementException e) {
String errorMessage = "Failed to get the ID of the API " + identifier.getApiName();
log.error(errorMessage);
throw new StripeMonetizationException(errorMessage, e);
}
String query = StripeMonetizationConstants.ADD_BE_SUBSCRIPTION_SQL;
ps = conn.prepareStatement(query);
ps.setInt(1, apiId);
ps.setString(1, apiUuid);
ps.setInt(2, applicationId);
ps.setInt(3, tenandId);
ps.setInt(4, sharedCustomerId);
Expand Down Expand Up @@ -779,38 +772,27 @@ public void removeMonetizedSubscription(int id) throws StripeMonetizationExcepti
/**
* Get billing engine Subscription info
*
* @param apiUuid UUID of the API
* @param apiName api name
* @param apiVersion api version
* @param apiProvider api provider
* @param applicationId Id of the Application
* @param tenantDomain tenant domain
* @return MonetizationSubscription info of Billing Engine Subscription
* @throws StripeMonetizationException If Failed To get Billing Engine Subscription details
*/
public MonetizedSubscription getMonetizedSubscription(String apiName, String apiVersion, String apiProvider,
int applicationId, String tenantDomain)
throws StripeMonetizationException {
public MonetizedSubscription getMonetizedSubscription(String apiUuid, String apiName, int applicationId,
String tenantDomain) throws StripeMonetizationException {

Connection conn = null;
PreparedStatement ps = null;
ResultSet result = null;
int apiId;
MonetizedSubscription monetizedSubscription = new MonetizedSubscription();
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
APIIdentifier identifier = new APIIdentifier(apiProvider, apiName, apiVersion);
String sqlQuery = StripeMonetizationConstants.GET_BE_SUBSCRIPTION_SQL;
try {
conn = APIMgtDBUtil.getConnection();
try {
apiId = apiMgtDAO.getAPIID(identifier, conn);
} catch (APIManagementException e) {
String errorMessgae = "Failed to get ID for API : " + apiName;
log.error(errorMessgae);
throw new StripeMonetizationException(errorMessgae, e);
}
ps = conn.prepareStatement(sqlQuery);
ps.setInt(1, applicationId);
ps.setInt(2, apiId);
ps.setString(2, apiUuid);
ps.setInt(3, tenantId);
result = ps.executeQuery();
if (result.next()) {
Expand Down
Loading

0 comments on commit 29c0859

Please sign in to comment.