2012-11-12 57 views
3

我使用的是貝寶IPN腳本我發現這裏 http://coderzone.org/library/PHP-PayPal-Instant-Payment-Notification-IPN_1099.htm貝寶IPN貨幣和響應

我知道我可以將信息發送到PayPal,並得到迴應。它聲明我可以使用$ _POST獲取信息。我的查詢是如何指定英國貨幣?

也想澄清一個小問題。我是否正確,這是我如何確認它是成功的。

if ($_POST['payment_status'] == 'completed') 
     // Received Payment! 
     // $_POST['custom'] is order id and has been paid for. 
    } 

回答

-1

您需要使用PayPal自適應付款,IPN不會幫助。

PayPal Adaptive Payments

使用貝寶PHP庫,然後它可能看起來像這樣:

// Create an instance, you'll make all the necessary requests through this 
     // object, if you digged through the code, you'll notice an AdaptivePaymentsProxy class 
     // wich has in it all of the classes corresponding to every object mentioned on the 
     // documentation of the API 
     $ap = new AdaptivePayments(); 

     // Our request envelope 
     $requestEnvelope = new RequestEnvelope(); 
     $requestEnvelope->detailLevel = 0; 
     $requestEnvelope->errorLanguage = 'en_GB'; 

     // Our base amount, in other words the currency we want to convert to 
     // other currency type. It's very straighforward, just have a public 
     // prop. to hold de amount and the current code. 
     $baseAmountList = new CurrencyList(); 
     $baseAmountList->currency = array('amount' => $this->amount, 'code' => 'GBP'); 

     // Our target currency type. Given that I'm from Mexico I would like to 
     // see it in mexican pesos. Again, just need to provide the code of the 
     // currency. On the docs you'll have access to the complete list of codes 
     $convertToCurrencyListUSD = new CurrencyCodeList(); 
     $convertToCurrencyListUSD->currencyCode = 'USD'; 

     // Now create a instance of the ConvertCurrencyRequest object, which is 
     // the one necessary to handle this request. 
     // This object takes as parameters the ones we previously created, which 
     // are our base currency, our target currency, and the req. envelop 
     $ccReq = new ConvertCurrencyRequest(); 
     $ccReq->baseAmountList = $baseAmountList; 
     $ccReq->convertToCurrencyList = $convertToCurrencyListUSD; 
     $ccReq->requestEnvelope = $requestEnvelope; 

     // And finally we call the ConvertCurrency method on our AdaptivePayment object, 
     // and assign whatever result we get to our variable 
     $resultUSD = $ap->ConvertCurrency($ccReq); 
     $convertToCurrencyListUSD->currencyCode = 'EUR'; 
     $resultEUR = $ap->ConvertCurrency($ccReq); 

     // Given that our result should be a ConvertCurrencyResponse object, we can 
     // look into its properties for further display/processing purposes 
     $resultingCurrencyListUSD = $resultUSD->estimatedAmountTable->currencyConversionList; 
     $resultingCurrencyListEUR = $resultEUR->estimatedAmountTable->currencyConversionList; 
+0

對不起,你能解釋一下爲什麼你推薦的Adaptive Payments,其他人都推薦IPN。 –

+0

我相信IPN不支持貨幣轉換。 –

+0

顯然,如果我使用 \t $ p-> add_field('currency_code','GBP'); 它應該爲未來的讀者設置貨幣英鎊 –

0

這可能是有點晚了對不起你,但以防萬一 - 我目前使用的「貨幣代碼」 => 「AUD」,它在沙箱中工作。

有可用的貨幣代碼在PayPal

爲了您的完整列表,我猜這將是:

$p->add_field('currencyCode', 'GBP'); 

至於你提到的IPN本身的問題,它看起來像你重新走上正軌。這將取決於您收回的數據以及您是否對單個交易感興趣(如果使用適應性付款),或者您是否將錯誤全部倒轉等等。確定您需要什麼的最簡單方法做的只是簡單地顯示或記錄所有的發佈數據,這樣你就可以看到它是如何構建的。

您還需要進行設置,以便腳本可以通過PayPal訪問。然後,您將該腳本的完整URL傳遞給「notify_url」參數並將其發送給PayPal。一旦付款完成,PayPal將向您的腳本發送一堆信息,以便您可以處理它。

不幸的是,我不是來自PHP背景,所以我不能給你你需要的確切代碼。另請注意,在進入生產環境之前,您需要查看許多安全問題。不知道您是否打算使用該validateIPN函數執行此操作,但您需要確保您可以確定它是來自PayPal而不是惡意用戶。一種方法是使用自定義屬性傳遞一個值,並讓PayPal將此傳遞給您,但使用API​​證書等會更好。

如果您還沒有,可能值得檢查了一些sample applications PayPal已經完成了,似乎有不少PHP的。

讓我知道你是否需要別的東西,