/*
* ProxyPay API Wrapper
* https://flowck.github.io/proxypay-api
*
* Licensed MIT @ Firmino Changani
*/

// Enable strict mode
"use strict";

// Import dependencies
const request = require("request");
const hasha = require("hasha");

// ProxyPay constructor
function ProxyPay(config){
	this.config = {
		host: "https://api.proxypay.co.ao",
		apikey: new Buffer("api:" + config.apikey).toString("base64")
	}
}

/*
* Method name: Generate.
* Description: It generates a new reference.
* params: data - An object containing all information needed to generate a new reference.
*/
ProxyPay.prototype.GenerateReference = function(data){
	
	var that = this;

	return new Promise(function(resolve, reject){
		request({
			uri:  that.config.host + "/references",
			method: "POST",
			headers: {
				"Content-Type": "application/json",
				"authorization": "Basic " + that.config.apikey
			},
			body: data,
			json: true
		}, function(err, response, body){

			if(err){
				reject(err);
			}

			resolve(body);
			
		});
	});

}

/*
* Method name: GetAll.
* Description: This method returns all references.
* params: N / A
*/
ProxyPay.prototype.GetAllReferences = function(){
	
	var that = this;

	return new Promise(function(reject, resolve){
		request({
			uri:  that.config.host + "/references",
			method: "GET",
			headers: {
				"Content-Type": "application/json",
				"authorization": "Basic " + that.config.apikey
			},
			json: true
		}, function(err, response, body){

			if(err){
				reject(err);
			}

			resolve(body);
			
		});
	});


}

/*
* Method name: GetAll.
* Description: This method returns and object with the specified reference.
* params: id - A string
*/
ProxyPay.prototype.GetOneReference = function(id){
	
	var that = this;

	return new Promise(function(reject, resolve){
		request({
			uri:  that.config.host + "/references/" + id,
			method: "GET",
			headers: {
				"Content-Type": "application/json",
				"authorization": "Basic " + that.config.apikey
			},
			json: true
		}, function(err, response, body){

			if(err){
				reject(err);
			}

			resolve(body);
			
		});
	});

}

/*
* Method name: GetPayments.
* Description: This method returns and object with all payments made.
* params: N / A
*/
ProxyPay.prototype.GetPayments = function(){

	var that = this;

	return new Promise(function(reject, resolve){
		request({
			uri:  that.config.host + "/payments",
			method: "GET",
			headers: {
				"Content-Type": "application/json",
				"authorization": "Basic " + that.config.apikey
			},
			json: true
		}, function(err, response, body){

			if(err){
				reject(err);
			}

			resolve(body);
			
		});
	});	
}



// Export the constructor
module.exports = ProxyPay;
@@ -2636,16 +2636,611 @@
 %7D);%09%0A%7D%0A%0A
+/*%0A* Method name: Acknowledge Payment.%0A* Description: This method acknowledges that a specific payment has been processed..%0A* params: paymentid%0A*/%0AProxyPay.prototype.AcknowledgePayment = function(paymentid)%7B%0A%0A%09var that = this;%0A%0A%09return new Promise(function(reject, resolve)%7B%0A%09%09request(%7B%0A%09%09%09uri:  that.config.host + %22/payments/%22 + paymentid,%0A%09%09%09method: %22DELETE%22,%0A%09%09%09headers: %7B%0A%09%09%09%09%22Content-Type%22: %22application/json%22,%0A%09%09%09%09%22authorization%22: %22Basic %22 + that.config.apikey%0A%09%09%09%7D,%0A%09%09%09json: true%0A%09%09%7D, function(err, response, body)%7B%0A%0A%09%09%09if(err)%7B%0A%09%09%09%09reject(err);%0A%09%09%09%7D%0A%0A%09%09%09resolve(body);%0A%09%09%09%0A%09%09%7D);%0A%09%7D);%09%0A%7D%0A
 %0A%0A// Exp

Add a new methodto Acknowledge payments