这部分对我来说很新,所以这可能是一个非常明显的答案。我在我的Android应用程序中使用了PayPal MPL,在PHP的服务器端使用了这个来验证付款:
function verify_paypal($payKey, $appID)
{
global $payPalUser_Id, $payPalPassword, $payPalSig, $amount, $currency;
$headerArray = array(
'X-PAYPAL-SECURITY-USERID:'.$payPalUser_Id,
'X-PAYPAL-SECURITY-PASSWORD:'.$payPalPassword,
'X-PAYPAL-SECURITY-SIGNATURE:'.$payPalSig,
'X-PAYPAL-APPLICATION-ID:'.$appID,
'X-PAYPAL-REQUEST-DATA-FORMAT:NV',
'X-PAYPAL-RESPONSE-DATA-FORMAT:XML'
);
$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);
if (!is_null($adaptiveResponse)){
//check result
$dom_document = new DOMDocument();
$dom_document->loadXML($adaptiveResponse);
$searchNode = $dom_document->getElementsByTagName("responseEnvelope");
foreach( $searchNode as $searchNode )
{
$xmlResponse = $searchNode->getElementsByTagName( "ack" );
$valueResponse = $xmlResponse->item(0)->nodeValue;
}
if (strtolower($valueResponse) =="failure"){
return false;
}
$xml=simplexml_load_string($adaptiveResponse);
$valueCurrency=$xml->currencyCode;
$valueStatus=$xml->status;
$searchNode = $dom_document->getElementsByTagName("receiver");
foreach( $searchNode as $searchNode )
{
$xmlAmount = $searchNode->getElementsByTagName( "amount" );
$valueAmount = $xmlAmount->item(0)->nodeValue;
$xmlEmail = $searchNode->getElementsByTagName( "email" );
$valueEmail = $xmlEmail->item(0)->nodeValue;
}
$searchNode = $dom_document->getElementsByTagName("paymentInfo");
foreach( $searchNode as $searchNode )
{
$xmlSenderStatus = $searchNode->getElementsByTagName( "senderTransactionStatus" );
$valueSenderStatus = $xmlSenderStatus->item(0)->nodeValue;
}
if ((strtolower($valueStatus) =="completed")&&(strtolower($valueSenderStatus) =="completed")&&(strtolower($valueEmail) =="mymail@paypal.com")&&($valueAmount==$amount)&&($valueCurrency==$currency)){
return true;
} else {
return false;
}
}
return false;
};
但是使用新的Android SDK我得到了一个PaymentConfirmation对象:
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
我如何从确认中获得$ payKey,还是应该以不同的方式验证付款?
答案 0 :(得分:0)
根据您使用的MSDK版本,您可能需要使用自己使用的自适应付款或REST API。请查看此页面,了解如何验证付款https://developer.paypal.com/docs/integration/mobile/verify-mobile-payment/