diff --git a/MangoPaySDK/entities/cardPreAuthorization.inc b/MangoPaySDK/entities/cardPreAuthorization.inc new file mode 100644 index 00000000..813b3c89 --- /dev/null +++ b/MangoPaySDK/entities/cardPreAuthorization.inc @@ -0,0 +1,123 @@ + '\MangoPay\Money' + ); + } + + /** + * Get array with read-only properties + * @return array + */ + public function GetReadOnlyProperties() { + $properties = parent::GetReadOnlyProperties(); + array_push( $properties, 'Status' ); + array_push( $properties, 'ResultCode' ); + array_push( $properties, 'ResultMessage' ); + + return $properties; + } +} diff --git a/MangoPaySDK/entities/payIn.inc b/MangoPaySDK/entities/payIn.inc index 9458c8c7..0b4dd24f 100644 --- a/MangoPaySDK/entities/payIn.inc +++ b/MangoPaySDK/entities/payIn.inc @@ -45,6 +45,8 @@ class PayIn extends Transaction { 'PaymentType' => array( '_property_name' => 'PaymentDetails', 'CARD' => '\MangoPay\PayInPaymentDetailsCard', + 'PREAUTHORIZED' => '\MangoPay\PayInPaymentDetailsPreAuthorized', + 'BANK_WIRE' => '\MangoPay\PayInPaymentDetailsBankWire', // ...and more in future... ), 'ExecutionType' => array( diff --git a/MangoPaySDK/entities/transaction.inc b/MangoPaySDK/entities/transaction.inc index 6963cf54..99d66f4d 100644 --- a/MangoPaySDK/entities/transaction.inc +++ b/MangoPaySDK/entities/transaction.inc @@ -49,6 +49,12 @@ class Transaction extends EntityBase { */ public $ResultCode; + /** + * The PreAuthorization result Message explaining the result code + * @var string + */ + public $ResultMessage; + /** * Execution date; * @var date diff --git a/MangoPaySDK/mangoPayApi.inc b/MangoPaySDK/mangoPayApi.inc index c39d80d1..d3909b8f 100644 --- a/MangoPaySDK/mangoPayApi.inc +++ b/MangoPaySDK/mangoPayApi.inc @@ -81,7 +81,13 @@ class MangoPayApi { * Card registration methods * @var ApiCardRegistrations */ - public $CardRegistrations; + public $CardRegistrations; + + /** + * Pre-authorization methods + * @var ApiCardPreAuthorization + */ + public $CardPreAuthorizations; /** * Card methods @@ -116,5 +122,6 @@ class MangoPayApi { $this->CardRegistrations = new ApiCardRegistrations($this); $this->Cards = new ApiCards($this); $this->Events = new ApiEvents($this); + $this->CardPreAuthorizations = new ApiCardPreAuthorizations($this); } } \ No newline at end of file diff --git a/MangoPaySDK/tools/apiBase.inc b/MangoPaySDK/tools/apiBase.inc index 56ecfaae..3b4a92d8 100644 --- a/MangoPaySDK/tools/apiBase.inc +++ b/MangoPaySDK/tools/apiBase.inc @@ -20,9 +20,6 @@ abstract class ApiBase { 'authentication_base' => array( '/api/clients/', RequestType::POST ), 'authentication_oauth' => array( '/api/oauth/token', RequestType::POST ), - 'crosscurrencytransfers_create' => array( '/transfers/%s', RequestType::POST ), - 'crosscurrencytransfers_get' => array( '/transfers/%s', RequestType::GET ), - 'events_all' => array( '/events', RequestType::GET ), 'events_gethookcallbacks' => array( '/events/%s/hook-callbacks', RequestType::GET ), @@ -39,47 +36,28 @@ abstract class ApiBase { 'cardregistration_get' => array( '/cardregistrations/%s', RequestType::GET ), 'cardregistration_save' => array( '/cardregistrations/%s', RequestType::PUT ), + 'preauthorization_create' => array( '/preauthorizations/card/direct', RequestType::POST ), + 'preauthorization_get' => array( '/preauthorizations/%s', RequestType::GET ), + 'preauthorization_save' => array( '/preauthorizations/%s', RequestType::PUT ), + 'card_get' => array( '/cards/%s', RequestType::GET ), // pay ins URLs 'payins_card-web_create' => array( '/payins/card/web/', RequestType::POST ), 'payins_card-direct_create' => array( '/payins/card/direct/', RequestType::POST ), - 'payins_card-preauthorized_create' => array( '/payins/card/preauthorized/', RequestType::POST ), - 'payins_card-recurrentexecution_create' => array( '/payins/card/recurrent-pay-in-execution/', RequestType::POST ), - - 'payins_registeredcard-web_create' => array( '/payins/card/web/', RequestType::POST ), - 'payins_registeredcard-direct_create' => array( '/payins/card/direct/', RequestType::POST ), - 'payins_registeredcard-preauthorized_create' => array( '/payins/registered-card/preauthorized/', RequestType::POST ), - 'payins_registeredcard-recurrentexecution_create' => array( '/payins/registered-card/recurrent-pay-in-execution/', RequestType::POST ), - - 'payins_bankwirepayin-web_create' => array( '/payins/bankwire/web/', RequestType::POST ), - 'payins_bankwirepayin-direct_create' => array( '/payins/bankwire/direct/', RequestType::POST ), - 'payins_bankwirepayin-preauthorized_create' => array( '/payins/bankwire/preauthorized/', RequestType::POST ), - 'payins_bankwirepayin-recurrentexecution_create' => array( '/payins/bankwire/recurrent-pay-in-execution/', RequestType::POST ), - - 'payins_directcredit-web_create' => array( '/payins/direct-credit/web/', RequestType::POST ), - 'payins_directcredit-direct_create' => array( '/payins/direct-credit/direct/', RequestType::POST ), - 'payins_directcredit-preauthorized_create' => array( '/payins/direct-credit/preauthorized/', RequestType::POST ), - 'payins_directcredit-recurrentexecution_create' => array( '/payins/direct-credit/recurrent-pay-in-execution/', RequestType::POST ), + 'payins_preauthorized-direct_create' => array( '/payins/preauthorized/direct/', RequestType::POST ), + 'payins_bankwire-direct_create' => array( '/payins/bankwire/direct/', RequestType::POST ), 'payins_get' => array( '/payins/%s', RequestType::GET ), 'payins_getrefunds' => array( '/payins/%s/refunds', RequestType::GET ), 'payins_createrefunds' => array( '/payins/%s/refunds', RequestType::POST ), 'payouts_bankwire_create' => array( '/payouts/bankwire/', RequestType::POST ), - 'payouts_merchantexpense_create' => array( '/payouts/merchant-expense/', RequestType::POST ), - 'payouts_amazongiftcard_create' => array( '/payouts/amazon-giftcard/', RequestType::POST ), 'payouts_get' => array( '/payouts/%s', RequestType::GET ), 'payouts_createrefunds' => array( '/payouts/%s/refunds', RequestType::POST ), 'payouts_getrefunds' => array( '/payouts/%s/refunds', RequestType::GET ), - 'reccurringpayinorders_create' => array( '/reccurring-pay-in-orders', RequestType::POST ), - 'reccurringpayinorders_get' => array( '/reccurring-pay-in-orders/%s', RequestType::GET ), - 'reccurringpayinorders_gettransactions' => array( '/reccurring-pay-in-orders/%s/transactions', RequestType::GET ), - 'refunds_get' => array( '/refunds/%s', RequestType::GET ), - 'repudiations_get' => array( '/repudiations/%s', RequestType::GET ), - 'transfers_create' => array( '/transfers', RequestType::POST ), 'transfers_get' => array( '/transfers/%s', RequestType::GET ), 'transfers_getrefunds' => array( '/transfers/%s/refunds', RequestType::GET ), @@ -94,7 +72,8 @@ abstract class ApiBase { 'users_allkycrequests' => array( '/users/%s/KYC/requests', RequestType::GET ), 'users_allwallets' => array( '/users/%s/wallets', RequestType::GET ), 'users_allbankaccount' => array( '/users/%s/bankaccounts', RequestType::GET ), - 'users_allpaymentcards' => array( '/users/%s/payment-cards', RequestType::GET ), + 'users_allcards' => array( '/users/%s/cards', RequestType::GET ), + 'users_alltransactions' => array( '/users/%s/transactions', RequestType::GET ), 'users_get' => array( '/users/%s', RequestType::GET ), 'users_getnaturals' => array( '/users/natural/%s', RequestType::GET ), 'users_getlegals' => array( '/users/legal/%s', RequestType::GET ), @@ -293,7 +272,11 @@ abstract class ApiBase { // is sub object? if (isset($subObjects[$name])) { - $object = $this->CastResponseToEntity($value, $subObjects[$name]); + if (is_null($value)) + $object = null; + else + $object = $this->CastResponseToEntity($value, $subObjects[$name]); + $entityProperty->setValue($entity, $object); } else { $entityProperty->setValue($entity, $value); diff --git a/MangoPaySDK/tools/apiCardPreAuthorizations.inc b/MangoPaySDK/tools/apiCardPreAuthorizations.inc new file mode 100644 index 00000000..9f82eda9 --- /dev/null +++ b/MangoPaySDK/tools/apiCardPreAuthorizations.inc @@ -0,0 +1,35 @@ +CreateObject('preauthorization_create', $cardPreAuthorization, '\MangoPay\CardPreAuthorization'); + } + + /** + * Get pre-authorization object + * @param int $cardPreAuthorizationId PreAuthorization identifier + * @return \MangoPay\CardPreAuthorization Card registration object returned from API + */ + public function Get($cardPreAuthorizationId) { + return $this->GetObject('preauthorization_get', $cardPreAuthorizationId, '\MangoPay\CardPreAuthorization'); + } + + /** + * Update pre-authorization object + * @param \MangoPay\CardPreAuthorization $preAuthorization PreAuthorization object to save + * @return \MangoPay\CardPreAuthorization PreAuthorization object returned from API + */ + public function Update($cardPreAuthorization) { + return $this->SaveObject('preauthorization_save', $cardPreAuthorization, '\MangoPay\CardPreAuthorization'); + } +} \ No newline at end of file diff --git a/MangoPaySDK/tools/apiUsers.inc b/MangoPaySDK/tools/apiUsers.inc index 2321b4c1..f629b309 100644 --- a/MangoPaySDK/tools/apiUsers.inc +++ b/MangoPaySDK/tools/apiUsers.inc @@ -132,6 +132,26 @@ class ApiUsers extends ApiBase { public function GetWallets($userId, & $pagination = null) { return $this->GetList('users_allwallets', $pagination, 'MangoPay\Wallet', $userId); } + + /** + * Get all transactions for user + * @param int $userId User Id + * @param \MangoPay\Pagination $pagination Pagination object + * @param \MangoPay\FilterTransactions $filter Object to filter data + * @return \MangoPay\Transaction[] Transactions for user returned from API + */ + public function GetTransactions($userId, & $pagination = null, $filter = null) { + return $this->GetList('users_alltransactions', $pagination, '\MangoPay\Transaction', $userId, $filter); + } + + /** + * Get all cards for user + * @param int $userId User Id + * @return \MangoPay\Card[] Cards for user returned from API + */ + public function GetCards($userId, & $pagination = null) { + return $this->GetList('users_allcards', $pagination, '\MangoPay\Card', $userId); + } /** * Create new KYC document diff --git a/MangoPaySDK/tools/enums.inc b/MangoPaySDK/tools/enums.inc index 95fe074c..ede68ab1 100644 --- a/MangoPaySDK/tools/enums.inc +++ b/MangoPaySDK/tools/enums.inc @@ -49,6 +49,9 @@ class EventType { class KycDocumentType { const IdentityProof = 'IDENTITY_PROOF'; const RegistrationProof = 'REGISTRATION_PROOF'; + const ArticlesOfAssociation = 'ARTICLES_OF_ASSOCIATION'; + const ShareholderDeclaration = 'SHAREHOLDER_DECLARATION'; + const AddressProof = 'ADDRESS_PROOF'; } /** diff --git a/MangoPaySDK/types/payInExecutionDetailsDirect.inc b/MangoPaySDK/types/payInExecutionDetailsDirect.inc index b23869cc..d53a7e63 100644 --- a/MangoPaySDK/types/payInExecutionDetailsDirect.inc +++ b/MangoPaySDK/types/payInExecutionDetailsDirect.inc @@ -12,12 +12,6 @@ class PayInExecutionDetailsDirect extends Dto implements PayInExecutionDetails { */ public $SecureMode; - /** - * CardId - * @var string - */ - public $CardId; - /** * SecureModeReturnURL * @var string diff --git a/MangoPaySDK/types/payInPaymentDetailsBankWire.inc b/MangoPaySDK/types/payInPaymentDetailsBankWire.inc new file mode 100644 index 00000000..9a83480e --- /dev/null +++ b/MangoPaySDK/types/payInPaymentDetailsBankWire.inc @@ -0,0 +1,44 @@ + '\MangoPay\Money' , + 'DeclaredFees' => '\MangoPay\Money' , + 'BankAccount' => '\MangoPay\BankAccount' + ); + } +} diff --git a/MangoPaySDK/types/payInPaymentDetailsCard.inc b/MangoPaySDK/types/payInPaymentDetailsCard.inc index 99461a1a..bbea1645 100644 --- a/MangoPaySDK/types/payInPaymentDetailsCard.inc +++ b/MangoPaySDK/types/payInPaymentDetailsCard.inc @@ -11,4 +11,10 @@ class PayInPaymentDetailsCard extends Dto implements PayInPaymentDetails { * @var string */ public $CardType; + + /** + * CardId + * @var string + */ + public $CardId; } diff --git a/MangoPaySDK/types/payInPaymentDetailsPreAuthorized.inc b/MangoPaySDK/types/payInPaymentDetailsPreAuthorized.inc new file mode 100644 index 00000000..cf0410cb --- /dev/null +++ b/MangoPaySDK/types/payInPaymentDetailsPreAuthorized.inc @@ -0,0 +1,14 @@ + 'User_Users_ListSubEntity_GetWallets', ), 'Transactions' => array( + 'List transactions for user' => 'User_Users_ListSubEntity_GetTransactions_FilterTransactions', 'List transactions for wallet' => 'Wallet_Wallets_ListSubEntity_GetTransactions_FilterTransactions', ), 'Transfers' => array( @@ -32,6 +33,8 @@ 'Pay-ins' => array( 'Create pay-in web card' => 'PayIn_PayIns_Create_:CARD:WEB', 'Create pay-in direct card' => 'PayIn_PayIns_Create_:CARD:DIRECT', + 'Create pay-in direct pre-authorized' => 'PayIn_PayIns_Create_:PREAUTHORIZED:DIRECT', + 'Create pay-in direct bank wire' => 'PayIn_PayIns_Create_:BANK_WIRE:DIRECT', 'Get pay-in' => 'PayIn_PayIns_Get', ), 'Pay-outs' => array( @@ -48,8 +51,14 @@ 'Get card registration' => 'CardRegistration_CardRegistrations_Get', 'Update card registration' => 'CardRegistration_CardRegistrations_Save', ), + 'Card pre-authorization' => array( + 'Create pre-authorization' => 'CardPreAuthorization_CardPreAuthorizations_Create', + 'Get pre-authorization' => 'CardPreAuthorization_CardPreAuthorizations_Get', + 'Update pre-authorization' => 'CardPreAuthorization_CardPreAuthorizations_Save', + ), 'Card' => array( 'Get card' => 'Card_Cards_Get', + 'List cards for user' => 'User_Users_ListSubEntity_GetCards', ), 'Event' => array( 'Get event' => 'Event_Events_All__FilterEvents', diff --git a/tests/cases/base.php b/tests/cases/base.php index ebe687c5..196a1390 100644 --- a/tests/cases/base.php +++ b/tests/cases/base.php @@ -114,6 +114,24 @@ protected function getJohn() { return self::$John; } + /** + * Creates new user + * @return \MangoPay\UserNatural + */ + protected function getNewJohn() { + $user = new \MangoPay\UserNatural(); + $user->FirstName = "John"; + $user->LastName = "Doe"; + $user->Email = "john.doe@sample.org"; + $user->Address = "Some Address"; + $user->Birthday = mktime(0, 0, 0, 12, 21, 1975); + $user->Nationality = "FR"; + $user->CountryOfResidence = "FR"; + $user->Occupation = "programmer"; + $user->IncomeRange = 3; + return $this->_api->Users->Create($user); + } + /** * Creates self::$Matrix (test legal user) if not created yet * @return \MangoPay\UserLegal @@ -308,12 +326,15 @@ protected function getJohnsPayInCardWeb() { * Creates Pay-In Card Direct object * @return \MangoPay\PayIn */ - protected function getNewPayInCardDirect() { + protected function getNewPayInCardDirect($userId = null) { $wallet = $this->getJohnsWalletWithMoney(); - $user = $this->getJohn(); - + if (is_null($userId)){ + $user = $this->getJohn(); + $userId = $user->Id; + } + $cardRegistration = new \MangoPay\CardRegistration(); - $cardRegistration->UserId = $user->Id; + $cardRegistration->UserId = $userId; $cardRegistration->Currency = 'EUR'; $cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistartionData($cardRegistration); @@ -324,7 +345,7 @@ protected function getNewPayInCardDirect() { // create pay-in CARD DIRECT $payIn = new \MangoPay\PayIn(); $payIn->CreditedWalletId = $wallet->Id; - $payIn->AuthorId = $user->Id; + $payIn->AuthorId = $userId; $payIn->DebitedFunds = new \MangoPay\Money(); $payIn->DebitedFunds->Amount = 10000; $payIn->DebitedFunds->Currency = 'EUR'; @@ -333,15 +354,14 @@ protected function getNewPayInCardDirect() { $payIn->Fees->Currency = 'EUR'; // payment type as CARD $payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsCard(); + $payIn->PaymentDetails->CardId = $card->Id; if ($card->CardType == 'CB' || $card->CardType == 'VISA' || $card->CardType == 'MASTERCARD') $payIn->PaymentDetails->CardType = 'CB_VISA_MASTERCARD'; elseif ($card->CardType == 'AMEX') $payIn->PaymentDetails->CardType = 'AMEX'; // execution type as DIRECT $payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect(); - $payIn->ExecutionDetails->CardId = $card->Id; $payIn->ExecutionDetails->SecureModeReturnURL = 'http://test.com'; - return $this->_api->PayIns->Create($payIn); } @@ -497,6 +517,32 @@ protected function getJohnsCardRegistration() { return self::$JohnsCardRegistration; } + /** + * Creates card registration object + * @return \MangoPay\CardPreAuthorization + */ + protected function getJohnsCardPreAuthorization() { + $user = $this->getJohn(); + $cardRegistration = new \MangoPay\CardRegistration(); + $cardRegistration->UserId = $user->Id; + $cardRegistration->Currency = 'EUR'; + $newCardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); + + $registrationData = $this->getPaylineCorrectRegistartionData($newCardRegistration); + $newCardRegistration->RegistrationData = $registrationData; + $getCardRegistration = $this->_api->CardRegistrations->Update($newCardRegistration); + + $cardPreAuthorization = new \MangoPay\CardPreAuthorization(); + $cardPreAuthorization->AuthorId = $user->Id; + $cardPreAuthorization->DebitedFunds = new \MangoPay\Money(); + $cardPreAuthorization->DebitedFunds->Currency = "EUR"; + $cardPreAuthorization->DebitedFunds->Amount = 10000; + $cardPreAuthorization->CardId = $getCardRegistration->CardId; + $cardPreAuthorization->SecureModeReturnURL = 'http://test.com'; + + return $this->_api->CardPreAuthorizations->Create($cardPreAuthorization); + } + /** * Get registration data from Payline service * @param \MangoPay\CardRegistration $cardRegistration @@ -574,9 +620,10 @@ protected function assertIdenticalInputProps($entity1, $entity2) { $this->assertIdenticalInputProps($entity1->CreditedFunds, $entity2->CreditedFunds); $this->assertIdenticalInputProps($entity1->Fees, $entity2->Fees); } elseif (is_a($entity1, '\MangoPay\Card')) { + $this->assertIdentical($entity1->ExpirationDate, $entity2->ExpirationDate); + $this->assertIdentical($entity1->Alias, $entity2->Alias); $this->assertIdentical($entity1->CardType, $entity2->CardType); - $this->assertIdentical($entity1->RedirectURL, $entity2->RedirectURL); - $this->assertIdentical($entity1->ReturnURL, $entity2->ReturnURL); + $this->assertIdentical($entity1->Currency, $entity2->Currency); } elseif (is_a($entity1, '\MangoPay\Web')) { $this->assertIdentical($entity1->TemplateURL, $entity2->TemplateURL); $this->assertIdentical($entity1->Culture, $entity2->Culture); diff --git a/tests/cases/cardPreAuthorizations.php b/tests/cases/cardPreAuthorizations.php new file mode 100644 index 00000000..067919c9 --- /dev/null +++ b/tests/cases/cardPreAuthorizations.php @@ -0,0 +1,39 @@ +getJohnsCardPreAuthorization(); + + $this->assertTrue($cardPreAuthorization->Id > 0); + $this->assertIdentical($cardPreAuthorization->Status, 'SUCCEEDED'); + $this->assertIdentical($cardPreAuthorization->PaymentStatus, 'WAITING'); + $this->assertIdentical($cardPreAuthorization->ExecutionType, 'DIRECT'); + $this->assertNull($cardPreAuthorization->PayInId); + } + + function test_CardPreAuthorization_Get() { + $cardPreAuthorization = $this->getJohnsCardPreAuthorization(); + + $getCardPreAuthorization = $this->_api->CardPreAuthorizations->Get($cardPreAuthorization->Id); + + $this->assertIdentical($cardPreAuthorization->Id, $getCardPreAuthorization->Id); + $this->assertIdentical($getCardPreAuthorization->ResultCode, '000000'); + } + + function test_CardPreAuthorization_Update() { + $cardPreAuthorization = $this->getJohnsCardPreAuthorization(); + $cardPreAuthorization->PaymentStatus = "CANCELED "; + + $resultCardPreAuthorization = $this->_api->CardPreAuthorizations->Update($cardPreAuthorization); + + $this->assertIdentical($resultCardPreAuthorization->Status, "SUCCEEDED"); + $this->assertIdentical($resultCardPreAuthorization->PaymentStatus, 'CANCELED'); + } +} \ No newline at end of file diff --git a/tests/cases/payIns.php b/tests/cases/payIns.php index f1c9299d..951c8c35 100644 --- a/tests/cases/payIns.php +++ b/tests/cases/payIns.php @@ -70,7 +70,7 @@ function test_PayIns_Get_CardDirect() { $this->assertIdentical($payIn->ExecutionType, 'DIRECT'); $this->assertIsA($payIn->ExecutionDetails, '\MangoPay\PayInExecutionDetailsDirect'); $this->assertIdenticalInputProps($payIn, $getPayIn); - $this->assertNotNull($getPayIn->ExecutionDetails->CardId); + $this->assertNotNull($getPayIn->PaymentDetails->CardId); } function test_PayIns_CreateRefund_CardDirect() { @@ -87,6 +87,119 @@ function test_PayIns_CreateRefund_CardDirect() { $this->assertEqual('PAYOUT', $refund->Type); $this->assertEqual('REFUND', $refund->Nature); } - + + function test_PayIns_PreAuthorizedDirect() { + $cardPreAuthorization = $this->getJohnsCardPreAuthorization(); + $wallet = $this->getJohnsWalletWithMoney(); + $user = $this->getJohn(); + // create pay-in PRE-AUTHORIZED DIRECT + $payIn = new \MangoPay\PayIn(); + $payIn->CreditedWalletId = $wallet->Id; + $payIn->AuthorId = $user->Id; + $payIn->DebitedFunds = new \MangoPay\Money(); + $payIn->DebitedFunds->Amount = 10000; + $payIn->DebitedFunds->Currency = 'EUR'; + $payIn->Fees = new \MangoPay\Money(); + $payIn->Fees->Amount = 0; + $payIn->Fees->Currency = 'EUR'; + // payment type as CARD + $payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsPreAuthorized(); + $payIn->PaymentDetails->PreauthorizationId = $cardPreAuthorization->Id; + // execution type as DIRECT + $payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect(); + $payIn->ExecutionDetails->SecureModeReturnURL = 'http://test.com'; + + $createPayIn = $this->_api->PayIns->Create($payIn); + + $this->assertTrue($createPayIn->Id > 0); + $this->assertEqual($wallet->Id, $createPayIn->CreditedWalletId); + $this->assertEqual('PREAUTHORIZED', $createPayIn->PaymentType); + $this->assertIsA($createPayIn->PaymentDetails, '\MangoPay\PayInPaymentDetailsPreAuthorized'); + $this->assertEqual('DIRECT', $createPayIn->ExecutionType); + $this->assertIsA($createPayIn->ExecutionDetails, '\MangoPay\PayInExecutionDetailsDirect'); + $this->assertIsA($createPayIn->DebitedFunds, '\MangoPay\Money'); + $this->assertIsA($createPayIn->CreditedFunds, '\MangoPay\Money'); + $this->assertIsA($createPayIn->Fees, '\MangoPay\Money'); + $this->assertEqual($user->Id, $createPayIn->AuthorId); + $this->assertEqual('SUCCEEDED', $createPayIn->Status); + $this->assertEqual('PAYIN', $createPayIn->Type); + } + + function test_PayIns_BankWireDirect_Create() { + $wallet = $this->getJohnsWallet(); + $user = $this->getJohn(); + // create pay-in PRE-AUTHORIZED DIRECT + $payIn = new \MangoPay\PayIn(); + $payIn->CreditedWalletId = $wallet->Id; + $payIn->AuthorId = $user->Id; + // payment type as CARD + $payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsBankWire(); + $payIn->PaymentDetails->DeclaredDebitedFunds = new \MangoPay\Money(); + $payIn->PaymentDetails->DeclaredDebitedFunds->Amount = 10000; + $payIn->PaymentDetails->DeclaredDebitedFunds->Currency = 'EUR'; + $payIn->PaymentDetails->DeclaredFees = new \MangoPay\Money(); + $payIn->PaymentDetails->DeclaredFees->Amount = 0; + $payIn->PaymentDetails->DeclaredFees->Currency = 'EUR'; + $payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect(); + + $createPayIn = $this->_api->PayIns->Create($payIn); + + $this->assertTrue($createPayIn->Id > 0); + $this->assertEqual($wallet->Id, $createPayIn->CreditedWalletId); + $this->assertEqual('BANK_WIRE', $createPayIn->PaymentType); + $this->assertIsA($createPayIn->PaymentDetails, '\MangoPay\PayInPaymentDetailsBankWire'); + $this->assertIsA($createPayIn->PaymentDetails->DeclaredDebitedFunds, '\MangoPay\Money'); + $this->assertIsA($createPayIn->PaymentDetails->DeclaredFees, '\MangoPay\Money'); + $this->assertEqual('DIRECT', $createPayIn->ExecutionType); + $this->assertIsA($createPayIn->ExecutionDetails, '\MangoPay\PayInExecutionDetailsDirect'); + $this->assertEqual($user->Id, $createPayIn->AuthorId); + $this->assertEqual('CREATED', $createPayIn->Status); + $this->assertEqual('PAYIN', $createPayIn->Type); + $this->assertNotNull($createPayIn->PaymentDetails->WireReference); + $this->assertIsA($createPayIn->PaymentDetails->BankAccount, '\MangoPay\BankAccount'); + $this->assertEqual($createPayIn->PaymentDetails->BankAccount->Type, 'IBAN'); + $this->assertNotNull($createPayIn->PaymentDetails->BankAccount->IBAN); + $this->assertNotNull($createPayIn->PaymentDetails->BankAccount->BIC); + } + + function test_PayIns_BankWireDirect_Get() { + $wallet = $this->getJohnsWallet(); + $user = $this->getJohn(); + // create pay-in PRE-AUTHORIZED DIRECT + $payIn = new \MangoPay\PayIn(); + $payIn->CreditedWalletId = $wallet->Id; + $payIn->AuthorId = $user->Id; + // payment type as CARD + $payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsBankWire(); + $payIn->PaymentDetails->DeclaredDebitedFunds = new \MangoPay\Money(); + $payIn->PaymentDetails->DeclaredDebitedFunds->Amount = 10000; + $payIn->PaymentDetails->DeclaredDebitedFunds->Currency = 'EUR'; + $payIn->PaymentDetails->DeclaredFees = new \MangoPay\Money(); + $payIn->PaymentDetails->DeclaredFees->Amount = 0; + $payIn->PaymentDetails->DeclaredFees->Currency = 'EUR'; + $payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect(); + $createdPayIn = $this->_api->PayIns->Create($payIn); + + $getPayIn = $this->_api->PayIns->Get($createdPayIn->Id); + + $this->assertEqual($getPayIn->Id, $createdPayIn->Id); + $this->assertEqual('BANK_WIRE', $getPayIn->PaymentType); + $this->assertIsA($getPayIn->PaymentDetails, '\MangoPay\PayInPaymentDetailsBankWire'); + $this->assertIsA($getPayIn->PaymentDetails->DeclaredDebitedFunds, '\MangoPay\Money'); + $this->assertIsA($getPayIn->PaymentDetails->DeclaredFees, '\MangoPay\Money'); + $this->assertEqual('DIRECT', $getPayIn->ExecutionType); + $this->assertIsA($getPayIn->ExecutionDetails, '\MangoPay\PayInExecutionDetailsDirect'); + $this->assertEqual($user->Id, $getPayIn->AuthorId); + $this->assertEqual('PAYIN', $getPayIn->Type); + $this->assertNotNull($getPayIn->PaymentDetails->WireReference); + $this->assertIsA($getPayIn->PaymentDetails->BankAccount, '\MangoPay\BankAccount'); + $this->assertEqual($getPayIn->PaymentDetails->BankAccount->Type, 'IBAN'); + $this->assertNotNull($getPayIn->PaymentDetails->BankAccount->IBAN); + $this->assertNotNull($getPayIn->PaymentDetails->BankAccount->BIC); + + + + + } } diff --git a/tests/cases/users.php b/tests/cases/users.php index c03705b5..6027162f 100644 --- a/tests/cases/users.php +++ b/tests/cases/users.php @@ -159,6 +159,49 @@ function test_Users_GetKycDocument(){ $this->assertIdentical($kycDocument->Type, $getKycDocument->Type); } + function test_Users_CreateKycDocument_TestAll(){ + $john = $this->getJohn(); + $legalJohn = $this->getMatrix(); + + $aKycDocTypes = array( + array(\MangoPay\KycDocumentType::AddressProof, $john->Id), + array(\MangoPay\KycDocumentType::ArticlesOfAssociation, $legalJohn->Id), + array(\MangoPay\KycDocumentType::IdentityProof, $john->Id), + array(\MangoPay\KycDocumentType::RegistrationProof, $legalJohn->Id), + array(\MangoPay\KycDocumentType::ShareholderDeclaration, $legalJohn->Id) + ); + + foreach ($aKycDocTypes as $kycDoc) { + try{ + $this->CreateKycDocument_TestOne($kycDoc[0], $kycDoc[1]); + } catch (\MangoPay\Exception $exc){ + + $message = 'Error (Code: ' . $exc->getCode() . ', ' + . $exc->getMessage() . ') ' + .'during create/get KYC Document with type: ' . $kycDoc[0]; + $this->fail($message); + + } + } + } + + function CreateKycDocument_TestOne($kycDocType, $userId){ + + $kycDocument = new \MangoPay\KycDocument(); + $kycDocument->Status = \MangoPay\KycDocumentStatus::Created; + $kycDocument->Type = $kycDocType; + + $createdKycDocument = $this->_api->Users->CreateKycDocument($userId, $kycDocument); + $getKycDocument = $this->_api->Users->GetKycDocument($userId, $createdKycDocument->Id); + + $this->assertTrue($createdKycDocument->Id > 0); + $this->assertIdentical($createdKycDocument->Status, \MangoPay\KycDocumentStatus::Created); + $this->assertIdentical($createdKycDocument->Type, $kycDocType); + $this->assertIdentical($createdKycDocument->Id, $getKycDocument->Id); + $this->assertIdentical($createdKycDocument->Status, $getKycDocument->Status); + $this->assertIdentical($createdKycDocument->Type, $getKycDocument->Type); + } + function test_Users_UpdateKycDocument(){ $kycDocument = $this->getJohnsKycDocument(); $user = $this->getJohn(); @@ -179,7 +222,7 @@ function test_Users_CreateKycPage_EmptyFileString(){ $this->fail('Expected ResponseException when empty file string'); } catch (\MangoPay\ResponseException $exc) { - + $this->assertIdentical($exc->getCode(), 400); } } @@ -251,4 +294,34 @@ function test_Users_CreateKycPage_CorrectFilePath() { $this->_api->Users->CreateKycPageFromFile($user->Id, $kycDocument->Id, __FILE__); } + + function test_Users_AllTransactions() { + $john = $this->getJohn(); + $payIn = $this->getNewPayInCardDirect(); + + $pagination = new \MangoPay\Pagination(1, 1); + $filter = new \MangoPay\FilterTransactions(); + $filter->Type = 'PAYIN'; + $filter->AfterDate = $payIn->CreationDate - 1; + $filter->BeforeDate = $payIn->CreationDate + 1; + $transactions = $this->_api->Users->GetTransactions($john->Id, $pagination, $filter); + + $this->assertEqual(count($transactions), 1); + $this->assertIsA($transactions[0], '\MangoPay\Transaction'); + $this->assertEqual($transactions[0]->AuthorId, $john->Id); + $this->assertIdenticalInputProps($transactions[0], $payIn); + } + + function test_Users_AllCards() { + $john = $this->getNewJohn(); + $payIn = $this->getNewPayInCardDirect($john->Id); + $card =$this->_api->Cards->Get($payIn->PaymentDetails->CardId); + $pagination = new \MangoPay\Pagination(1, 1); + + $cards = $this->_api->Users->GetCards($john->Id, $pagination); + + $this->assertEqual(count($cards), 1); + $this->assertIsA($cards[0], '\MangoPay\Card'); + $this->assertIdenticalInputProps($cards[0], $card); + } }