I am new to in app buy integration, It is myfirst time however I am getting the difficulty.
Every time i make a transaction from any system with any logged in account, it robotically saves it for the primary account logged in (userid 6718d1d4c4d8cc8ae50de132) each time.
I’ve swap account, logged out and logged one other account in on my app to get a special userid, when i attempted the acquisition, identical difficulty, it solely will get saved for the primary userid. I attempted completely different gadgets too perhaps it was cached, identical factor.
Pls help, I am utilizing the apple retailer notification server and that i obtained the small print under which i decode
transactiondata: {
notificationType: 'EXPIRED',
subtype: 'VOLUNTARY',
notificationUUID: '33993256-fb6b-44c2-a6a1-e183e6936711',
information: {
appAppleId: 6737527243,
bundleId: '-X4JU4ZNDG.com.instance.podcella',
bundleVersion: '5',
atmosphere: 'Sandbox',
signedTransactionInfo: 'eyJhbGciOiJFUzI1NiIsIng1YyI6WyJNSUlFTURDQ0E3YWd....',
signedRenewalInfo: 'eyJhbGciOiJFUzI1NiIsIng1YyI6WyJNSUlFTURDQ0E3YWdBd0lCQWdJ...',
standing: 2
},
model: '2.0',
signedDate: 1730559317958
}
transactiondata2: {
transactionId: '2000000762928300',
originalTransactionId: '2000000759306490',
webOrderLineItemId: '2000000079532551',
bundleId: '-X4JU4ZNDG.com.instance.podcella',
productId: 'com.podcella.monthlysubscription',
subscriptionGroupIdentifier: '21571853',
purchaseDate: 1730558583000,
originalPurchaseDate: 1730257647000,
expiresDate: 1730558883000,
amount: 1,
kind: 'Auto-Renewable Subscription',
inAppOwnershipType: 'PURCHASED',
signedDate: 1730559317937,
atmosphere: 'Sandbox',
transactionReason: 'RENEWAL',
storefront: 'NGA',
storefrontId: '143561',
value: 1900000,
forex: 'NGN'
}
under is my endpoint code
// Shared secret and Google API variables as outlined in your code
const APPLE_SHARED_SECRET = course of.env.APPLE_SHARED_SECRET;
const GOOGLE_PACKAGE_NAME = 'com.instance.podcella';
const GOOGLE_PRODUCT_ID_WEEKLY = 'com.podcella.weeklysubscription';
const GOOGLE_PRODUCT_ID_MONTHLY = 'com.podcella.monthlysubscription';
const GOOGLE_PRODUCT_ID_YEARLY = 'com.podcella.yearlysubscription';
// const GOOGLE_API_ACCESS_TOKEN = 'your_google_api_access_token';
// Replace Subscription After Buy
const updateSubscriptionAfterPurchase = async (req, res) => {
const { signedPayload, purchaseToken } = req.physique;
// console.log('Acquired notification:', req.physique);
attempt {
let paymentPlan, quantity, planExpiryDate, transactionData, transactionData2;
if (signedPayload) {
const decodedPayload = jwt.decode(signedPayload, { full: true });
transactionData = decodedPayload?.payload;
console.log('transactiondata: ', transactionData);
//second decoding
const decodedPayload2 = jwt.decode(transactionData.information.signedTransactionInfo, { full: true });
transactionData2 = decodedPayload2?.payload;
console.log('transactiondata2: ', transactionData2);
if (!transactionData2) {
return res.standing(400).json({ message: 'Apple signedPayload decoding failed' });
}
paymentPlan = mapApplePlan(transactionData2);
// quantity = getAppleAmount(transactionData2);
if (transactionData2.forex === 'NGN') {
quantity = transactionData2.value / 1000;
} else {
quantity = transactionData2.value;
}
planExpiryDate = new Date(parseInt(transactionData2.expiresDate));
// console.log(paymentPlan);
// console.log(quantity);
// console.log(planExpiryDate);
} else if (purchaseToken) {
const googleResponse = await verifyGooglePurchase(purchaseToken);
if (!googleResponse || !googleResponse.information) {
return res.standing(400).json({ message: 'Google transaction verification failed' });
}
const subscriptionData = googleResponse.information;
paymentPlan = mapGooglePlan(subscriptionData);
quantity = getGoogleAmount(subscriptionData);
planExpiryDate = new Date(parseInt(subscriptionData.expiryTimeMillis));
transactionData = subscriptionData; // Utilizing for uniform construction
}
if (!paymentPlan || !quantity) {
return res.standing(400).json({ message: 'Invalid fee plan or quantity' });
}
const consumer = await Person.findOne({
$or: [
{ 'subscription.appleTransactionId': transactionData2?.originalTransactionId },
{ 'subscription.googlePurchaseToken': purchaseToken }
]
});
console.log(consumer?.id);
console.log("Person up to date efficiently");
if (!consumer) {
return res.standing(404).json({ message: 'Person not discovered' });
}
consumer.subscription = ;
await consumer.save();
const transaction = await Transaction.create({
userId: consumer._id,
paymentPlan,
quantity,
standing: 'accomplished'
});
res.standing(200).json({
message: 'Subscription up to date efficiently!',
transaction,
});
console.log("Transaction up to date efficiently");
} catch (error) {
console.error('Error updating subscription:', error);
res.standing(500).json({ message: 'Error updating subscription', error: error.message });
}
};
// Apple Plan Mapping Operate
operate mapApplePlan(transactionData2) {
const productId = transactionData2.productId;
swap (productId) {
case 'com.podcella.weeklysubscription':
return 'weekly';
case 'com.podcella.monthlysubscription':
return 'month-to-month';
case 'com.podcella.yearlysubscription':
return 'yearly';
default:
return 'inactive';
}
}
// Google verification operate stays the identical
async operate verifyGooglePurchase(purchaseToken) {
const url = `https://androidpublisher.googleapis.com/androidpublisher/v3/purposes/${GOOGLE_PACKAGE_NAME}/purchases/subscriptions/${GOOGLE_PRODUCT_ID}/tokens/${purchaseToken}`;
const headers = { Authorization: `Bearer ${GOOGLE_API_ACCESS_TOKEN}` };
return await axios.get(url, { headers });
}
I would like transaction to replace for the consumer that made that transaction, in the intervening time, solely this userid is gotten 6718d1d4c4d8cc8ae50de132. regardless of testing the in app buy with one other system and account completely different account.
each time, it is alway this 6718d1d4c4d8cc8ae50de132