We have encountered a strange problem in the payment module of trigger.io. The flow works perfectly with ios payments but in android, some in-app payment callbacks are called twice in the same second. the receipt signatures are different but the orderid, notificationid, purchasetoken and developerPayload all stay the same. when we try to validate the receipt it turns out to be true and correct. But when we look at the financial report, we only see one payment instead of two (because its probably just one payment but why the different signatures?).
why is trigger.io calling the callback twice which leads to the product being bought twice? why is android returning 2 different and confirmable receipts for one payment? is this a bug on andorid side or trigger.io side, cause i have no way of calling the callback using javascipt? or is this a known hack attempt?
We also encountered a case where no callback was called at all, whereas the credit card was charged successfully. Is this a bug or are there any workarounds for this case?
here is the code i'm initiating a purchase:
if(forge.is.android())
forge.payments.purchaseProduct("someproductname", paymentSuccess, paymentError);
and here is the callback function:
function paymentCallback(data, confirm){
forge.request.ajax({
url: "someurl.php",
dataType: "json",
data:"function=logPayment&action=PaymentCallbackStart",
success: function (data) {
hideLoader();
},
error: function (error) {
hideLoader();
}
});
var productId = data.productId;
var orderId = data.orderId;
var signed_data;
if(forge.is.android())
{
var state = data.purchaseState;
var receipt = encodeURIComponent(data.receipt.signature);
signed_data = encodeURIComponent(data.receipt.data);
}
else if(forge.is.ios())
{
var state = data.PurchaseState;
var receipt = data.receipt.data;
}
forge.request.ajax({
url: "someurl.php",
dataType: "json",
data:"function=logPayment&data=" + encodeURIComponent("birthday=" + gbirthday + "&birthhour=" + gbirthhour + "&name=" + gname + "&gender=" + ggender + "&birthday2=" + gbirthday2 + "&birthhour2=" + gbirthhour2 + "&name2=" + gname2 + "&gender2=" + ggender2 + "&content=" + text + "&ProductID=" + qs.ProductID + "&userId=" + guserId + "&data=" + JSON.stringify(data)) + "&action=PaymentCallback",
success: function (data) {
hideLoader();
},
error: function (error) {
hideLoader();
}
});
if(state == "PURCHASED")
{
if(typeof gbirthday != "undefined")
{
var text = $('#imessagem').val();
forge.request.ajax({
url: "someurl.php",
dataType: "json",
data:"function=askQuestion&birthday=" + encodeURIComponent(gbirthday) + "&birthhour=" + encodeURIComponent(gbirthhour) + "&name=" + encodeURIComponent(gname) + "&gender=" + ggender + "&birthday2=" + encodeURIComponent(gbirthday2) + "&birthhour2=" + encodeURIComponent(gbirthhour2) + "&name2=" + encodeURIComponent(gname2) + "&gender2=" + ggender2 + "&content=" + encodeURIComponent(text) + "&ProductID=" + qs.ProductID + "&userId=" + guserId + "&signed_data=" + signed_data + "&receipt=" + receipt,
success: function (data) {
processPayment(productId,orderId)
hideLoader();
},
error: function (error) {
hideLoader();
forge.request.ajax({
url: "someurl.php",
dataType: "json",
data:"function=logPayment&data=" + encodeURIComponent(JSON.stringify(error)) + "&action=PaymentQuestionError",
success: function (data) {
hideLoader();
},
error: function (error) {
hideLoader();
}
});
}
});
forge.request.ajax({
url: "someurl.php",
dataType: "json",
data:"function=logPayment&data=" + encodeURIComponent(JSON.stringify(data)) + "&action=Payment",
success: function (data) {
hideLoader(); },
error: function (error) {
hideLoader();
}
});
}
if(forge.is.android())
processPayment(productId,orderId);
}
else
{
if(forge.is.ios())
processPayment(productId,orderId);
}
confirm();
}