HomeiOS DevelopmentThe best way to use a easy PHP Script to confirm iOS...

The best way to use a easy PHP Script to confirm iOS In App Fee Receipt utilizing Flutter in_app_payment plugin


For the Consumer Facet I used following Code to ship Request to the Server:

  Future<http.Response> validateReceiptServer(Map<String, String> receiptBody) async {
    const String url="..."; // Your Server URL right here
    return await http.put up(
      Uri.parse(url),
      headers: {
        'Settle for': 'utility/json',
        'Content material-Kind': 'utility/json',
      },
      physique: json.encode(receiptBody),
    );
  }

This Perform may be known as like that, when verifying a Receipt

http.Response response = await validateReceiptServer(<String, String>{
  'receipt-data': purchaseDetails.verificationData.serverVerificationData, // receipt key you'll obtain in request buy callback operate
});

Within the Server I take advantage of CURL to ship the information to Apple. With a Fallback if the response is 21007 to Ship the request to Sandbox Server. This fashion you do not have to alter something when testing.

<?php
    header('Content material-Kind: utility/json; charset=utf-8');
    
    operate verifyReceipt($retailer, $put up) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$retailer);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $put up);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec ($ch);
        curl_close ($ch);
        return json_decode($response);
    }

    $inputJSON = file_get_contents('php://enter');
    $enter = json_decode($inputJSON, TRUE);
    
    //ios receipt verification
    $json['receipt-data'] = $enter['receipt-data'];
    $json['password'] = '...'; // Your key from App Retailer Join right here.

    $put up = json_encode($json);

    $retailer = "https://purchase.itunes.apple.com/verifyReceipt";
    $response = verifyReceipt($retailer, $put up);
    if($response->standing == 21007) {
        $response = verifyReceipt("https://sandbox.itunes.apple.com/verifyReceipt", $put up);
    }
    print(json_encode($response));
?>

This may permit you to confirm receipts utilizing PHP. What ought to be added is:

  • to make use of personalized response that’s despatched to the consumer.
  • Verify if the receipt is already expired.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments