<commit_before><?php
namespace Payum\Paypal\ExpressCheckout\Nvp\Examples;

use Buzz\Client\Curl;
use Payum\Request\CaptureRequest;
use Payum\Request\SyncRequest;
use Payum\Request\BinaryMaskStatusRequest;
use Payum\Request\RedirectUrlInteractiveRequest;
use Payum\Paypal\ExpressCheckout\Nvp\Api;
use Payum\Paypal\ExpressCheckout\Nvp\Examples\Model\AwesomeCart;
use Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory;
use Payum\Paypal\ExpressCheckout\Nvp\Request\Api\CreateRecurringPaymentProfileRequest;
use Payum\Paypal\ExpressCheckout\Nvp\Examples\Action\CaptureAwesomeCartAction;

class ReadmeTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function doCapture()
    {
        //@testo:start
        //@testo:source
        //@testo:uncomment:use Buzz\Client\Curl;
        //@testo:uncomment:use Payum\Paypal\ExpressCheckout\Nvp\Api;
        //@testo:uncomment:use Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory;
        //@testo:uncomment:use Payum\Request\CaptureRequest;
        //@testo:uncomment:use Payum\Request\RedirectUrlInteractiveRequest;
        
        $payment = PaymentFactory::create(new Api(new Curl, array(
            'username' => 'a_username',
            'password' => '<PASSWORD>',
            'signature' => 'a_signature',
            'sandbox' => true
        )));

        $capture = new CaptureRequest(array(
            'PAYMENTREQUEST_0_AMT' => 10,
            'PAYMENTREQUEST_0_CURRENCY' => 'USD',
            'RETURNURL' => 'http://foo.com/finishPayment',
            'CANCELURL' => 'http://foo.com/finishPayment',
        ));
        
        if ($interactiveRequest = $payment->execute($capture, $expectsInteractive = true)) {
            //save your models somewhere.
            if ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
                header('Location: '.$interactiveRequest->getUrl());
                exit;
            }
            
            throw $interactiveRequest;
        }
        //@testo:end
        
        $this->assertArrayHasKey('L_LONGMESSAGE0', $capture->getModel());
        $this->assertEquals('Security header is not valid', $capture->getModel()['L_LONGMESSAGE0']);
        
        return array(
            $payment,
            $capture
        );
    }

    /**
     * @test
     */
    public function doDigitalGoodsCapture()
    {
        //@testo:source
        
        $capture = new CaptureRequest(array(
            
            // ... 
            
            'NOSHIPPING' => Api::NOSHIPPING_NOT_DISPLAY_ADDRESS,
            'REQCONFIRMSHIPPING' => Api::REQCONFIRMSHIPPING_NOT_REQUIRED,
            'L_PAYMENTREQUEST_0_ITEMCATEGORY0' => Api::PAYMENTREQUEST_ITERMCATEGORY_DIGITAL, 
            'L_PAYMENTREQUEST_0_NAME0' => 'Awesome e-book',
            'L_PAYMENTREQUEST_0_DESC0' => 'Great stories of America.',
            'L_PAYMENTREQUEST_0_AMT0' => 10,
            'L_PAYMENTREQUEST_0_QTY0' => 1,
            'L_PAYMENTREQUEST_0_TAXAMT0' => 2,
        ));
    }

    /**
     * @test
     *
     * @depends doCapture
     */
    public function doStatus(array $arguments)
    {
        $payment = $arguments[0];
        $capture = $arguments[1];

        unset($capture->getModel()['L_ERRORCODE0']);
        $capture->getModel()['CHECKOUTSTATUS'] = Api::CHECKOUTSTATUS_PAYMENT_COMPLETED;
        $capture->getModel()['PAYMENTREQUEST_0_PAYMENTSTATUS'] = Api::PAYMENTSTATUS_COMPLETED;

        //@testo:start
        //@testo:source
        //@testo:uncomment:use Payum\Request\BinaryMaskStatusRequest;
        
        $status = new BinaryMaskStatusRequest($capture->getModel());
        $payment->execute($status);
        
        if ($status->isSuccess()) {
            //@testo:uncomment:echo 'We are done';
        }

        //@testo:uncomment:echo "Hmm. We are not. Let's check other possible statuses!";
        //@testo:end
        $this->assertTrue($status->isSuccess());<commit_msg>fix BC breaks in tests. make them work on 5.3 again<commit_after><?php
namespace Payum\Paypal\ExpressCheckout\Nvp\Examples;

use Buzz\Client\Curl;
use Payum\Request\CaptureRequest;
use Payum\Request\SyncRequest;
use Payum\Request\BinaryMaskStatusRequest;
use Payum\Request\RedirectUrlInteractiveRequest;
use Payum\Paypal\ExpressCheckout\Nvp\Api;
use Payum\Paypal\ExpressCheckout\Nvp\Examples\Model\AwesomeCart;
use Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory;
use Payum\Paypal\ExpressCheckout\Nvp\Request\Api\CreateRecurringPaymentProfileRequest;
use Payum\Paypal\ExpressCheckout\Nvp\Examples\Action\CaptureAwesomeCartAction;

class ReadmeTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function doCapture()
    {
        //@testo:start
        //@testo:source
        //@testo:uncomment:use Buzz\Client\Curl;
        //@testo:uncomment:use Payum\Paypal\ExpressCheckout\Nvp\Api;
        //@testo:uncomment:use Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory;
        //@testo:uncomment:use Payum\Request\CaptureRequest;
        //@testo:uncomment:use Payum\Request\RedirectUrlInteractiveRequest;
        
        $payment = PaymentFactory::create(new Api(new Curl, array(
            'username' => 'a_username',
            'password' => '<PASSWORD>',
            'signature' => 'a_signature',
            'sandbox' => true
        )));

        $capture = new CaptureRequest(array(
            'PAYMENTREQUEST_0_AMT' => 10,
            'PAYMENTREQUEST_0_CURRENCY' => 'USD',
            'RETURNURL' => 'http://foo.com/finishPayment',
            'CANCELURL' => 'http://foo.com/finishPayment',
        ));
        
        if ($interactiveRequest = $payment->execute($capture, $expectsInteractive = true)) {
            //save your models somewhere.
            if ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
                header('Location: '.$interactiveRequest->getUrl());
                exit;
            }
            
            throw $interactiveRequest;
        }
        //@testo:end

        $model = $capture->getModel();

        $this->assertArrayHasKey('L_LONGMESSAGE0', $model);
        $this->assertEquals('Security header is not valid', $model['L_LONGMESSAGE0']);
        
        return array(
            $payment,
            $capture
        );
    }

    /**
     * @test
     */
    public function doDigitalGoodsCapture()
    {
        //@testo:source
        
        $capture = new CaptureRequest(array(
            
            // ... 
            
            'NOSHIPPING' => Api::NOSHIPPING_NOT_DISPLAY_ADDRESS,
            'REQCONFIRMSHIPPING' => Api::REQCONFIRMSHIPPING_NOT_REQUIRED,
            'L_PAYMENTREQUEST_0_ITEMCATEGORY0' => Api::PAYMENTREQUEST_ITERMCATEGORY_DIGITAL, 
            'L_PAYMENTREQUEST_0_NAME0' => 'Awesome e-book',
            'L_PAYMENTREQUEST_0_DESC0' => 'Great stories of America.',
            'L_PAYMENTREQUEST_0_AMT0' => 10,
            'L_PAYMENTREQUEST_0_QTY0' => 1,
            'L_PAYMENTREQUEST_0_TAXAMT0' => 2,
        ));
    }

    /**
     * @test
     *
     * @depends doCapture
     */
    public function doStatus(array $arguments)
    {
        $payment = $arguments[0];
        $capture = $arguments[1];

        $model = $capture->getModel();

        unset($model['L_ERRORCODE0']);
        $model['CHECKOUTSTATUS'] = Api::CHECKOUTSTATUS_PAYMENT_COMPLETED;
        $model['PAYMENTREQUEST_0_PAYMENTSTATUS'] = Api::PAYMENTSTATUS_COMPLETED;

        //@testo:start
        //@testo:source
        //@testo:uncomment:use Payum\Request\BinaryMaskStatusRequest;
        
        $status = new BinaryMaskStatusRequest($capture->getModel());
        $payment->execute($status);
        
        if ($status->isSuccess()) {
            //@testo:uncomment:echo 'We are done';
        }

        //@testo:uncomment:echo "Hmm. We are not. Let's check other possible statuses!";
        //@testo:end
        $this->assertTrue($status->isSuccess());
{'fraction_non_alphanumeric': 0.1270242914979757, 'fraction_numerical': 0.0068319838056680165, 'mean_word_length': 2.386889460154242, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '417719', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2446, 'n_words': 349}