Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
feat: add checkout function
Browse files Browse the repository at this point in the history
Closes #64
  • Loading branch information
jonyw4 committed Oct 21, 2020
1 parent c7ce153 commit 64694c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/MelhorEnvio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ class MelhorEnvio {
): Promise<Response.Cart> {
return this.fetch<Response.Cart>('/api/v2/me/cart', 'POST', {}, data);
}

public async checkout(data: Request.Shipment.Checkout) {
return this.fetch<Response.Shipment.Checkout>(
'/api/v2/me/shipment/checkout',
'POST',
{},
data
);
}
}

export default MelhorEnvio;
21 changes: 20 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ export namespace Response {
export type Calculate<T = Array<string> | string | null> = T extends string
? CalculateItem
: CalculateItem[];

/**
* **Nota: entre os dados retornados constará o id da etiqueta. Este id deverá ser salvo em vias de realizar futuras interações para esta etiqueta, como o momento da compra da etiqueta (checkout).**
* Após feita a requisição, será retornado, entre outros dados, uma url de redirecionamento para concluir o pagamento junto ao gateway.
*/
export interface Checkout {
id: string;
}
}
export interface Cart {
id: string;
Expand All @@ -157,6 +161,21 @@ export namespace Request {
ownHand: boolean;
insuranceValue: number;
}
/**
* - Para poder realizar a compra da etiqueta, o usuário deverá ter na carteira do Melhor Envio o saldo necessário para tal compra.
* - Deverá ser respeitado o limite de envios disponível no momento da compra.
*/
interface CheckoutBase {
orders: string[];
}
interface CheckoutWithGateway extends CheckoutBase {
gateway: 'moip' | 'mercado-pago' | 'picpay' | 'pagseguro';
/**
* URL de redirecionamento para retorno após o pagamento
*/
redirect: string;
}
export type Checkout = CheckoutBase | CheckoutWithGateway;
}

type CartProducts = Array<{
Expand Down

0 comments on commit 64694c2

Please sign in to comment.