iOS Question enhanced receipts for subscriptions, purchase

JohnnyHamburg

Member
Licensed User
Longtime User
No, I have not. Sorry, I thought that this would make it possible to validate the subscription without a server.
I have no experience on server and I am not sure how to do it.

My main problem at the moment is that if I call 'restoreTransactions' then my app receives the very first transaction date of the subscription but not the last renew date. That's all.

Maybe you might give me a hint for the way I have to go. On my webhoster I have the possibility to use php on a apache. But this can't be done with b4j, right?
I do not want to have a server at home on my private internetconnection.
So I have to learn a little php and validate the receipt in a php script?

Do I have to set up a database for all users? Or is the server only transmittig the receipt and sending back the validation to the app?

Sorry for so many questions.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
No, I have not. Sorry, I thought that this would make it possible to validate the subscription without a server.
I have no experience on server and I am not sure how to do it.

My main problem at the moment is that if I call 'restoreTransactions' then my app receives the very first transaction date of the subscription but not the last renew date. That's all.

Maybe you might give me a hint for the way I have to go. On my webhoster I have the possibility to use php on a apache. But this can't be done with b4j, right?
I do not want to have a server at home on my private internetconnection.
So I have to learn a little php and validate the receipt in a php script?

Do I have to set up a database for all users? Or is the server only transmittig the receipt and sending back the validation to the app?

Sorry for so many questions.

If I remember correct , script validation with the very first transaction id wil lstill give you correct results.
 
Upvote 0

JohnnyHamburg

Member
Licensed User
Longtime User
If I remember correct , script validation with the very first transaction id wil lstill give you correct results.

Hello tufanv,
I have read all your posts about this here and that you finally managed to use autorenewable subscriptions on apple. Can you give me some more advice, please? How did you validate the receipt? Via vps, php or direct from the app? Is there a possibility to receive the latest renew information using restore in the app?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Hello tufanv,
I have read all your posts about this here and that you finally managed to use autorenewable subscriptions on apple. Can you give me some more advice, please? How did you validate the receipt? Via vps, php or direct from the app? Is there a possibility to receive the latest renew information using restore in the app?
I am using curl within the php , which i send the transaction info , the php checks the receipt number with apple servers and return if it is a true purchase. I use this for normal in app purchases.

For subscriptions I also use this , but I am using non renewable so auto-renewing is totlally a different issue. about a year ago I did it but I can't remember how because i cant find my example project.


this is the function in the php I use :

B4X:
function validate_receipt($receipt_data) {

    //   $url = "https://sandbox.itunes.apple.com/verifyReceipt/";
      $url = "https://buy.itunes.apple.com/verifyReceipt";

    $ch = curl_init($url);
    $data_string = json_encode(array(
        'receipt-data' => $receipt_data,
        'password'     => 'CHANGE_THIS',
    ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
    );
    $output   = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if (200 != $httpCode) {
        die("Error validating App Store transaction receipt. Response HTTP code $httpCode");
    }
    $decoded = json_decode($output, TRUE);
    return $decoded;
}

you have to change CHANGE_THIS with your app sscret found on itunes connect developer page. To call this function in php you can use stg like:

B4X:
 $dekoder = validate_receipt($str);
     if ($dekoder['status']=='0' and strpos($trans, '00')  !== FALSE)      {

if you get 0 for status it means ok but sometimes fake purchases are treated as correct purchases so i added another thing to change the trans number if it has double zero's , all the valid receipts has at least 00 next to each other.
 
Upvote 0

ajk

Active Member
Licensed User
Longtime User
Unfortunately, my php is in its infancy.
Do you have any idea what a function written in PHP should look like in B4J?
I have servers in B4J, so implementing this function seems more natural.
 
Upvote 0
Top