3
votes

I am using a paypal ipn script i found here http://coderzone.org/library/PHP-PayPal-Instant-Payment-Notification-IPN_1099.htm

I am aware that I can send information to paypal and get a response. It states I can get the information back using $_POST . My query is how do I specify the UK currency?

Also wanted to clarify a minor point. Am I correct that this is how i can confirm it was a success.

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

3 Answers

0
votes

This might be a little late for you sorry, but just in case - I currently use "currencyCode" = > "AUD" and it is working in the sandbox.

There's a full list of the currency codes available at PayPal

For yours, I'm guessing it would be:

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

As for your question about the IPN itself, it looks like you're on the right track. It will depend on the data you're getting back and whether you're interested in the individual transactions (if using adaptive payments) or if you're reversing them all on error etc. The easiest way to determine what you'll need to do is to simply display or log all the post data so you can see how it's constructed.

You'll also need to set it up so that the script is accessible by PayPal. You'll then pass the full URL of this script to the "notify_url" parameter and send it off to PayPal. Once the payment has completed PayPal will send a bunch of information to your script so that you can process it.

Unfortunately I'm not from a PHP background so I can't give you the exact code you'll need. Also note that there are a lot of security issues that you'll want to look into before going to a production environment. Not sure if you already intend to do this with that validateIPN function, but you need to ensure that you can tell whether it comes from PayPal and not a malicious user. One way would be to pass a value using the custom attribute and have PayPal pass this back to you, however you'd be much better off using the API certificates etc.

If you haven't already, it may be worth checking out a few of the sample applications PayPal has done up, there seem to be quite a few PHP ones.

Let me know if you need anything else,

0
votes

Use this, it works for me

$p->add_field('currency_code', 'GBP');
-1
votes

You need to use PayPal Adaptive Payments, IPN wouldn't help.

PayPal Adaptive Payments

Using PayPal PHP library then it could look like this:

// 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;