2013-11-26 70 views
0

我打電話給服務器發送數字產品,我想讓服務器檢查付款是否已完成。我正在使用應用內結算以及Android應用的PayPal移動結賬。從服務器檢索支付數據谷歌播放應用內付款和PayPal移動支付

他們得到一個RESULT_OK,然後我打電話給服務器,但我想要服務器驗證付款是否完成。

我發現了一些文檔,但它不是很清楚我應該使用什麼。

對於谷歌Play應用我應該可以檢查這個帖子:

www.googleapis.com/androidpublisher/v1.1/applications/{packageName}/inapp/{productId}/purchases/{token} 

我找不到產品ID是什麼,但我猜這是我送的SKU,以及我在哪裏得到令牌?

貝寶,我發現:

GET https://api.paypal.com/v1/payments/sale/{id} 

這使得它更加清楚一點,但我不知道如何將其轉換成PHP:https://quar.me/paypal/rest/_sales_look-up-a-sale.html

但在文檔看起來id與我在應用中使用的不一樣,並且不起作用。它沒有返回,我的ID是這樣的AP-8BH89990X7137743X:

{ 
    "name": "INVALID_RESOURCE_ID", 
    "message": "The requested resource ID was not found", 
    "information_link": "https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID", 
    "debug_id": "fec9d138aa55d" 
} 

獲得PayPal上更接近,我仍然不知道如何翻譯這個到PHP,以及如何使用這種形式我的服務器時應對證書。這也似乎是取決於使用PayPal帳戶或信用卡,你應該使用不同的驗證,我怎麼知道用戶使用哪種方法?:

curl -s --insecure 
-H "X-PAYPAL-SECURITY-USERID: api_username" 
-H "X-PAYPAL-SECURITY-PASSWORD: api_password" 
-H "X-PAYPAL-SECURITY-SIGNATURE: api_signature" 
-H "X-PAYPAL-REQUEST-DATA-FORMAT: NV" 
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV" 
-H "X-PAYPAL-APPLICATION-ID: app_id" 
https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails -d 
"payKey=AP-3TY011106S4428730 
&requestEnvelope.errorLanguage=en_US" 

一些示例代碼將幫助我很多,我使用PHP。

回答

0

您可以使用以下功能:

function verify_play($signed_data, $signature) 
{ 
    global $public_key_base64; 
    $pkey = "-----BEGIN PUBLIC KEY-----\n". 
    chunk_split($public_key_base64, 64,"\n"). 
    '-----END PUBLIC KEY-----'; 
    //using PHP to create an RSA key 
    $pkey = openssl_get_publickey($pkey); 
    //$signature should be in binary format, but it comes as BASE64. 
    //So, I'll convert it. 
    $signature = base64_decode($signature); 
    //using PHP's native support to verify the signature 
    $result = openssl_verify(
     $signed_data, 
     $signature, 
     $pkey, 
     OPENSSL_ALGO_SHA1); 

    if (0 === $result) 
    { 
    return false; 
    } 
    else if (1 !== $result) 
    { 
    return false; 
    } 
    else 
    { 
    return true; 
    } 
} ; 

function verify_paypal($payKey, $appID) 
{ 
    global $payPalUser_Id, $payPalPassword, $payPalSig; 
$headerArray = array(
'X-PAYPAL-SECURITY-USERID:'.$payPalUser_Id, 
'X-PAYPAL-SECURITY-PASSWORD:'.$payPalPassword, 
'X-PAYPAL-SECURITY-SIGNATURE:'.$payPalSig, 
'X-PAYPAL-REQUEST-DATA-FORMAT:JSON', 
'X-PAYPAL-RESPONSE-DATA-FORMAT:XML', 
'X-PAYPAL-APPLICATION-ID:'.$appID 
); 


$url="https://svcs.paypal.com/AdaptivePayments/PaymentDetails?payKey={$payKey}&requestEnvelope.errorLanguage=en_US"; 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); 
$adaptiveResponse = curl_exec($ch); 
curl_close($ch); 

echo $adaptiveResponse; 

//check following and return true or false: 
//Is completed ("status": "COMPLETED"). 
//Is the expected currency ("currencyCode": "USD"). 
//Has a paymentInfo within paymentInfoList that: 
//Has a receiver with amount and email as expected. 
//Is complete ("senderTransactionStatus": "COMPLETED"). 
};