public function preparePayment() {
    if ($this->validate()) {
      $trans = array();

      foreach ($this->fieldsJSON as $fieldName) {
        if (is_array($this->{$fieldName}) || !C2PValidate::isEmpty($this->{$fieldName})) {
          $trans[$fieldName] = $this->{"get" . ucfirst($fieldName)}();
        }
      }

      // Only PHP >= 5.4 has JSON_UNESCAPED_SLASHES option
      $post_data = str_replace('\\/', '/', json_encode($trans));
      $url = $this->url . Connect2PayClient::$API_ROUTES['TRANS_PREPARE'];

      $result = $this->doPost($url, $post_data);

      if ($result != null && is_array($result)) {
        $this->returnCode = $result['code'];
        $this->returnMessage = $result['message'];

        if ($this->returnCode == "200") {
          $this->merchantToken = $result['merchantToken'];
          $this->customerToken = $result['customerToken'];

          return true;
        } else {
          $this->clientErrorMessage = $this->returnMessage;
        }
      }
    }

    return false;
  }
public function preparePayment() {
    if ($this->validate()) {
      $trans = array();

      foreach ($this->fieldsJSON as $fieldName) {
        if (is_array($this->{$fieldName}) || !C2PValidate::isEmpty($this->{$fieldName})) {
          $trans[$fieldName] = $this->{"get" . ucfirst($fieldName)}();
        }
      }

      // Only PHP >= 5.4 has JSON_UNESCAPED_SLASHES option
      $post_data = str_replace('\\/', '/', json_encode($trans));
      $url = $this->url . Connect2PayClient::$API_ROUTES['TRANS_PREPARE'];

      $result = $this->doPost($url, $post_data);

      if ($result != null && is_array($result)) {
        $this->returnCode = $result['code'];
        $this->returnMessage = $result['message'];

        if ($this->returnCode == "200") {
          $this->merchantToken = $result['merchantToken'];
          $this->customerToken = $result['customerToken'];

          return true;
        } else {
          $this->clientErrorMessage = $this->returnMessage;
        }
      }
    }

    return false;
  }
public function preparePayment ( ) { if ( $ this -> validate ( ) ) { $ trans = array ( ) ; foreach ( $ this -> fieldsJSON as $ fieldName ) { if ( is_array ( $ this -> { $ fieldName } ) || ! C2PValidate :: isEmpty ( $ this -> { $ fieldName } ) ) { $ trans [ $ fieldName ] = $ this -> { "get" . ucfirst ( $ fieldName ) } ( ) ; } } // Only PHP >= 5.4 has JSON_UNESCAPED_SLASHES option $ post_data = str_replace ( '\\/' , '/' , json_encode ( $ trans ) ) ; $ url = $ this -> url . Connect2PayClient :: $ API_ROUTES [ 'TRANS_PREPARE' ] ; $ result = $ this -> doPost ( $ url , $ post_data ) ; if ( $ result != null && is_array ( $ result ) ) { $ this -> returnCode = $ result [ 'code' ] ; $ this -> returnMessage = $ result [ 'message' ] ; if ( $ this -> returnCode == "200" ) { $ this -> merchantToken = $ result [ 'merchantToken' ] ; $ this -> customerToken = $ result [ 'customerToken' ] ; return true ; } else { $ this -> clientErrorMessage = $ this -> returnMessage ; } } } return false ; }
Prepare a new payment on the payment page application.
This method will validate the payment data and call
the payment page application to create a new payment.
The fields returnCode, returnMessage, merchantToken and
customerToken will be populated according to the call result.

@return boolean true if creation is successful, false otherwise
Prepare a new payment on the payment page application . This method will validate the payment data and call the payment page application to create a new payment . The fields returnCode returnMessage merchantToken and customerToken will be populated according to the call result .