Function to perform Adaptive Payments API's PAY operation.

@param array $data

@throws \Exception

@return array
339716
public function createPayRequest($data)
    {
        if (empty($data['return_url']) && empty($data['cancel_url'])) {
            throw new \Exception('Return & Cancel URL should be specified');
        }

        $this->setPayRequestDetails($data);

        return $this->doPayPalRequest('Pay');
    }
40085
public function update(array $data)
    {
        $project_id = (int) (empty($data['project_id']) ? 0: $data['project_id']);
        $person_id = (int) (empty($data['person_id']) ? 0: $data['person_id']);
        if ($project_id <= 0) {
            throw new Exception("Required field project_id");
        }
        if ($person_id <= 0) {
            throw new Exception("Required field person_id");
        }
        return $this->rest->put("projects/$project_id/people/$person_id", $data);
    }
954116
protected function UFCreate(array $data)
    {
        $return = [];
        global $USER_FIELD_MANAGER;
        if (empty($data['FIELD_NAME'])) {
            throw new Exception('You must set group FIELD_NAME');
        }
        if (empty($data['ENTITY_ID'])) {
            throw new Exception('You must set group ENTITY_ID');
        }
        if ($this->UFGetIdByCode($data['ENTITY_ID'], $data['FIELD_NAME'])) {
            throw new Exception('UF with code ' . $data['FIELD_NAME'] . ' already exists');
        }
        $ib = new CUserTypeEntity();
        $id = $ib->Add(array_merge(['USER_TYPE_ID' => 'string'], $data));
        if ($id) {
            $return[] = "Add {$data['FIELD_NAME']} user field";
            if (
                !empty($data['LIST'])
                && ($arType = $USER_FIELD_MANAGER->GetUserType($data['USER_TYPE_ID']))
                && $arType['BASE_TYPE'] == 'enum'
            ) {
                $obEnum = new CUserFieldEnum();
                $res = $obEnum->SetEnumValues($id, $data['LIST']);
                $return[] = "Add {$data['FIELD_NAME']} user field list";
            }
        } else {
            throw new Exception("Can't create {$data['FIELD_NAME']} user field");
        }

        return $return;
    }
424651
public function factoryFromArray(array $data, $type = null)
    {
        if ($type === null) {
            if (array_key_exists('type', $data)) {
                $type = $data['type'];
                unset($data['type']);
            } else {
                throw new \InvalidArgumentException(
                    'Parameter type not specified in PaymentDataFactory.factoryFromArray()'
                );
            }
        }

        $paymentData = $this->factory($type);
        $this->fillModel($paymentData, $data);

        return $paymentData;
    }
1035062
public static function createFromData(array $data)
    {
        if (!isset($data['type'])) {
            throw new DomainException(self::MSG_REQUIRED_TYPE);
        }

        switch ($data['type']) {
            case self::TYPE_DISCOUNTS_PER_REDEMPTION:
                $restriction = new Restrictions\DiscountsPerRedemption($data);

                break;
            case self::TYPE_REDEMPTIONS_PER_CUSTOMER:
                $restriction = new Restrictions\RedemptionsPerCustomer($data);

                break;
            case self::TYPE_RESTRICT_TO_INVOICES:
                $restriction = new Restrictions\RestrictToInvoices($data);

                break;
            case self::TYPE_RESTRICT_TO_PLANS:
                $restriction = new Restrictions\RestrictToPlans($data);

                break;
            case self::TYPE_RESTRICT_TO_SUBSCRIPTIONS:
                $restriction = new Restrictions\RestrictToSubscriptions($data);

                break;
            case self::TYPE_TOTAL_REDEMPTIONS:
                $restriction = new Restrictions\TotalRedemptions($data);

                break;
            case self::TYPE_MINIMUM_ORDER_AMOUNT:
                $restriction = new Restrictions\MinimumOrderAmount($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::MSG_UNSUPPORTED_TYPE, implode(',', self::$supportedTypes))
                );
        }

        return $restriction;
    }
777306
private function createPaymillMethod(array $data)
    {
        $paymentMethod = new PaymillMethod();
        $paymentMethod
            ->setApiToken($data['api_token'])
            ->setCreditCardNumber($data['credit_card_1'] . $data['credit_card_2'] . $data['credit_card_3'] . $data['credit_card_4'])
            ->setCreditCardOwner($data['credit_card_owner'])
            ->setCreditCardExpirationMonth($data['credit_card_expiration_month'])
            ->setCreditCardExpirationYear($data['credit_card_expiration_year'])
            ->setCreditCardSecurity($data['credit_card_security']);

        return $paymentMethod;
    }
233372
public function doWebPayment(array $array) 
    {
        $this->formatRequest($array);
        $WSRequest = array(
            'payment'                    => $this->payment($array['payment']),
            'returnURL'                  => $array['returnURL'],
            'cancelURL'                  => $array['cancelURL'],
            'order'                      => $this->order($array['order']),
            'notificationURL'            => $array['notificationURL'],
            'customPaymentTemplateURL'   => $array['customPaymentTemplateURL'],
            'selectedContractList'       => $array['contracts'],
            'secondSelectedContractList' => $array['secondContracts'],
            'privateDataList'            => $this->privateData,
            'languageCode'               => $array['languageCode'],
            'customPaymentPageCode'      => $array['customPaymentPageCode'],
            'buyer'                      => $this->buyer($array['buyer'], $array['shippingAddress'], $array['billingAddress']),
            'owner'                      => $this->owner($array['owner'], $array['ownerAddress']),
            'securityMode'               => $array['securityMode'],
            'contractNumberWalletList'   => $array['walletContracts'],
            'merchantName'               => $array['merchantName'],
            'subMerchant'                => $this->subMerchant($array['subMerchant']),
            'miscData'                   => $array['miscData'],
            'asynchronousRetryTimeout'   => $array['asynchronousRetryTimeout']
        );

        if (isset($array['payment']['mode'])) {
            if (($array['payment']['mode'] == "REC") || ($array['payment']['mode'] == "NX")) {
                $WSRequest['recurring'] = $this->recurring($array['recurring']);
            }
        }
        return $this->webServiceRequest($array, $WSRequest, self::WEB_API, 'doWebPayment');
    }
468428
protected function HLUpdate(array $data)
    {
        $return = [];
        if (empty($data['NAME'])) {
            throw new Exception('You must set NAME');
        }
        if ($id = $this->HLGetIdByCode($data['NAME'])) {
            $arLoad = $data;
            unset($arLoad['LANGS'], $arLoad['RIGHTS'], $arLoad['NAME']);
            if ($arLoad) {
                $result = HighloadBlockTable::update($id, $arLoad);
                if ($result->isSuccess()) {
                    if (!empty($data['LANGS'])) {
                        $this->HLSetLangs($id, $data['LANGS']);
                    }
                    if (!empty($data['RIGHTS'])) {
                        $this->HLSetRights($id, $data['RIGHTS']);
                    }
                    $return[] = "Update {$data['NAME']} ({$id}) highload block";
                } else {
                    throw new Exception("Can't update {$data['NAME']} ({$id}) highload block: " . implode(', ', $result->getErrorMessages()));
                }
            } elseif (!empty($data['RIGHTS'])) {
                $this->HLSetRights($id, $data['RIGHTS']);
            } elseif (!empty($data['LANGS'])) {
                $this->HLSetLangs($id, $data['LANGS']);
            }
        } else {
            throw new Exception("Hl entity with name {$data['NAME']} does not exist");
        }

        return $return;
    }
1101414
protected function transform($data)
    {
        if (!$data instanceof GetSchema\Schema) {
            throw new Exception('Schema instance missing.');
        }

        $field = $this->specializedFIelds[0];
        $returnData = [];

        foreach ($data->getTableDefinitions() as $definition) {
            $returnData[] = [
                $field => $definition->getName(),
                0 => $definition->getName(),
            ];
        }

        return $returnData;
    }
303591
public function create($data)
    {
        $res = $this->request(self::PAYMENTS_PATH)->setRequestBody($data)->post();

        if ($res->isError()) {
            throw new RequestError($res->errorMessage, null, $res);
        }

        return new Payment($res->json);
    }
134274
private function setPayRequestDetails($data)
    {
        $this->post = $this->setRequestData([
            'actionType'   => 'PAY',
            'currencyCode' => $this->currency,
            'receiverList' => [
                'receiver' => $data['receivers'],
            ],
            'returnUrl'       => $data['return_url'],
            'cancelUrl'       => $data['cancel_url'],
            'requestEnvelope' => $this->setEnvelope(),
            'feesPayer'       => $data['payer'],
        ])->filter(function ($value, $key) {
            return (($key === 'feesPayer') && empty($value)) ? null : $value;
        });
    }
67588
public function updateFromApiResponse(array $data): OrderInterface
    {
        $order = $this->orderRepository->findOneByExternalId($data['id']);
        if (!$order) {
            $order = new Order();
        }

        // we start by syncing the currency, since we use the currency to create Money objects
        $currency = $this->currencyRepository->findOneByCode($data['currencyCode']);
        if (!$currency) {
            $currency = $this->currencySynchronizer->syncOne([
                'code' => $data['currencyCode'],
            ]);

            // this means that the currency does not exist anymore
            // @todo create placeholder
            if (!$currency) {
                throw new \RuntimeException('Could not sync currency `'.$data['currencyCode'].'`. Try again');
            }
        }

        $currencyCode = $currency->getIsoCodeAlpha();

        // set shortcuts for embedded objects
        $orderLinesData = $data['orderLines'] ?? [];
        $paymentData = $data['paymentInfo'] ?? [];
        $shippingData = $data['shippingInfo'] ?? [];

        $createdDate = DateTimeImmutable::createFromJson($data['createdDate']);
        $modifiedDate = $data['modifiedDate'] ? DateTimeImmutable::createFromJson($data['modifiedDate']) : null;

        $giftCertificateAmount = DandomainFoundation\createMoneyFromFloat($currencyCode, $data['giftCertificateAmount']);
        $totalPrice = DandomainFoundation\createMoneyFromFloat($currencyCode, $data['totalPrice']);
        $salesDiscount = DandomainFoundation\createMoneyFromFloat($currencyCode, $data['salesDiscount']);
        $paymentMethodFee = DandomainFoundation\createMoneyFromFloat($currencyCode, $paymentData['fee'] ?? 0.0);
        $shippingMethodFee = DandomainFoundation\createMoneyFromFloat($currencyCode, $shippingData['fee'] ?? 0.0);

        $order
            ->setExternalId($data['id'])
            ->setCurrency($currency)
            ->setComment($data['comment'])
            ->setCreatedDate($createdDate)
            ->setCustomerComment($data['customerComment'])
            ->setGiftCertificateAmount($giftCertificateAmount)
            ->setGiftCertificateNumber($data['giftCertificateNumber'])
            ->setIncomplete($data['incomplete'])
            ->setIp($data['ip'])
            ->setModified($data['modified'])
            ->setModifiedDate($modifiedDate)
            ->setReferenceNumber($data['referenceNumber'])
            ->setReferrer($data['referrer'])
            ->setReservedField1($data['reservedField1'])
            ->setReservedField2($data['reservedField2'])
            ->setReservedField3($data['reservedField3'])
            ->setReservedField4($data['reservedField4'])
            ->setReservedField5($data['reservedField5'])
            ->setSalesDiscount($salesDiscount)
            ->setTotalPrice($totalPrice)
            ->setTotalWeight($data['totalWeight'])
            ->setTrackingNumber($data['trackingNumber'])
            ->setTransactionNumber($data['transactionNumber'])
            ->setVatPct((float) $data['vatPct'])
            ->setVatRegNumber($data['vatRegNumber'])
            ->setXmlParams($data['xmlParams'])
            ->setShippingMethodFee($shippingMethodFee)
            ->setPaymentMethodFee($paymentMethodFee)
        ;

        // populate customer info
        $customer = $this->customerUpdater->updateFromEmbeddedApiResponse($data['customerInfo']);
        $order->setCustomer($customer);

        // populate delivery info
        $delivery = $this->deliveryUpdater->updateFromEmbeddedApiResponse($data['deliveryInfo'], $order->getDelivery());
        $order->setDelivery($delivery);

        // populate invoice info
        $invoice = $this->invoiceUpdater->updateFromEmbeddedApiResponse($data['invoiceInfo'], $order->getInvoice());
        $order->setInvoice($invoice);

        // populate payment info
        $paymentMethod = $this->paymentMethodUpdater->updateFromEmbeddedApiResponse($data['paymentInfo'], $currencyCode, $order->getPaymentMethod());
        $order->setPaymentMethod($paymentMethod);

        // populate shipping info
        $shippingMethod = $this->shippingMethodUpdater->updateFromEmbeddedApiResponse($data['shippingInfo'], $currencyCode, $order->getShippingMethod());
        $order->setShippingMethod($shippingMethod);

        // populate site
        $site = $this->siteRepository->findOneByExternalId($data['siteId']);
        if (!$site) {
            $site = $this->siteSynchronizer->syncOne([
                'externalId' => $data['siteId'],
            ]);

            // this means that the site does not exist anymore so we create a placeholder
            if (!$site) {
                $site = new Site();
                $site->setExternalId($data['siteId'])
                    ->setName((string) $data['siteId'])
                    ->setCurrency($currency)
                ;

                // we soft delete the site because it does not exist anymore
                $site->delete();

                $this->siteRepository->save($site);
            }
        }
        $order->setSite($site);

        // populate state
        $state = $this->stateRepository->findOneByExternalId($data['orderState']['id']);
        if(!$state) {
            $state = $this->stateSynchronizer->syncOne([
                'externalId' => $data['orderState']['id']
            ]);

            if(!$state) {
                // @todo create placeholder
                throw new \InvalidArgumentException('The order state `'.$data['orderState']['name'].'` (id: '.$data['orderState']['id'].') does not exist');
            }
        }
        $order->setState($state);

        if (count($orderLinesData)) {
            // first remove order lines that are not present anymore
            $removeOrderLines = [];
            foreach ($order->getOrderLines() as $orderLineEntity) {
                $found = false;
                foreach ($orderLinesData as $orderLineData) {
                    if ($orderLineData['id'] === $orderLineEntity->getExternalId()) {
                        $found = true;
                    }
                }

                if (!$found) {
                    $removeOrderLines[] = $orderLineEntity;
                }
            }

            foreach ($removeOrderLines as $removeOrderLine) {
                $order->removeOrderLine($removeOrderLine);
            }

            // then update the rest of the order lines
            foreach ($orderLinesData as $orderLineData) {
                if (!$orderLineData['id']) {
                    continue;
                }

                $collection = $order
                    ->getOrderLines()
                    ->matching(
                        Criteria::create()->where(Criteria::expr()->eq('externalId', $orderLineData['id']))
                    );

                if ($collection->count()) {
                    $orderLineEntity = $collection->first();
                } else {
                    $orderLineEntity = new OrderLine();
                    $order->addOrderLine($orderLineEntity);
                }

                $orderLineUnitPrice = DandomainFoundation\createMoneyFromFloat($currencyCode, $orderLineData['unitPrice'] ?? 0.0);
                $orderLineTotalPrice = DandomainFoundation\createMoneyFromFloat($currencyCode, $orderLineData['totalPrice'] ?? 0.0);

                $orderLineEntity
                    ->setExternalId((int) $orderLineData['id'])
                    ->setFileUrl($orderLineData['fileUrl'])
                    ->setProductNumber($orderLineData['productId'])
                    ->setProductName($orderLineData['productName'])
                    ->setQuantity((int) $orderLineData['quantity'])
                    ->setTotalPrice($orderLineTotalPrice)
                    ->setUnitPrice($orderLineUnitPrice)
                    ->setVatPct((float) $orderLineData['vatPct'])
                    ->setVariant($orderLineData['variant'])
                    ->setXmlParams($orderLineData['xmlParams'])
                ;

                $product = $this->getProductFromOrderLine($orderLineEntity);
                if ($product) {
                    $orderLineEntity->setProduct($product);
                }
            }
        } else {
            $order->clearOrderLines();
        }

        return $order;
    }
798694
public function createPaymentForm(array $data)
    {
        $this->ensureApiIsConfigured();

        try {
            $data = $this
                ->getRequestOptionsResolver()
                ->resolve($data);
        } catch (ExceptionInterface $e) {
            throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
        }

        $fields = [
            'TPE'         => $this->config['tpe'],
            'date'        => $data['date'],
            'montant'     => $data['amount'] . $data['currency'],
            'reference'   => $data['reference'],
            'texte-libre' => $data['comment'],
            'version'     => static::VERSION,
            'lgue'        => $data['locale'],
            'societe'     => $this->config['company'],
            'mail'        => $data['email'],
        ];

        $macData = array_values($fields);

        $fields['texte-libre'] = $this->htmlEncode($data['comment']);

        if (!empty($data['schedule'])) {
            $macData[] = $fields['nbrech'] = count($data['schedule']);

            $count = 0;
            foreach ($data['schedule'] as $datum) {
                $count++;
                $macData[] = $fields['dateech' . $count] = $datum['date'];
                $macData[] = $fields['montantech' . $count] = $datum['amount'] . $data['currency'];
            }

            // Fills empty schedule
            for ($i = 2 * $count + 10; $i < 18; $i++) {
                $macData[] = null;
            }

            $options = [];
            foreach ($data['options'] as $key => $value) {
                $options = "$key=$value";
            }
            $macData[] = $fields['options'] = implode('&', $options);
        }

        $fields['MAC'] = $this->computeMac($macData);

        $fields['url_retour'] = $data['return_url'];
        $fields['url_retour_ok'] = $data['success_url'];
        $fields['url_retour_err'] = $data['failure_url'];

        return [
            'action' => $this->getEndpointUrl(static::TYPE_PAYMENT),
            'method' => 'POST',
            'fields' => $fields,
        ];
    }
1123608
public function doRecurrentWalletPayment(array $array)
    {
        $this->formatRequest($array);
        $WSRequest = array(
            'payment'         => $this->payment($array['payment']),
            'orderRef'        => $array['orderRef'],
            'orderDate'       => $array['orderDate'],
            'scheduledDate'   => $array['scheduledDate'],
            'walletId'        => $array['walletId'],
            'cardInd'         => $array['cardInd'],
            'recurring'       => $this->recurring($array['recurring']),
            'privateDataList' => $this->privateData,
            'order'           => $this->order($array['order'])
        );
        return $this->webServiceRequest($array, $WSRequest, self::DIRECT_API, 'doRecurrentWalletPayment');
    }
354593
public function postDocument(array $data)
    {
        $path = '/'.$this->databaseName;
        $response = $this->httpClient->request('POST', $path, json_encode($data));

        if ($response->status != 201) {
            throw HTTPException::fromResponse($path, $response);
        }

        return [$response->body['id'], $response->body['rev']];
    }
1225758
public function parseData(array $data) : array
    {
        if ($this->getTransformer() instanceof RequestTransformerContract) {
            return $this->getTransformer()->transformRequestData($data);
        }

        return $data;
    }
710861
public function setCard(?array $data): PaymentInstrumentInterface
    {
        $this->setLast4Digits($data['last_4_digits']);
        $this->setCardType($data['type']);

        return $this;
    }