/** * @ignore */ protected function _initialize($attributes) { $this->_attributes = $attributes; $addOnArray = array(); if (isset($attributes['addOns'])) { foreach ($attributes['addOns'] as $addOn) { $addOnArray[] = Braintree_AddOn::factory($addOn); } } $this->_attributes['addOns'] = $addOnArray; $discountArray = array(); if (isset($attributes['discounts'])) { foreach ($attributes['discounts'] as $discount) { $discountArray[] = Braintree_Discount::factory($discount); } } $this->_attributes['discounts'] = $discountArray; if (isset($attributes['descriptor'])) { $this->_set('descriptor', new Braintree_Descriptor($attributes['descriptor'])); } $statusHistory = array(); if (isset($attributes['statusHistory'])) { foreach ($attributes['statusHistory'] as $history) { $statusHistory[] = new Braintree_Subscription_StatusDetails($history); } } $this->_attributes['statusHistory'] = $statusHistory; $transactionArray = array(); if (isset($attributes['transactions'])) { foreach ($attributes['transactions'] as $transaction) { $transactionArray[] = Braintree_Transaction::factory($transaction); } } $this->_attributes['transactions'] = $transactionArray; }
protected function _initialize($attributes) { $this->_attributes = $attributes; if (isset($attributes['subject']['apiErrorResponse'])) { $wrapperNode = $attributes['subject']['apiErrorResponse']; } else { $wrapperNode = $attributes['subject']; } if (isset($wrapperNode['subscription'])) { $this->_set('subscription', Braintree_Subscription::factory($attributes['subject']['subscription'])); } if (isset($wrapperNode['merchantAccount'])) { $this->_set('merchantAccount', Braintree_MerchantAccount::factory($wrapperNode['merchantAccount'])); } if (isset($wrapperNode['transaction'])) { $this->_set('transaction', Braintree_Transaction::factory($wrapperNode['transaction'])); } if (isset($wrapperNode['disbursement'])) { $this->_set('disbursement', Braintree_Disbursement::factory($wrapperNode['disbursement'])); } if (isset($wrapperNode['partnerMerchant'])) { $this->_set('partnerMerchant', Braintree_PartnerMerchant::factory($wrapperNode['partnerMerchant'])); } if (isset($wrapperNode['errors'])) { $this->_set('errors', new Braintree_Error_ValidationErrorCollection($wrapperNode['errors'])); $this->_set('message', $wrapperNode['message']); } }
/** * overrides default constructor * @ignore * @param array $response gateway response array */ public function __construct($response) { $this->_attributes = $response; $this->_set('errors', new Braintree_Error_ErrorCollection($response['errors'])); if (isset($response['verification'])) { $this->_set('creditCardVerification', new Braintree_Result_CreditCardVerification($response['verification'])); } else { $this->_set('creditCardVerification', null); } if (isset($response['transaction'])) { $this->_set('transaction', Braintree_Transaction::factory($response['transaction'])); } else { $this->_set('transaction', null); } if (isset($response['subscription'])) { $this->_set('subscription', Braintree_Subscription::factory($response['subscription'])); } else { $this->_set('subscription', null); } if (isset($response['merchantAccount'])) { $this->_set('merchantAccount', Braintree_MerchantAccount::factory($response['merchantAccount'])); } else { $this->_set('merchantAccount', null); } }
private function _doTestRequest($testPath, $transactionId) { self::_checkEnvironment(); $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . $testPath; $response = $this->_http->put($path); return Braintree_Transaction::factory($response['transaction']); }
function test__isset() { $transaction = Braintree_Transaction::factory(array('creditCard' => array('expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100', 'cardType' => 'MasterCard'))); $this->assertEquals('MasterCard', $transaction->creditCardDetails->cardType); $this->assertFalse(empty($transaction->creditCardDetails->cardType)); $this->assertTrue(isset($transaction->creditCardDetails->cardType)); $transaction = Braintree_Transaction::factory(array('creditCard' => array('expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100'))); $this->assertTrue(empty($transaction->creditCardDetails->cardType)); $this->assertFalse(isset($transaction->creditCardDetails->cardType)); }
function testIsset() { $t = Braintree_Transaction::factory(array('creditCard' => array('expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100'), 'customer' => array(), 'billing' => array(), 'descriptor' => array(), 'shipping' => array(), 'subscription' => array('billingPeriodStartDate' => '1983-07-12'), 'statusHistory' => array())); $this->assertTrue(isset($t->creditCard)); $this->assertFalse(empty($t->creditCard)); }
/** * generic method for validating incoming gateway responses * * creates a new Braintree_Transaction object and encapsulates * it inside a Braintree_Result_Successful object, or * encapsulates a Braintree_Errors object inside a Result_Error * alternatively, throws an Unexpected exception if the response is invalid. * * @ignore * @param array $response gateway response values * @return object Result_Successful or Result_Error * @throws Braintree_Exception_Unexpected */ private function _verifyGatewayResponse($response) { if (isset($response['transaction'])) { // return a populated instance of Braintree_Transaction return new Braintree_Result_Successful(Braintree_Transaction::factory($response['transaction'])); } else { if (isset($response['apiErrorResponse'])) { return new Braintree_Result_Error($response['apiErrorResponse']); } else { throw new Braintree_Exception_Unexpected("Expected transaction or apiErrorResponse"); } } }
function testInitializationWithoutArguments() { $transaction = Braintree_Transaction::factory(array()); $this->assertTrue($transaction instanceof Braintree_Transaction); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Some transactions are already settled or voided and cannot be voided. */ public function testVoidInvalidState() { $orderId = 1005; $paymentObject = $this->setupPaymentObjectForVoid($orderId); $transactions = ['1' => \Braintree_Transaction::factory(['id' => '1', 'status' => \Braintree_Transaction::SETTLED])]; $this->setupTransactionIds($orderId, array_keys($transactions)); $index = 0; foreach ($transactions as $id => $transaction) { $this->braintreeTransactionMock->expects($this->at($index))->method('find')->with($id)->willReturn($transaction); $index++; } $this->model->void($paymentObject); }
/** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function authorizeDataProvider() { return ['paypal_payment_nonce' => ['config' => ['is3dSecureEnabled' => false, 'isFraudProtectionEnabled' => false, 'isDebugEnabled' => false, 'useVault' => false, 'getMerchantAccountId' => self::MERCHANT_ACCOUNT_ID], 'infoInstanceValueMap' => [['store_in_vault', null], ['payment_method_nonce', self::PAYMENT_METHOD_NONCE], ['device_data', 'fraud_detection_data']], 'expectedParams' => ['options' => ['addBillingAddressToPaymentMethod' => true], 'merchantAccountId' => self::MERCHANT_ACCOUNT_ID, 'paymentMethodNonce' => self::PAYMENT_METHOD_NONCE], 'braintree_response' => ['transaction' => \Braintree_Transaction::factory(['id' => self::AUTH_TRAN_ID, 'gatewayRejectionReason' => null, 'processorAuthorizationCode' => 'S02T5Q', 'processorResponseCode' => '1000', 'processorResponseText' => 'Approved', 'paypal' => ['payerEmail' => self::PAYER_EMAIL, 'paymentId' => self::PAYMENT_ID, 'authorizationId' => self::AUTHORIZATION_ID, 'payerId' => self::PAYER_ID, 'payerFirstName' => self::FNAME, 'payerLastName' => self::LNAME]])], 'expected_payment_fields' => ['status' => 'APPROVED', 'cc_trans_id' => self::AUTH_TRAN_ID, 'last_trans_id' => self::AUTH_TRAN_ID, 'transaction_id' => self::AUTH_TRAN_ID, 'is_transactioN_cloned' => 0, 'amount' => self::AUTH_AMOUNT, 'should_close_parent_transaction' => false, 'additional_information' => ['processorAuthorizationCode' => 'S02T5Q', 'processorResponseCode' => '1000', 'processorResponseText' => 'Approved', 'payerEmail' => self::PAYER_EMAIL, 'paymentId' => self::PAYMENT_ID, 'authorizationId' => self::AUTHORIZATION_ID, 'payerId' => self::PAYER_ID, 'payerFirstName' => self::FNAME, 'payerLastName' => self::LNAME]]], 'paypal_payment_nonce_fraud_protection' => ['config' => ['is3dSecureEnabled' => false, 'isFraudProtectionEnabled' => true, 'isDebugEnabled' => false, 'useVault' => false, 'getMerchantAccountId' => self::MERCHANT_ACCOUNT_ID], 'infoInstanceValueMap' => [['store_in_vault', null], ['payment_method_nonce', self::PAYMENT_METHOD_NONCE], ['device_data', 'fraud_detection_data']], 'expectedParams' => ['options' => ['addBillingAddressToPaymentMethod' => true], 'merchantAccountId' => self::MERCHANT_ACCOUNT_ID, 'paymentMethodNonce' => self::PAYMENT_METHOD_NONCE, 'deviceData' => 'fraud_detection_data'], 'braintree_response' => ['transaction' => \Braintree_Transaction::factory(['id' => self::AUTH_TRAN_ID, 'gatewayRejectionReason' => null, 'processorAuthorizationCode' => 'S02T5Q', 'processorResponseCode' => '1000', 'processorResponseText' => 'Approved', 'paypal' => ['payerEmail' => self::PAYER_EMAIL, 'paymentId' => self::PAYMENT_ID, 'authorizationId' => self::AUTHORIZATION_ID, 'payerId' => self::PAYER_ID, 'payerFirstName' => self::FNAME, 'payerLastName' => self::LNAME]])], 'expected_payment_fields' => ['status' => 'APPROVED', 'cc_trans_id' => self::AUTH_TRAN_ID, 'last_trans_id' => self::AUTH_TRAN_ID, 'transaction_id' => self::AUTH_TRAN_ID, 'is_transactioN_cloned' => 0, 'amount' => self::AUTH_AMOUNT, 'should_close_parent_transaction' => false, 'additional_information' => ['processorAuthorizationCode' => 'S02T5Q', 'processorResponseCode' => '1000', 'processorResponseText' => 'Approved', 'payerEmail' => self::PAYER_EMAIL, 'paymentId' => self::PAYMENT_ID, 'authorizationId' => self::AUTHORIZATION_ID, 'payerId' => self::PAYER_ID, 'payerFirstName' => self::FNAME, 'payerLastName' => self::LNAME]]]]; }
function testGet_givesErrorIfInvalidProperty() { $t = Braintree_Transaction::factory(array('creditCard' => array('expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100'), 'customer' => array(), 'billing' => array(), 'descriptor' => array(), 'shipping' => array(), 'subscription' => array('billingPeriodStartDate' => '1983-07-12'), 'statusHistory' => array())); $this->setExpectedException('PHPUnit_Framework_Error', 'Undefined property on Braintree_Transaction: foo'); $t->foo; }
/** * @ignore */ private static function _verifyGatewayResponse($response) { if (isset($response['subscription'])) { return new Braintree_Result_Successful(self::factory($response['subscription'])); } else { if (isset($response['transaction'])) { // return a populated instance of Braintree_Transaction, for subscription retryCharge return new Braintree_Result_Successful(Braintree_Transaction::factory($response['transaction'])); } else { if (isset($response['apiErrorResponse'])) { return new Braintree_Result_Error($response['apiErrorResponse']); } } } }