Question

“Slow test card, declines after a few minutes” not response status when decline.

  • 4 May 2024
  • 1 reply
  • 24 views

Badge

Dear Suuport team, 

As per check ‘getCustomerInfo’, it work for: 

- “Test card, always approves” / “Slow test card, approves after a  few minutes” and “Test card, always declines” but for “Slow test card, declines after a few minutes”, there is no response status of that case. 

May you advise in this case? 

Please kindly check the code below: 

Future<void> makePurchase(context, String numberOfEgg) async {
Map<String, dynamic> payload = {};
List<Map<dynamic, dynamic>> filteredItems = [];
bool slowCardApproval = true;
try {
filteredItems =
filterById(numberOfEgg, Platform.isIOS ? products : googleProducts);

if (filteredItems.isNotEmpty && !isPurchasePending) {
ref.read(purchaseInProgressProvider.notifier).setInProgress(true);

payload = {
'identifier': filteredItems[0]['identifier'],
'description': filteredItems[0]['description'],
'title': filteredItems[0]['title'],
'price': filteredItems[0]['price'],
'priceString': filteredItems[0]['priceString'],
'currencyCode': filteredItems[0]['currencyCode']
};

final payloadGooglePay = {
'identifier': filteredItems[0]['identifier'],
'description': filteredItems[0]['description'],
'title': filteredItems[0]['title'],
'price': filteredItems[0]['price'],
'priceString': filteredItems[0]['priceString'],
'currencyCode': filteredItems[0]['currencyCode'],
'productCategory': 'NON_SUBSCRIPTION',
};

CustomerInfo customerInfo = await Purchases.purchaseStoreProduct(
Platform.isIOS
? StoreProduct.fromJson(payload)
: StoreProduct.fromJson(payloadGooglePay));
// Check if the purchase is active
if (customerInfo
.entitlements
.all[Platform.isIOS
? dotenv.env['REVENUECAT_ENTITLEMENTS_APPLE']
: dotenv.env['REVENUECAT_ENTITLEMENTS_GOOGLE']]!
.isActive) {
isPurchasePending =
false; // Set isPurchasePending to false when a purchase is confirmed
ref
.read(purchaseInProgressProvider.notifier)
.setInProgress(false); // Add this line
final titleValue = getTitlePurchase(payload['title']);
final titleKoValue = getTitleKoPurchase(payload['title']);
ref.read(bonusEggsHistoryProvider).memberBonusAttend(
memberId: memberInfo.id!,
bonusEggQty: int.parse(numberOfEgg),
type: 1,
title: titleValue,
titleKo: titleKoValue,
);
// Create a new instance of MemberModel with the updated purchasedEggs value
if (memberInfo.id != null) {
final updatedMemberInfo = memberInfo.copyWith(
purchasedEggs:
memberInfo.purchasedEggs! + int.parse(numberOfEgg));
// Update memberInfo immediately after purchase is successful
ref
.read(memberInfoProvider.notifier)
.updateState(updatedMemberInfo);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChargeUseHistoryScreen(
purchasedEgg: filteredItems[0]['id'],
purchaseSuccessful: true,
)),
).then((value) => {
ref.refresh(memberObjByIdProvider(memberInfo.id)),
ref.refresh(memberObjByIdProvider(eggMember!.id)),
ref.refresh(memberObjProvider),
ref.refresh(memberInfoProvider),
ref.refresh(bonusEggsHistoryProvider),
ref.refresh(memberObjByIdProvider(memberInfo.id ?? 0)),
ref.refresh(usageEggHistoryFutureProvider(memberInfo.id!)),
ref.refresh(
purchasedEggHistoryFutureProvider(memberInfo.id!)),
ref.refresh(loadingProvider),
});
}
debugPrint('Purchase successful########################');
}
}
} catch (e) {
debugPrint('Purchase failed with error++++++++++++++++++: $e');

if (e is PlatformException) {
if (e.code == '3' || e.code == '1') {
isPurchasePending = false;
ref.read(purchaseInProgressProvider.notifier).setInProgress(false);
slowCardApproval = false;
Purchases.addCustomerInfoUpdateListener((customerInfo) async {
var entitlements = customerInfo.entitlements.all;
if (entitlements.isEmpty) {
slowCardApproval = false;
} else {
var latestPurchaseDate =
entitlements.values.first.latestPurchaseDate;
SharedPreferences prefs = await SharedPreferences.getInstance();
String? savedDate = prefs.getString('latestPurchaseDate');
if (savedDate != null &&
savedDate != latestPurchaseDate.toString()) {
slowCardApproval = false;
}
}
});
}
if (e.code == '20') {
slowCardApproval = true;
}
}
if (slowCardApproval) {
Purchases.addCustomerInfoUpdateListener((customerInfo) async {
var entitlements = customerInfo.entitlements.all;
debugPrint('entitlements*********************: $entitlements');
if (entitlements.isNotEmpty) {
var latestPurchaseDate =
entitlements.values.first.latestPurchaseDate;
SharedPreferences prefs = await SharedPreferences.getInstance();
String? savedDate = prefs.getString('latestPurchaseDate');
debugPrint(
'latestPurchaseDate*********************: $latestPurchaseDate');
debugPrint('savedDate*********************: $savedDate');
if (savedDate != null &&
savedDate != latestPurchaseDate.toString()) {
if (customerInfo
.entitlements
.all[Platform.isIOS
? dotenv.env['REVENUECAT_ENTITLEMENTS_APPLE']
: dotenv.env['REVENUECAT_ENTITLEMENTS_GOOGLE']]!
.isActive) {
isPurchasePending =
false; // Set isPurchasePending to false when a purchase is confirmed
ref
.read(purchaseInProgressProvider.notifier)
.setInProgress(false); // Add this line
final titleValue = getTitlePurchase(payload['title']);
final titleKoValue = getTitleKoPurchase(payload['title']);
ref.read(bonusEggsHistoryProvider).memberBonusAttend(
memberId: memberInfo.id!,
bonusEggQty: int.parse(numberOfEgg),
type: 1,
title: titleValue,
titleKo: titleKoValue,
);
// Create a new instance of MemberModel with the updated purchasedEggs value
if (memberInfo.id != null) {
final updatedMemberInfo = memberInfo.copyWith(
purchasedEggs:
memberInfo.purchasedEggs! + int.parse(numberOfEgg));
// Update memberInfo immediately after purchase is successful
ref
.read(memberInfoProvider.notifier)
.updateState(updatedMemberInfo);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChargeUseHistoryScreen(
purchasedEgg: filteredItems[0]['id'],
purchaseSuccessful: true,
)),
).then((value) => {
ref.refresh(memberObjByIdProvider(memberInfo.id)),
ref.refresh(memberObjByIdProvider(eggMember!.id)),
ref.refresh(memberObjProvider),
ref.refresh(memberInfoProvider),
ref.refresh(bonusEggsHistoryProvider),
ref.refresh(
memberObjByIdProvider(memberInfo.id ?? 0)),
ref.refresh(
usageEggHistoryFutureProvider(memberInfo.id!)),
ref.refresh(purchasedEggHistoryFutureProvider(
memberInfo.id!)),
ref.refresh(loadingProvider),
});
ref
.read(purchaseInProgressProvider.notifier)
.setInProgress(false);
}
debugPrint('Purchase successful########################');
}
}

await prefs.setString(
'latestPurchaseDate', latestPurchaseDate.toString());
}
});
}
}
}

 


This post has been closed for comments

1 reply

Userlevel 4
Badge +8

Hi, can you please run our SDK’s debug logs and post them here, it could be an error is being thrown there. You can enable them following our guide here and please include the entirety of them: https://www.revenuecat.com/docs/test-and-launch/debugging#section-debugging

Can you also let me know what version of our SDK you are using? We also have a guide on sandbox testing if you wanted to double-check you have everything setup correctly: https://www.revenuecat.com/docs/test-and-launch/sandbox