Skip to content

Commit

Permalink
[DELIVERY-70570] Android + iOS updates
Browse files Browse the repository at this point in the history
* Update Gradle propperties to run the Android sample project;
* Update Android AppsFlyer SDK to version 6.15.1
* Implement validateAndLog (BETA) API
* Implement logAdrevenue API
* Add new files to the Android.mk
* Finish iOS completion callback for `validateAndLog`
  • Loading branch information
af-obodovskyi committed Oct 15, 2024
1 parent c8accc8 commit ab3e1aa
Show file tree
Hide file tree
Showing 21 changed files with 422 additions and 52 deletions.
51 changes: 43 additions & 8 deletions Classes/AppsFlyer/AFSDKXPurchaseDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#include <stdio.h>
#include "AFSDKXPurchaseDetails.h"

AFSDKXPurchaseDetails::AFSDKXPurchaseDetails(const std::string &productId,
const std::string &price,
const std::string &currency,
const std::string &transactionId)
: productId_(productId),
price_(price),
currency_(currency),
transactionId_(transactionId) {
AFSDKXPurchaseDetails::AFSDKXPurchaseDetails(const AFXPurchaseType &purchaseType,
const std::string &purchaseToken,
const std::string &productId,
const std::string &price,
const std::string &currency,
const std::string &transactionId)
:purchaseType_(purchaseType),
purchaseToken_(purchaseToken),
productId_(productId),
price_(price),
currency_(currency),
transactionId_(transactionId) {
}

std::string AFSDKXPurchaseDetails::getProductId() const {
Expand Down Expand Up @@ -49,3 +53,34 @@ std::string AFSDKXPurchaseDetails::getTransactionId() const {
void AFSDKXPurchaseDetails::setTransactionId(const std::string &transactionId) {
transactionId_ = transactionId;
}

std::string AFSDKXPurchaseDetails::getPurchaseToken() const {
return purchaseToken_;
}

void AFSDKXPurchaseDetails::setPurchaseToken(const std::string &purchaseToken) {
purchaseToken_ = purchaseToken;
}

std::string AFSDKXPurchaseDetails::getPurchaseType() const {
std::string purchaseTypeStr = purchaseTypeToString();
return purchaseTypeStr;
}

void AFSDKXPurchaseDetails::setPurchaseType(AFXPurchaseType &purchaseType) {
purchaseType_ = purchaseType;
}

// Function to get the string value of the enum
std::string AFSDKXPurchaseDetails::purchaseTypeToString() const{
switch (purchaseType_) {
case AFXPurchaseType::SUBSCRIPTION:
return "subscription";
case AFXPurchaseType::ONE_TIME_PURCHASE:
return "one_time_purchase";
case AFXPurchaseType::APPLE:
return "";
default:
return "";
}
}
28 changes: 24 additions & 4 deletions Classes/AppsFlyer/AFSDKXPurchaseDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@
#include "cocos2d.h"
#include "AFSDKXValidateAndLogResult.h"

enum class AFXPurchaseType {
SUBSCRIPTION,
ONE_TIME_PURCHASE,
APPLE
};


class AFSDKXPurchaseDetails {
public:
// Deleted default constructor to prevent usage.
AFSDKXPurchaseDetails() = delete;

// Constructor with parameters to initialize the properties.
AFSDKXPurchaseDetails(const std::string &productId,
const std::string &price,
const std::string &currency,
const std::string &transactionId);
AFSDKXPurchaseDetails(const AFXPurchaseType &purchaseType,
const std::string &purchaseToken,
const std::string &productId,
const std::string &price,
const std::string &currency,
const std::string &transactionId);

// Default destructor.
virtual ~AFSDKXPurchaseDetails() = default;
Expand All @@ -44,11 +52,23 @@ class AFSDKXPurchaseDetails {
std::string getTransactionId() const;
void setTransactionId(const std::string &transactionId);

// Propperties related to Android impl
// For Apple implementation, please pass APPLE, it will be interpreted as an empty string
std::string purchaseTypeToString() const;
std::string getPurchaseType() const;
void setPurchaseType(AFXPurchaseType &purchaseType);

// Android purchase token, for iOS impl, please use empty string
std::string getPurchaseToken() const;
void setPurchaseToken(const std::string &purchaseToken);

private:
// Private member variables.
std::string productId_;
std::string price_;
std::string currency_;
std::string transactionId_;
std::string purchaseToken_;
AFXPurchaseType purchaseType_;
};
#endif /* AFSDKXPurchaseDetails_h */
19 changes: 17 additions & 2 deletions Classes/AppsFlyer/AFSDKXValidateAndLogResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AFSDKXValidateAndLogResult::AFSDKXValidateAndLogResult(
AFSDKXValidateAndLogStatus status,
const cocos2d::ValueMap& result,
const cocos2d::ValueMap& errorData,
const std::shared_ptr<Error>& error)
const cocos2d::ValueMap& error)
: status_(status), result_(result), errorData_(errorData), error_(error) {
}

Expand All @@ -30,6 +30,21 @@ cocos2d::ValueMap AFSDKXValidateAndLogResult::getErrorData() const {
return errorData_;
}

std::shared_ptr<Error> AFSDKXValidateAndLogResult::getError() const {
cocos2d::ValueMap AFSDKXValidateAndLogResult::getError() const {
return error_;
}

// Function to map Objective-C enum to C++ enum
AFSDKXValidateAndLogStatus AFSDKXValidateAndLogResult::objcEnumToCppEnum(int objcStatus) {
switch (objcStatus) {
case 0:
return AFSDKXValidateAndLogStatus::Success;
case 1:
return AFSDKXValidateAndLogStatus::Failure;
case 2:
return AFSDKXValidateAndLogStatus::Error;
default:
// Handle unknown cases, or return a default value
return AFSDKXValidateAndLogStatus::Error;
}
}
8 changes: 5 additions & 3 deletions Classes/AppsFlyer/AFSDKXValidateAndLogResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ class AFSDKXValidateAndLogResult {
AFSDKXValidateAndLogResult(AFSDKXValidateAndLogStatus status,
const cocos2d::ValueMap& result,
const cocos2d::ValueMap& errorData,
const std::shared_ptr<Error>& error);
const cocos2d::ValueMap& error);

// Getter methods
AFSDKXValidateAndLogStatus getStatus() const;
static AFSDKXValidateAndLogStatus objcEnumToCppEnum(int objcStatus);
cocos2d::ValueMap getResult() const;
cocos2d::ValueMap getErrorData() const;
std::shared_ptr<Error> getError() const;
cocos2d::ValueMap getError() const;


private:
// Member variables.
AFSDKXValidateAndLogStatus status_;
cocos2d::ValueMap result_;
cocos2d::ValueMap errorData_;
std::shared_ptr<Error> error_;
cocos2d::ValueMap error_;
};

#endif /* AFSDKXValidateAndLogResult_h */
35 changes: 35 additions & 0 deletions Classes/AppsFlyer/AFXAdRevenueData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,41 @@ AppsFlyerXAdRevenueMediationNetworkType AFXAdRevenueData::getMediationNetwork()
return mediationNetwork;
}

std::string AFXAdRevenueData::meditationNetworkString() const {
switch (mediationNetwork) {
case AppsFlyerXAdRevenueMediationNetworkType::GoogleAdMob:
return "GOOGLE_ADMOB";
case AppsFlyerXAdRevenueMediationNetworkType::IronSource:
return "IRONSOURCE";
case AppsFlyerXAdRevenueMediationNetworkType::ApplovinMax:
return "APPLOVIN_MAX";
case AppsFlyerXAdRevenueMediationNetworkType::Fyber:
return "FYBER";
case AppsFlyerXAdRevenueMediationNetworkType::Appodeal:
return "APPODEAL";
case AppsFlyerXAdRevenueMediationNetworkType::Admost:
return "ADMOST";
case AppsFlyerXAdRevenueMediationNetworkType::Topon:
return "TOPON";
case AppsFlyerXAdRevenueMediationNetworkType::Tradplus:
return "TRADPLUS";
case AppsFlyerXAdRevenueMediationNetworkType::Yandex:
return "YANDEX";
case AppsFlyerXAdRevenueMediationNetworkType::ChartBoost:
return "CHARTBOOST";
case AppsFlyerXAdRevenueMediationNetworkType::Unity:
return "UNITY";
case AppsFlyerXAdRevenueMediationNetworkType::ToponPte:
return "TOPON_PTE";
case AppsFlyerXAdRevenueMediationNetworkType::Custom:
return "CUSTOM_MEDIATION";
case AppsFlyerXAdRevenueMediationNetworkType::DirectMonetization:
return "DIRECT_MONETIZATION_NETWORK";
default:
return "unknown";
}
};

std::string AFXAdRevenueData::getCurrencyIso4217Code() const {
return currencyIso4217Code;
}
Expand Down
1 change: 1 addition & 0 deletions Classes/AppsFlyer/AFXAdRevenueData.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AFXAdRevenueData {
std::string getCurrencyIso4217Code() const;
double getEventRevenue() const;
int convertMeditationType(AppsFlyerXAdRevenueMediationNetworkType a);
std::string meditationNetworkString() const;

private:
// Private member variables
Expand Down
3 changes: 3 additions & 0 deletions Classes/AppsFlyer/AppsFlyerX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ void AppsFlyerX::validateAndLogInAppPurchase(const std::string& publicKey,
void AppsFlyerX::logAdRevenue(AFXAdRevenueData adRevenueData, cocos2d::ValueMap additionalParameters) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// Android implementation
CCLOGWARN("Log AdRevenue Android");
AppsFlyerXAndroid::logAdRevenue(adRevenueData, additionalParameters);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
AppsFlyerXApple::logAdRevenue(adRevenueData, additionalParameters);
#endif
Expand All @@ -343,6 +345,7 @@ void AppsFlyerX::logAdRevenue(AFXAdRevenueData adRevenueData, cocos2d::ValueMap
void AppsFlyerX::validateAndLogInAppPurchase(AFSDKXPurchaseDetails &details, cocos2d::ValueMap params, std::function<void(AFSDKXValidateAndLogResult)> completionHandler) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// Android implementation
AppsFlyerXAndroid::validateAndLogInAppPurchase(details, std::move(params), std::move(completionHandler));
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
AppsFlyerXApple::validateAndLogInAppPurchase(details, params, completionHandler);
#endif
Expand Down
Loading

0 comments on commit ab3e1aa

Please sign in to comment.