Payum / PayumYiiExtension

Rich payment solutions for Yii framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
https://payum.forma-pro.com/
MIT License
12 stars 16 forks source link

Add token factory. #16

Closed makasim closed 10 years ago

makasim commented 10 years ago

Simplify token creation by using a factory, instead of doing:

<?php

        $doneToken = $tokenStorage->createModel();
        $doneToken->setPaymentName($paymentName);
        $doneToken->setDetails($storage->getIdentificator($paymentDetails));
        $doneToken->setTargetUrl(
            $this->createAbsoluteUrl('paypal/done', array('payum_token' => $doneToken->getHash()))
        );
        $tokenStorage->updateModel($doneToken);

        $captureToken = $tokenStorage->createModel();
        $captureToken->setPaymentName('paypal');
        $captureToken->setDetails($storage->getIdentificator($paymentDetails));
        $captureToken->setTargetUrl(
            $this->createAbsoluteUrl('payment/capture', array('payum_token' => $captureToken->getHash()))
        );
        $captureToken->setAfterUrl($doneToken->getTargetUrl());
        $tokenStorage->updateModel($captureToken);

        $paymentDetails['RETURNURL'] = $captureToken->getTargetUrl();
        $paymentDetails['CANCELURL'] = $captureToken->getTargetUrl();
        $storage->updateModel($paymentDetails);

we just do:

<?php

$payum->getTokenFactory()->createCaptureToken(
    $paymentName, 
    $paymentDetails, 
    'paypal/done'
);

@alexandernst Could you please test it since you have working app?

alexandernst commented 10 years ago

This is great! :+1: Anyways, I can test it as soon as Monday morning, can't clone company's project in my home computer :(

makasim commented 10 years ago

@alexandernst that's ok!

alexandernst commented 10 years ago

Hi! I tested your patch and some small changes are required to make it work.

In PayumComponent.php, right after the namespace, theres should be a line with this:

\Yii::import('Payum\YiiExtension\TokenFactory', true);

This is because of how Yii loads the extension. Without this line, Yii complains about not knowing what TokenFactory is. I'm not aware of any other solution :disappointed:

One more thing. In PayumController, the line (in the docs)

$tokenStorage = $payum->getTokenStorage();

is not needed anymore

makasim commented 10 years ago

@alexandernst you can open PR over my PR (:, could you do it?

makasim commented 10 years ago

if not I do that,

thanks for the review.

alexandernst commented 10 years ago

Sure, give me a moment :wink:

Where do I push? Here? Or in formapro-forks?

makasim commented 10 years ago

you have to use formapro-forks branch as a base one.

makasim commented 10 years ago

you have to create a new branch from this formapro-forks:token-factory one and after you done open a PR agains it.

alexandernst commented 10 years ago

Ok, will be ready in a few minutes

makasim commented 10 years ago

closing in favor https://github.com/Payum/PayumYiiExtension/pull/19