/**
  * @param array $data
  * @return \SubscribePro\Service\Subscription\SubscriptionInterface
  */
 public function create(array $data = [])
 {
     $addressData = $this->getFieldData($data, SubscriptionInterface::SHIPPING_ADDRESS);
     $data[SubscriptionInterface::SHIPPING_ADDRESS] = $this->addressFactory->create($addressData);
     $paymentProfileData = $this->getFieldData($data, SubscriptionInterface::PAYMENT_PROFILE);
     $data[SubscriptionInterface::PAYMENT_PROFILE] = $this->paymentProfileFactory->create($paymentProfileData);
     return new $this->instanceName($data);
 }
 public function testLoadEvent()
 {
     $eventId = 52231;
     $itemData = [EventInterface::ID => $eventId];
     $eventMock = $this->getMockBuilder('SubscribePro\\Service\\Webhook\\EventInterface')->getMock();
     $this->httpClientMock->expects($this->once())->method('get')->with("/services/v2/webhook-events/{$eventId}.json")->willReturn([WebhookService::API_NAME_WEBHOOK_EVENT => $itemData]);
     $this->eventFactoryMock->expects($this->once())->method('create')->with($itemData)->willReturn($eventMock);
     $this->assertSame($eventMock, $this->webhookService->loadEvent($eventId));
 }
 public function testLoadToken()
 {
     $token = 'token-value';
     $itemData = [TokenInterface::TOKEN => 'token', TokenInterface::CITY => 'city'];
     $tokenMock = $this->createTokenMock();
     $this->httpClientMock->expects($this->once())->method('get')->with("/services/v1/vault/tokens/{$token}.json")->willReturn([TokenService::API_NAME_TOKEN => $itemData]);
     $this->tokenFactoryMock->expects($this->once())->method('create')->with($itemData)->willReturn($tokenMock);
     $this->assertSame($tokenMock, $this->tokenService->loadToken($token));
 }
 public function testVoid()
 {
     $itemId = 12321;
     $resultData = [TransactionInterface::ID => $itemId];
     $transactionMock = $this->createTransactionMock();
     $this->transactionFactoryMock->expects($this->once())->method('create')->with($resultData)->willReturn($transactionMock);
     $this->httpClientMock->expects($this->once())->method('post')->with("/services/v1/vault/transactions/{$itemId}/void.json")->willReturn([TransactionService::API_NAME_TRANSACTION => $resultData]);
     $this->assertSame($transactionMock, $this->transactionService->void($itemId));
 }
 /**
  * @param int $customerId
  * @param array $filters
  * @param array $itemsData
  * @dataProvider loadProductsDataProvider
  */
 public function testLoadProducts($customerId, $filters, $itemsData)
 {
     $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/products.json', $filters)->willReturn([ProductService::API_NAME_PRODUCTS => $itemsData]);
     $products = [];
     $productFactoryMap = [];
     foreach ($itemsData as $itemData) {
         $product = $this->createProductMock();
         $productFactoryMap[] = [$itemData, $product];
         $products[] = $product;
     }
     $this->productFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($productFactoryMap);
     $this->assertSame($products, $this->productService->loadProducts($customerId));
 }
 /**
  * @param array $filters
  * @param array $itemsData
  * @dataProvider loadCustomersDataProvider
  */
 public function testLoadCustomers($filters, $itemsData)
 {
     $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/customers.json', $filters)->willReturn([CustomerService::API_NAME_CUSTOMERS => $itemsData]);
     $customers = [];
     $customerFactoryMap = [];
     foreach ($itemsData as $itemData) {
         $customer = $this->createCustomerMock();
         $customerFactoryMap[] = [$itemData, $customer];
         $customers[] = $customer;
     }
     $this->customerFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($customerFactoryMap);
     $this->assertSame($customers, $this->customerService->loadCustomers($filters));
 }
 /**
  * @param array $filters
  * @param array $itemsData
  * @dataProvider loadProfilesDataProvider
  */
 public function testLoadProfiles($filters, $itemsData)
 {
     $this->httpClientMock->expects($this->once())->method('get')->with('/services/v1/vault/paymentprofiles.json', $filters)->willReturn([PaymentProfileService::API_NAME_PROFILES => $itemsData]);
     $profiles = [];
     $paymentProfileFactoryMap = [];
     foreach ($itemsData as $itemData) {
         $paymentProfile = $this->createProfileMock();
         $paymentProfileFactoryMap[] = [$itemData, $paymentProfile];
         $profiles[] = $paymentProfile;
     }
     $this->paymentProfileFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($paymentProfileFactoryMap);
     $this->assertSame($profiles, $this->paymentProfileService->loadProfiles($filters));
 }
 /**
  * @param int $customerId
  * @param array $filters
  * @param array $itemsData
  * @dataProvider loadAddressesDataProvider
  */
 public function testLoadAddresses($customerId, $filters, $itemsData)
 {
     $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/addresses.json', $filters)->willReturn([AddressService::API_NAME_ADDRESSES => $itemsData]);
     $addresses = [];
     $addressFactoryMap = [];
     foreach ($itemsData as $itemData) {
         $address = $this->createAddressMock();
         $addressFactoryMap[] = [$itemData, $address];
         $addresses[] = $address;
     }
     $this->addressFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($addressFactoryMap);
     $this->assertSame($addresses, $this->addressService->loadAddresses($customerId));
 }
 /**
  * @param int $customerId
  * @param array $filters
  * @param array $itemsData
  * @dataProvider loadSubscriptionsDataProvider
  */
 public function testLoadSubscriptions($customerId, $filters, $itemsData)
 {
     $this->httpClientMock->expects($this->once())->method('get')->with('/services/v2/subscriptions.json', $filters)->willReturn([SubscriptionService::API_NAME_SUBSCRIPTIONS => $itemsData]);
     $subscriptions = [];
     $subscriptionFactoryMap = [];
     foreach ($itemsData as $itemData) {
         $subscription = $this->createSubscriptionMock();
         $subscriptionFactoryMap[] = [$itemData, $subscription];
         $subscriptions[] = $subscription;
     }
     $this->subscriptionFactoryMock->expects($this->exactly(count($itemsData)))->method('create')->willReturnMap($subscriptionFactoryMap);
     $this->assertSame($subscriptions, $this->subscriptionService->loadSubscriptions($customerId));
 }
 /**
  * @param array $data
  * @return \SubscribePro\Service\Webhook\Event\DestinationInterface[]
  */
 protected function createDestinationItems(array $data = [])
 {
     return array_map(function ($itemData) {
         return $this->destinationFactory->create($itemData);
     }, $data);
 }
 /**
  * @param array $data
  * @return \SubscribePro\Service\PaymentProfile\PaymentProfileInterface
  */
 public function create(array $data = [])
 {
     $addressData = $this->getFieldData($data, PaymentProfileInterface::BILLING_ADDRESS);
     $data[PaymentProfileInterface::BILLING_ADDRESS] = $this->addressFactory->create($addressData);
     return new $this->instanceName($data);
 }
 /**
  * @param array $data
  * @return \SubscribePro\Service\DataInterface[]
  */
 private function createItems(array $data = [])
 {
     return array_map(function ($itemData) {
         return $this->dataFactory->create($itemData);
     }, $data);
 }