Skip to content

Commit

Permalink
3.29.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Feb 27, 2018
1 parent 3720e06 commit 0cf1231
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.29.0
* Add support for `association_filter_id` in `Customer#find`
* Add support for setting `timeout` and `acceptGzipEncoding` values on construction of `Configuration` instances

## 3.28.0
* Add support for Level 3 summary parameters: `shippingAmount`, `discountAmount`, and `shipsFromPostalCode`
* Add support for `tax_amount` field on transaction `line_items`
Expand All @@ -6,6 +10,7 @@
* Deprecate `TRANSACTION_LINE_ITEM_UNIT_TAX_AMOUNT_MUST_BE_GREATER_THAN_ZERO` error in favor of `TRANSACTION_LINE_ITEM_UNIT_TAX_AMOUNT_CANNOT_BE_NEGATIVE`.
* Deprecate `Braintree\Transaction\LineItem` in favor of `Braintree\TransactionLineItem`.
* Add `findAll` static method to `TransactionLineItem` class
* Add support for `profile_id` in Transaction#create options for VenmoAccounts

## 3.27.0
* Add support for Level 3 summary parameters: `shippingAmount`, `discountAmount`, and `shipsFromPostalCode`
Expand Down
49 changes: 39 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,25 @@ The following PHP extensions are required:

require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('your_merchant_id');
Braintree_Configuration::publicKey('your_public_key');
Braintree_Configuration::privateKey('your_private_key');
// Instantiate a Braintree Gateway either like this:
$gateway = new Braintree_Gateway([
'environment' => 'sandbox'
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);

// or like this:
$config = new Braintree_Configuration([
'environment' => 'sandbox'
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);
$gateway = new Braintree\Gateway($config)

$result = Braintree_Transaction::sale([
// Then, create a transaction:
$result = $gateway->transaction()->sale([
'amount' => '1000.00',
'paymentMethodNonce' => 'nonceFromTheClient',
'options' => [ 'submitForSettlement' => true ]
Expand All @@ -51,10 +64,22 @@ Both PSR-0 and PSR-4 namespacing are supported. If you are using composer with `
`--optimize-autoloader` enabled, you'll have to reference classes using PSR-4 namespacing:

```php
Braintree\Configuration::environment('sandbox');
Braintree\Configuration::merchantId('your_merchant_id');
Braintree\Configuration::publicKey('your_public_key');
Braintree\Configuration::privateKey('your_private_key');
$gateway = new Braintree\Gateway([
'environment' => 'sandbox'
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);

// or

$config = new Braintree\Configuration([
'environment' => 'sandbox'
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);
$gateway = new Braintree\Gateway($config)
```

## HHVM Support
Expand All @@ -72,7 +97,11 @@ extension = "curl.so"
and turn off accepting gzip responses:

```php
Braintree\Configuration::acceptGzipEncoding(false);
$gateway = new Braintree\Gateway([
'environment' => 'sandbox'
// ...
'acceptGzipEncoding' => false,
]);
```

## Legacy PHP Support
Expand Down
8 changes: 7 additions & 1 deletion lib/Braintree/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function __construct($attribs = [])
if ($kind == 'privateKey') {
$this->_privateKey = $value;
}
if ($kind == 'timeout') {
$this->_timeout = $value;
}
if ($kind == 'acceptGzipEncoding') {
$this->_acceptGzipEncoding = $value;
}
}

if (isset($attribs['clientId']) || isset($attribs['accessToken'])) {
Expand Down Expand Up @@ -414,7 +420,7 @@ private function getSslVersion()
return $this->_sslVersion;
}

private function getAcceptGzipEncoding()
public function getAcceptGzipEncoding()
{
return $this->_acceptGzipEncoding;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Braintree/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public static function createCustomerUrl()
* @param string $id customer id
* @return Customer
*/
public static function find($id)
public static function find($id, $associationFilterId = null)
{
return Configuration::gateway()->customer()->find($id);
return Configuration::gateway()->customer()->find($id, $associationFilterId);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions lib/Braintree/CustomerGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,19 @@ public static function updateSignature()
*
* @access public
* @param string id customer Id
* @param string associationFilterId association filter Id
* @return Customer|boolean The customer object or false if the request fails.
* @throws Exception\NotFound
*/
public function find($id)
public function find($id, $associationFilterId)
{
$this->_validateId($id);
try {
$path = $this->_config->merchantPath() . '/customers/' . $id;
$queryParams = '';
if ($associationFilterId) {
$queryParams = '?association_filter_id=' . $associationFilterId;
}
$path = $this->_config->merchantPath() . '/customers/' . $id . $queryParams;
$response = $this->_http->get($path);
return Customer::factory($response['customer']);
} catch (Exception\NotFound $e) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Braintree/TransactionGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public static function createSignature()
'currencyAmount',
'currencyIsoCode'
]
],
['venmo' =>
[
'profile_id'
]
]
],
],
Expand Down
2 changes: 1 addition & 1 deletion lib/Braintree/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Version
* class constants
*/
const MAJOR = 3;
const MINOR = 28;
const MINOR = 29;
const TINY = 0;

/**
Expand Down
91 changes: 91 additions & 0 deletions tests/integration/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,97 @@ public function testFind()
$this->assertEquals('http://example.com', $customer->website);
}

public function test_findCustomerWithAllFilterableAssociationsFilteredOut()
{
$result = Braintree\Customer::create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'email' => 'mike.jones@example.com',
'phone' => '419.555.1234',
'fax' => '419.555.1235',
'website' => 'http://example.com',
'customFields' => [
'storeMe' => 'custom value'
]
]);
$creditCard = Braintree\CreditCard::create([
'customerId' => $result->customer->id,
'number' => '5105105105105100',
'expirationDate' => '05/12',
'billingAddress' => [
'firstName' => 'Drew',
'lastName' => 'Smith',
'company' => 'Smith Co.',
'streetAddress' => '1 E Main St',
'locality' => 'Chicago',
'region' => 'IL',
'postalCode' => '60622',
'countryName' => 'United States of America'
]
]);
$id = strval(rand());
$subscriptions = Braintree\Subscription::create([
'id' => $id,
'paymentMethodToken' => $creditCard->creditCard->token,
'planId' => 'integration_trialless_plan',
'price' => '1.00'
]);

$customer = Braintree\Customer::find($result->customer->id, "customernoassociations");
$this->assertEquals(0, count($customer->creditCards));
$this->assertEquals(0, count($customer->paymentMethods));
$this->assertEquals(0, count($customer->addresses));
$this->assertEquals(0, count($customer->customFields));
}

public function test_findCustomerWithNestedFilterableAssociationsFilteredOut()
{
$result = Braintree\Customer::create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'email' => 'mike.jones@example.com',
'phone' => '419.555.1234',
'fax' => '419.555.1235',
'website' => 'http://example.com',
'customFields' => [
'storeMe' => 'custom value'
]
]);
$creditCard = Braintree\CreditCard::create([
'customerId' => $result->customer->id,
'number' => '5105105105105100',
'expirationDate' => '05/12',
'billingAddress' => [
'firstName' => 'Drew',
'lastName' => 'Smith',
'company' => 'Smith Co.',
'streetAddress' => '1 E Main St',
'locality' => 'Chicago',
'region' => 'IL',
'postalCode' => '60622',
'countryName' => 'United States of America'
]
]);
$id = strval(rand());
$subscriptions = Braintree\Subscription::create([
'id' => $id,
'paymentMethodToken' => $creditCard->creditCard->token,
'planId' => 'integration_trialless_plan',
'price' => '1.00'
]);

$customer = Braintree\Customer::find($result->customer->id, "customertoplevelassociations");

$this->assertEquals(1, count($customer->creditCards));
$this->assertEquals(0, count($customer->creditCards[0]->subscriptions));
$this->assertEquals(1, count($customer->paymentMethods));
$this->assertEquals(0, count($customer->paymentMethods[0]->subscriptions));
$this->assertEquals(1, count($customer->addresses));
$this->assertEquals(1, count($customer->customFields));
}

public function test_findUsBankAccountGivenPaymentMethodToken()
{
$nonce = Test\Helper::generateValidUsBankAccountNonce();
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/PaymentMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public function testCreate_fromFakeAndroidPayProxyCardNonce()
$this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCard->cardType);
$this->assertSame("1117", $androidPayCard->virtualCardLast4);
$this->assertSame("1117", $androidPayCard->last4);
$this->assertSame(Braintree\CreditCard::VISA, $androidPayCard->sourceCardType);
$this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCard->sourceCardType);
$this->assertSame("1111", $androidPayCard->sourceCardLast4);
$this->assertSame("Visa 1111", $androidPayCard->sourceDescription);
$this->assertSame("Discover 1111", $androidPayCard->sourceDescription);
$this->assertTrue($androidPayCard->default);
$this->assertContains('android_pay', $androidPayCard->imageUrl);
$this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
Expand Down Expand Up @@ -940,7 +940,7 @@ public function testFind_returnsAndroidPayCards()
$this->assertInstanceOf('Braintree\AndroidPayCard', $foundAndroidPayCard);
$this->assertSame(Braintree\CreditCard::DISCOVER, $foundAndroidPayCard->virtualCardType);
$this->assertSame("1117", $foundAndroidPayCard->virtualCardLast4);
$this->assertSame(Braintree\CreditCard::VISA, $foundAndroidPayCard->sourceCardType);
$this->assertSame(Braintree\CreditCard::DISCOVER, $foundAndroidPayCard->sourceCardType);
$this->assertSame("1111", $foundAndroidPayCard->sourceCardLast4);
$this->assertSame($customer->id, $foundAndroidPayCard->customerId);
$this->assertTrue($foundAndroidPayCard->default);
Expand Down
20 changes: 18 additions & 2 deletions tests/integration/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1891,9 +1891,9 @@ public function testCreateTransactionUsingFakeAndroidPayProxyCardNonce()
$this->assertNull($androidPayCardDetails->token);
$this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCardDetails->virtualCardType);
$this->assertSame("1117", $androidPayCardDetails->virtualCardLast4);
$this->assertSame(Braintree\CreditCard::VISA, $androidPayCardDetails->sourceCardType);
$this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCardDetails->sourceCardType);
$this->assertSame("1111", $androidPayCardDetails->sourceCardLast4);
$this->assertSame("Visa 1111", $androidPayCardDetails->sourceDescription);
$this->assertSame("Discover 1111", $androidPayCardDetails->sourceDescription);
$this->assertContains('android_pay', $androidPayCardDetails->imageUrl);
$this->assertTrue(intval($androidPayCardDetails->expirationMonth) > 0);
$this->assertTrue(intval($androidPayCardDetails->expirationYear) > 0);
Expand Down Expand Up @@ -1947,6 +1947,22 @@ public function testCreateTransactionUsingFakeAmexExpressCheckoutNonce()
$this->assertTrue(intval($amexExpressCheckoutCardDetails->expirationYear) > 0);
}

public function testCreateTransactionUsingFakeVenmoAccountNonceAndProfileId()
{
$result = Braintree\Transaction::sale(array(
'amount' => '47.00',
'merchantAccountId' => Test\Helper::fakeVenmoAccountMerchantAccountId(),
'paymentMethodNonce' => Braintree\Test\Nonces::$venmoAccount,
'options' => [
'venmo' => [
'profile_id' => "integration_venmo_merchant_public_id"
]
]
));

$this->assertTrue($result->success);
}

public function testCreateTransactionUsingFakeVenmoAccountNonce()
{
$result = Braintree\Transaction::sale(array(
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ public function testConstructWithArrayOfCredentials()
'merchantId' => 'sandbox_merchant_id',
'publicKey' => 'sandbox_public_key',
'privateKey' => 'sandbox_private_key',
'timeout' => 120,
'acceptGzipEncoding' => false,
]);

$this->assertEquals('sandbox', $config->getEnvironment());
$this->assertEquals('sandbox_merchant_id', $config->getMerchantId());
$this->assertEquals(120, $config->getTimeout());
$this->assertFalse($config->getAcceptGzipEncoding());
}

public function testSetValidEnvironment()
Expand Down

0 comments on commit 0cf1231

Please sign in to comment.