iOS Question problem with in app purchase

tufanv

Expert
Licensed User
Hello,

I have an inapp purchase ( auto-renewing subscription ) in one of my apps. When I build it with non-store provision file , there is no problem with the in app purchase , the local price of the in app purchase shows correctly in my app and when i click to buy , it opens the purchase window of apple inside the app where you have to confirm the payment to finish.

Today, my app got approved , but the price of the inapp purchase shows blank there and when i click on the purchase I directly get msgbox saying " purchase not completed" which is the part :

B4X:
Sub myStore_PurchaseCompleted (Success As Boolean, Purchases As Purchase)

    
    Log("Purchase completed")
    If Purchases.IsInitialized Then

        Log("Product: " & Purchases.ProductIdentifier & ", date=" & DateTime.Time(Purchases.TransactionDate) & _
       ", Transaction identifier=" & Purchases.TransactionIdentifier)
    Else
        Msgbox("Purchase NOT Completed","Error")
 
    End If
end sub

this means that purchases are not initialized while in the distributed app . My only idea is app is approved 6 hours ago maybe something is not synced yet with stg. But if it is not the case , can it be a problem with stg ?

TY
 

Yvon Steinthal

Active Member
Licensed User
It is visible now. It means, we need some time to iap be available after first release.

Hello,

I am doing something similar and i had a question regarding... How do you know if the person bought your subscription?
I have a monthly subscription set up, and i want to check everytime the app is launched if the person is still a member or not... How to?
Any ideas?
 
Upvote 0

tufanv

Expert
Licensed User
Hello,

I am doing something similar and i had a question regarding... How do you know if the person bought your subscription?
I have a monthly subscription set up, and i want to check everytime the app is launched if the person is still a member or not... How to?
Any ideas?

You can save the user's purchase token ( which is a very long string ) on a remote database and associate the token to that user's mail for example, everytime you run the app, check the database for the token of that mail address. If you are able to do this setup I can help you with the server side verification of checking the subscription.
 
Upvote 0

Yvon Steinthal

Active Member
Licensed User
You can save the user's purchase token ( which is a very long string ) on a remote database and associate the token to that user's mail for example, everytime you run the app, check the database for the token of that mail address. If you are able to do this setup I can help you with the server side verification of checking the subscription.

Thanks for your reply, i am still trying to figure out how to do all this and test it. I am already using a server for my app for Database queries and algorithms so i dont think the implementation will be hard. However i just don't know how to test it all...
 
Upvote 0

tufanv

Expert
Licensed User
Thanks for your reply, i am still trying to figure out how to do all this and test it. I am already using a server for my app for Database queries and algorithms so i dont think the implementation will be hard. However i just don't know how to test it all...
-create a test account for purchases ( sandbox ) under ios developer account.
-Signout from appstore and login with your sandbox account

This is how you will do the tests, after a purchase completed store the long purchase token in a table in your db. for example user : tt@ww.com token: xxxxx....

With every program start, get the users associated token and check it on apple servers. This is the php code to do this: send the token to php and check it like this: ( if you are testing change the url to sandbox)

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'     => 'xxxxxxxxxx',
    ));
    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;
}

this is the function you have to use change the password with your shared secret on itunes connect account. , send the token to this php and use below code:

B4X:
print json_encode(validate_receipt($transid));

transid is the token you have stored.this will return you the status of auto renewing subscription or in app purchase as json .
 
Upvote 0
Top