<commit_before>'use strict';
var Promise = require('promise');
var apiKey;
var secret;
var payment;
var consumer;
var delivery;
var payment;
var callbacks;

module.exports = function PayapiClient(params) {
  this.apiKey = params.apiKey;
  this.secret = params.secret;
  this.payment = params.payment;
  this.consumer = params.consumer;
  this.delivery = params.delivery;
  this.payment = params.payment;
  this.callbacks = params.callbacks;

  function validateApiKey(err) {
    return new Promise(function(resolve, reject) {
      if(!apiKey) {
        reject('apiKey must not be empty');
      }
    });
  }

  function validateSecret(err) {
    return new Promise(function(resolve, reject) {
      if(!secret) {
        reject('secret must not be empty');
      }
    });
  }

  function validatePayment(err) {
    return new Promise(function(resolve, reject) {
      if(!secret) {
        reject('secret must not be empty');
      }
    });
  }

  function handleError(err) {
    return new Promise(function(resolve, reject) {
      reject(err);
    });
  }

  return {
    call: function() {
      return validateApiKey(params)
        .then(validateSecret)
        .then(validatePayment)
        .then(validateConsumer)
        .then(validateDelivery)
        .then(validatePayment)
        .then(createToken)
        .then(doRestCall)
        .catch(handleError);
    }
  };
};<commit_msg>Generation of payment token done<commit_after>'use strict';
var jwt = require('jwt-simple');
var Promise = require('promise');
var apiKey;
var secret;
var payment;
var consumer;
var delivery;
var payment;
var callbacks;
var paymentToken;
var authenticationToken;

module.exports = function PayapiClient(params) {

  function print(key, value) {
    console.log(key + ':' + JSON.stringify(value, null, 2));
  }

  this.apiKey = params.apiKey;
  this.secret = params.secret;
  this.payment = params.payment;
  this.consumer = params.consumer;
  this.delivery = params.delivery;
  this.payment = params.payment;
  this.products = params.products;
  this.callbacks = params.callbacks;
  this.authenticationToken = params.authenticationToken;
  this.paymentToken = params.paymentToken;

  function validateApiKey(params) {
    return new Promise(function(resolve, reject) {
      if(!apiKey) {
        reject('apiKey must not be empty');
      }
      resolve(params);
    });
  }

  function validateSecret(params) {
    return new Promise(function(resolve, reject) {
      if(!secret) {
        reject('secret must not be empty');
      }
      resolve(params);
    });
  }

  function validatePayment(params) {
    return new Promise(function(resolve, reject) {
      if(!payment) {
        reject('payment must not be empty');
      }
      resolve(params);
    });
  }

  function validateConsumer(params) {
    return new Promise(function(resolve, reject) {
      if(!consumer) {
        reject('consumer must not be empty');
      }
      resolve(params);
    });
  }

  function validateDelivery(params) {
    return new Promise(function(resolve, reject) {
      if(!delivery) {
        reject('delivery must not be empty');
      }
      resolve(params);
    });
  }

  function validatePayment(params) {
    return new Promise(function(resolve, reject) {
      if(!payment) {
        reject('payment must not be empty');
      }
      resolve(params);
    });
  }

  function validateOrCreateToken(params) {
    return new Promise(function(resolve, reject) {
      if(!params.paymentToken) {
        var payload = {
          payment: params.payment,
          consumer: params.consumer,
          delivery: params.delivery,
          products: params.products,
          payment: params.payment,
          callbacks: params.callbacks
        }
        params.paymentToken = jwt.encode(payload, params.secret, 'HS512');
      }
      resolve(params);
    });
  }

  function doRestCall(params) {
    return new Promise(function(resolve, reject) {
      resolve(params);
    });
  }

  function handleError(err) {
    return new Promise(function(resolve, reject) {
      reject(err);
    });
  }

  return {
    call: function(token) {
      if(token) {
        var params = {paymentToken: token};
        return validateOrCreateToken(params)
          .then(doRestCall)
          .catch(handleError);
      } else {
        return validateApiKey(params)
          .then(validateSecret)
          .then(validatePayment)
          .then(validateConsumer)
          .then(validateDelivery)
          .then(validatePayment)
          .then(validateOrCreateToken)
          .then(doRestCall)
          .catch(handleError);
      }
    },
    paymentToken: function() {
      return validateOrCreateToken(params)
        .then(function(params) {
          return new Promise(function(resolve, reject) {
            resolve(params.paymentToken);
          });
        })
        .catch(function(err) {
          throw err;
        });
    }
  };
};
{'fraction_non_alphanumeric': 0.1187778227438284, 'fraction_numerical': 0.0008093889113719142, 'mean_word_length': 2.5818840579710143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1574849', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1409, 'n_words': 306}