@ballin-team/paysync-nubank
Version:
<h1 align="center"> <img src="https://docs.nupaybusiness.com.br/images/logotipo.png" alt="NuPay for Business" /> </h1>
152 lines (151 loc) • 7.38 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NubankPaymentClient = void 0;
const helpers_1 = require("./helpers");
const nubank_apiRequest_1 = require("./nubank.apiRequest");
class NubankPaymentClient extends nubank_apiRequest_1.NubankApiRequest {
/**
* This method returns available payment methods configured for the merchant and the information each method requires on payment creation.
*
* For NuPay integration, we recommend to use the AppLink returned by Payment Creation response.
* For Pix integration, we return the schema to obtain the QR Code and the QR Code Content.
* The groups field separates different payment methods into categories.
*
* [Details](https://docs.nupaybusiness.com.br/en/checkout/merchants/openapi/#tag/Checkout/operation/PaymentMethodsGet)
*/
getPaymentMethods() {
return __awaiter(this, void 0, void 0, function* () {
const path = '/checkouts/payment-methods';
try {
const response = yield this.api.get(path);
const { data } = response;
const isAuthentic = yield this.isAuthenticMessage(response);
if (!isAuthentic)
throw new helpers_1.NubankApiError({ path, data, isAuthentic });
return data;
}
catch (e) {
throw new helpers_1.NubankApiError({ path, data: e });
}
});
}
/**
* This method creates a new payment request, and it's the same method for creating either Pix or NuPay payments, the difference is in the data sent on the request. Check our request samples for more information.
*
* [Details](https://docs.nupaybusiness.com.br/en/checkout/merchants/openapi/#tag/Checkout/operation/PaymentsPost)
*/
createPayment(input) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/checkouts/payments';
try {
const response = yield this.api.post(path, input);
const { data } = response;
const isAuthentic = yield this.isAuthenticMessage(response);
if (!isAuthentic)
throw new helpers_1.NubankApiError({ path, data, isAuthentic });
return data;
}
catch (e) {
throw new helpers_1.NubankApiError({ path, data: e });
}
});
}
/**
* Get a **payment** order status.
* The response will contain information about the **payment**. It may include refunds' identification, if exists.
*
* [Details](https://docs.nupaybusiness.com.br/en/checkout/merchants/openapi/#tag/Checkout/operation/PaymentsStatusByPspReferenceIdGet)
*/
getPaymentStatus(id) {
return __awaiter(this, void 0, void 0, function* () {
const path = `/checkouts/payments/${id}/status`;
try {
const response = yield this.api.get(path);
const { data } = response;
const isAuthentic = yield this.isAuthenticMessage(response);
if (!isAuthentic)
throw new helpers_1.NubankApiError({ path, data, isAuthentic });
return data;
}
catch (e) {
throw new helpers_1.NubankApiError({ path, data: e });
}
});
}
/**
* Cancels a payment as long as it hasn't been paid yet, i.e. payments on *WAITING_FOR_PAYMENT_METHOD* state.
* If it has been paid, a refund must be requested.
*
* [Details](https://docs.nupaybusiness.com.br/en/checkout/merchants/openapi/#tag/Checkout/operation/PaymentsCancelByPspReferenceIdPost)
*/
cancelPayment(id) {
return __awaiter(this, void 0, void 0, function* () {
const path = `/checkouts/payments/${id}/cancel`;
try {
const response = yield this.api.post(path);
const { data } = response;
const isAuthentic = yield this.isAuthenticMessage(response);
if (!isAuthentic)
throw new helpers_1.NubankApiError({ path, data, isAuthentic });
return data;
}
catch (e) {
throw new helpers_1.NubankApiError({ path, data: e });
}
});
}
/**
* This method should be used to **refund** a payment that has been paid by the customer.
* Partial refunds are allowed for a payment paid with either Pix or NuPay, given that the sum of partial refunds open and completed doesn't exceed the total amount of the original payment.
* The status of the refund will change as it is processed, so the merchant system is accountable to monitor these changes via **notifications** as described in the corresponding section.
*
* [Details](https://docs.nupaybusiness.com.br/en/checkout/merchants/openapi/#tag/Checkout/operation/PaymentsRefundByPspReferenceIdPost)
*/
refundPayment(id, body) {
return __awaiter(this, void 0, void 0, function* () {
const path = `/checkouts/payments/${id}/refunds`;
try {
const response = yield this.api.post(path, body);
const { data } = response;
const isAuthentic = yield this.isAuthenticMessage(response);
if (!isAuthentic)
throw new helpers_1.NubankApiError({ path, data, isAuthentic });
return data;
}
catch (e) {
throw new helpers_1.NubankApiError({ path, data: e });
}
});
}
/**
* This method returns information for the **refund** (*refundId*) of a payment (*paymentId*) specified as request parameters.
*
* [Details](https://docs.nupaybusiness.com.br/en/checkout/merchants/openapi/#tag/Checkout/operation/PaymentsRefundByIdGet)
*/
getRefundedPayment(paymentId, refundId) {
return __awaiter(this, void 0, void 0, function* () {
const path = `/checkouts/payments/${paymentId}/refunds/${refundId}`;
try {
const response = yield this.api.get(path);
const { data } = response;
const isAuthentic = yield this.isAuthenticMessage(response);
if (!isAuthentic)
throw new helpers_1.NubankApiError({ path, data, isAuthentic });
return data;
}
catch (e) {
throw new helpers_1.NubankApiError({ path, data: e });
}
});
}
}
exports.NubankPaymentClient = NubankPaymentClient;