/**
  * WARNING, this class is only used for testing purposes. No card information should be sent to the server directly
  * as it will represent a serious security concern. Do not use this function in a production environment unless you
  * know very well what you are doing
  *
  * @param array $parameters
  * @return array
  * @throws \Openpay\Client\Exception\OpenpayException
  */
 public function store(array $parameters)
 {
     /* TODO validate parameters to be compatible */
     // https://sandbox-api.openpay.mx/v1/mzdtln0bmtms6o3kck8f/tokens
     $relativeUrl = $this->merchantId . '/' . self::TOKENS_ENDPOINT;
     $options = $this->options;
     $options['json'] = $parameters;
     $response = $this->callOpenpayClient($relativeUrl, $options, self::POST_METHOD);
     $card = $this->cardMapper->create($response['card']);
     $token = ['token_id' => $response['id'], 'card' => $card];
     return $token;
 }
 /**
  * @param OpenpayTransactionType $object
  * @param array $data
  * @return OpenpayTransactionType
  */
 public function populate(OpenpayTransactionType $object, array $data)
 {
     if (isset($data['id'])) {
         $object->setId($data['id']);
     }
     if (isset($data['authorization'])) {
         $object->setAuthorization($data['authorization']);
     }
     if (isset($data['transaction_type'])) {
         $object->setTransactionType($data['transaction_type']);
     }
     if (isset($data['operation_type'])) {
         $object->setOperationType($data['operation_type']);
     }
     if (isset($data['method'])) {
         $object->setMethod($data['method']);
     }
     if (isset($data['creation_date'])) {
         $object->setCreationDate(\DateTime::createFromFormat('Y-m-d*H:i:sO', $data['creation_date']));
     }
     if (isset($data['order_id'])) {
         $object->setOrderId($data['order_id']);
     }
     if (isset($data['status'])) {
         $object->setStatus($data['status']);
     }
     if (isset($data['amount'])) {
         $object->setAmount($data['amount']);
     }
     if (isset($data['description'])) {
         $object->setDescription($data['description']);
     }
     if (isset($data['error_message'])) {
         $object->setErrorMessage($data['error_message']);
     }
     if (isset($data['customer_id'])) {
         $object->setCustomerId($data['customer_id']);
     }
     if (isset($data['currency'])) {
         $object->setCurrency($data['currency']);
     }
     if (isset($data['bank_account'])) {
         $object->setBankAccount($this->bankAccountMapper->create($data['bank_account']));
     }
     if (isset($data['card'])) {
         $object->setCard($this->cardMapper->create($data['card']));
     }
     if (isset($data['card_points'])) {
         $object->setCardPoints($data['card_points']);
     }
     return $object;
 }
 /**
  * @param $customerId
  * @param array $parameters
  * @return \Openpay\Client\Type\OpenpayCardType
  * @throws OpenpayException
  */
 public function store($customerId, array $parameters)
 {
     $validator = new OpenpayCardTokenValidator();
     $violations = $validator->validate($parameters);
     if ($violations->count() > 0) {
         throw new OpenpayException($violations->__toString(), 400);
     }
     // POST https://sandbox-api.openpay.mx/v1/{MERCHANT_ID}/customers/{CUSTOMER_ID}/cards
     $relativeUrl = $this->merchantId . '/' . self::CUSTOMERS_ENDPOINT . '/' . $customerId . '/' . self::CARDS_ENDPOINT;
     $options = $this->options;
     $body = ['token_id' => $parameters['token_id'], 'device_session_id' => isset($parameters['device_session_id']) ? $parameters['device_session_id'] : null];
     $options['json'] = $body;
     $response = $this->callOpenpayClient($relativeUrl, $options, self::POST_METHOD);
     $card = $this->cardMapper->create($response);
     return $card;
 }