开发者

How to implement PayPal in Symfony 1.4 & Docrtrine

开发者 https://www.devze.com 2023-02-06 03:39 出处:网络
I want to use PayPal, Express Checkout, in a Symfony/Doctrine 1.4.8 the current plugins all seem to be in Beta and also somewhat over the top in the way they are implemented. I can follow the logic of

I want to use PayPal, Express Checkout, in a Symfony/Doctrine 1.4.8 the current plugins all seem to be in Beta and also somewhat over the top in the way they are implemented. I can follow the logic of the PayPal provided information and code although some items are a bit vague as to how i deal with them in Symfony.

Any class files are ok as i create a lib directory and rename开发者_JS百科 the class and this gets instantiated. However i have some plain procedural PHP files i.e. expresscheckout.php and i am not sure where to put this to load as it doesn't seem to fit in the templates. Perhaps it goes in the actions?

I am not looking for a line by line solution here (but if you have one feel free) but really a few pointers as to where the elements go. As i say i am still suffering form a bit of Symfony blindness.

Finally would i be better to implement a simple (is that possible?) plugin to handle this or group the paypal items in a module on their own?


What I did was write a class, I called it PaypalNvp, name the file PaypalNvp.class.php and put it in your /lib folder and put in functions for the Nvp Ops.

Then you can choose to either call the functions statically (change your class functions as needed) or initialize the class and call the functions...

So something like:

PaypalNvp::doExpressCheckoutPaypment($token, $payer_id, $amount, $currency, $payment_action);

or

$paypal = new PaypalNvp();
$paypal->doExpressCheckoutPaypment($token, $payer_id, $amount, $currency, $payment_action);

I don't think there is a set way of of saying which way is better... I use the latter method myself.

My class has a helper function in it that does the final communication operation with Paypal:

protected function api($data = array())
{
    if (empty($data) || !is_array($data)) return false;

    // INIT
    $data = array_merge($data, array(
        'VERSION'   => $this->VERSION,
        'PWD'       => $this->PASSWORD,
        'USER'      => $this->USERNAME,
        'SIGNATURE' => $this->SIGNATURE
    ));

    array_walk($data, array(&$this, 'urlencode_walk'));

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL             => $this->getUrl() . '/nvp',
        CURLOPT_VERBOSE         => 1,
        CURLOPT_SSL_VERIFYPEER  => false,
        CURLOPT_SSL_VERIFYHOST  => false,
        CURLOPT_RETURNTRANSFER  => 1,
        CURLOPT_POST            => 1,
        CURLOPT_POSTFIELDS      => http_build_query($data)
    ));

    $response = curl_exec($curl);

    if (curl_errno($curl)) {
        curl_close($curl);
        return false;
    } else {
        curl_close($curl);
        return $this->deformatNVP($response);
    }
}

Main things you need to remember is to set the api method, e.g. SetExpressCheckout, and any required fields according to the PaypalNvp API

0

精彩评论

暂无评论...
验证码 换一张
取 消