PHP 7.4.33
Preview: MerchantTest.php Size: 10.17 KB
/home/godevadmin/www/admin/braintree/final/braintree2/tests/integration/MerchantTest.php

<?php
namespace Test\Integration;

require_once dirname(__DIR__) . '/Setup.php';

use Test;
use Test\Setup;
use Braintree;

class MerchantTest extends Setup
{
    public function testCreateMerchant()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$integration_client_id',
            'clientSecret' => 'client_secret$development$integration_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'USA',
            'paymentMethods' => ['credit_card', 'paypal'],
        ]);

        $this->assertEquals(true, $result->success);
        $merchant = $result->merchant;
        $this->assertNotNull($merchant->id);
        $credentials = $result->credentials;
        $this->assertNotNull($credentials->accessToken);
    }

    /**
    * @expectedException Braintree\Exception\Configuration
    * @expectedExceptionMessage clientId needs to be passed to Braintree\Gateway
    */
    public function testAssertsHasCredentials()
    {
        $gateway = new Braintree\Gateway([
            'clientSecret' => 'client_secret$development$integration_client_secret',
        ]);
        $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'USA',
        ]);
    }

    public function testBadPaymentMethods()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$integration_client_id',
            'clientSecret' => 'client_secret$development$integration_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'USA',
            'paymentMethods' => ['fake_money'],
        ]);

        $this->assertEquals(false, $result->success);
        $errors = $result->errors->forKey('merchant')->onAttribute('paymentMethods');
        $this->assertEquals(Braintree\Error\Codes::MERCHANT_ACCOUNT_PAYMENT_METHODS_ARE_INVALID, $errors[0]->code);
    }

    public function testCreateUSMerchantThatAcceptsMultipleCurrencies()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$signup_client_id',
            'clientSecret' => 'client_secret$development$signup_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'USA',
            'paymentMethods' => ['credit_card', 'paypal'],
            'currencies' => ['GBP', 'USD']
        ]);

        $this->assertEquals(true, $result->success);
        $merchant = $result->merchant;
        $this->assertNotNull($merchant->id);
        $credentials = $result->credentials;
        $this->assertNotNull($credentials->accessToken);

        $merchantAccounts = $merchant->merchantAccounts;
        $this->assertEquals(2, count($merchantAccounts));

        $usdMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'USD');
        $this->assertNotNull($usdMerchantAccount);
        $this->assertEquals(true, $usdMerchantAccount->default);
        $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);

        $gbpMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'GBP');
        $this->assertNotNull($gbpMerchantAccount);
        $this->assertEquals(false, $gbpMerchantAccount->default);
        $this->assertEquals('GBP', $gbpMerchantAccount->currencyIsoCode);
    }

    public function testCreateEUMerchantThatAcceptsMultipleCurrencies()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$signup_client_id',
            'clientSecret' => 'client_secret$development$signup_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'GBR',
            'paymentMethods' => ['credit_card', 'paypal'],
            'currencies' => ['GBP', 'USD']
        ]);

        $this->assertEquals(true, $result->success);
        $merchant = $result->merchant;
        $this->assertNotNull($merchant->id);
        $credentials = $result->credentials;
        $this->assertNotNull($credentials->accessToken);

        $merchantAccounts = $merchant->merchantAccounts;
        $this->assertEquals(2, count($merchantAccounts));

        $usdMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'USD');
        $this->assertNotNull($usdMerchantAccount);
        $this->assertEquals(false, $usdMerchantAccount->default);
        $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);

        $gbpMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'GBP');
        $this->assertNotNull($gbpMerchantAccount);
        $this->assertEquals(true, $gbpMerchantAccount->default);
        $this->assertEquals('GBP', $gbpMerchantAccount->currencyIsoCode);
    }

    public function testCreatePaypalOnlyMerchantThatAcceptsMultipleCurrencies()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$signup_client_id',
            'clientSecret' => 'client_secret$development$signup_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'USA',
            'paymentMethods' => ['paypal'],
            'currencies' => ['GBP', 'USD'],
            'paypalAccount' => [
                'clientId' => 'fake_client_id',
                'clientSecret' => 'fake_client_secret',
            ]
        ]);

        $this->assertEquals(true, $result->success);
        $merchant = $result->merchant;
        $this->assertNotNull($merchant->id);
        $credentials = $result->credentials;
        $this->assertNotNull($credentials->accessToken);

        $merchantAccounts = $merchant->merchantAccounts;
        $this->assertEquals(2, count($merchantAccounts));

        $usdMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'USD');
        $this->assertNotNull($usdMerchantAccount);
        $this->assertEquals(true, $usdMerchantAccount->default);
        $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);

        $gbpMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'GBP');
        $this->assertNotNull($gbpMerchantAccount);
        $this->assertEquals(false, $gbpMerchantAccount->default);
        $this->assertEquals('GBP', $gbpMerchantAccount->currencyIsoCode);
    }

    private function getMerchantAccountForCurrency($merchantAccounts, $currency)
    {
        foreach($merchantAccounts as $merchantAccount) {
            if($merchantAccount->id == $currency) {
                return $merchantAccount;
            }
        }
        return null;
    }

    public function testCreatePaypalOnlyMerchantWithNoCurrenciesProvided()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$signup_client_id',
            'clientSecret' => 'client_secret$development$signup_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'JPN',
            'paymentMethods' => ['paypal'],
            'paypalAccount' => [
                'clientId' => 'fake_client_id',
                'clientSecret' => 'fake_client_secret',
            ]
        ]);

        $this->assertEquals(true, $result->success);
        $merchant = $result->merchant;
        $this->assertNotNull($merchant->id);
        $credentials = $result->credentials;
        $this->assertNotNull($credentials->accessToken);

        $merchantAccounts = $merchant->merchantAccounts;
        $this->assertEquals(1, count($merchantAccounts));

        $jpyMerchantAccount = $merchantAccounts[0];
        $this->assertEquals(true, $jpyMerchantAccount->default);
        $this->assertEquals('JPY', $jpyMerchantAccount->currencyIsoCode);
    }

    public function testCreatePaypalOnlyMerchantWithUnsupportedCountryCodeProvided()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$signup_client_id',
            'clientSecret' => 'client_secret$development$signup_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'YEM',
            'paymentMethods' => ['paypal'],
            'paypalAccount' => [
                'clientId' => 'fake_client_id',
                'clientSecret' => 'fake_client_secret',
            ]
        ]);

        $this->assertEquals(true, $result->success);
        $merchant = $result->merchant;
        $this->assertNotNull($merchant->id);
        $credentials = $result->credentials;
        $this->assertNotNull($credentials->accessToken);

        $merchantAccounts = $merchant->merchantAccounts;
        $this->assertEquals(1, count($merchantAccounts));

        $usdMerchantAccount = $merchantAccounts[0];
        $this->assertEquals(true, $usdMerchantAccount->default);
        $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);
    }

    public function testInvalidCurrencyForMultiCurrency()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$signup_client_id',
            'clientSecret' => 'client_secret$development$signup_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => '[email protected]',
            'countryCodeAlpha3' => 'USA',
            'paymentMethods' => ['paypal'],
            'currencies' => ['FAKE', 'USD'],
            'paypalAccount' => [
                'clientId' => 'fake_client_id',
                'clientSecret' => 'fake_client_secret',
            ]
        ]);

        $this->assertEquals(false, $result->success);
        $errors = $result->errors->forKey('merchant')->onAttribute('currencies');
        $this->assertEquals(Braintree\Error\Codes::MERCHANT_CURRENCIES_ARE_INVALID, $errors[0]->code);
    }
}

Directory Contents

Dirs: 2 × Files: 34

Name Size Perms Modified Actions
Error DIR
- drwxrwxr-x 2023-11-07 19:59:44
Edit Download
Result DIR
- drwxrwxr-x 2023-11-07 19:59:44
Edit Download
2.97 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
12.84 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
7.04 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
56.07 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
11.20 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
1.84 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
7.68 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
62.86 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
1.22 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
3.09 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
1.93 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
5.09 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
5.63 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
4.13 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
6.01 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
29.95 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
10.17 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
3.35 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
13.75 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
2.60 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
67.92 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
11.34 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
4.77 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
3.51 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
2.49 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
17.89 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
50.99 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
2.92 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
5.40 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
65.59 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
173.21 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
12.51 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
4.28 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download
7.06 KB lrwxrwxr-x 2023-11-07 19:59:44
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).