mirror of https://github.com/BTCPrivate/copay.git
[v4] Updates MeLi integration
This commit is contained in:
parent
06d9553107
commit
510974162f
|
@ -276,21 +276,15 @@ export class BuyMercadoLibrePage {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.sendStatus = '';
|
this.sendStatus = '';
|
||||||
this.onGoingProcessProvider.set('Comprando Vale-Presente', false, this.statusChangeHandler);
|
this.onGoingProcessProvider.set('Comprando Vale-Presente', false, this.statusChangeHandler);
|
||||||
giftCard = {};
|
giftCard = giftCard || {};
|
||||||
giftCard.status = 'FAILURE';
|
giftCard['status'] = 'FAILURE';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (giftCard && giftCard.cardStatus && (giftCard.cardStatus != 'active' && giftCard.cardStatus != 'inactive' && giftCard.cardStatus != 'expired')) {
|
if (giftCard && giftCard.cardStatus && (giftCard.cardStatus != 'active' && giftCard.cardStatus != 'inactive' && giftCard.cardStatus != 'expired')) {
|
||||||
this.sendStatus = '';
|
this.sendStatus = '';
|
||||||
this.onGoingProcessProvider.set('Comprando Vale-Presente', false, this.statusChangeHandler);
|
this.onGoingProcessProvider.set('Comprando Vale-Presente', false, this.statusChangeHandler);
|
||||||
giftCard = {};
|
giftCard = giftCard || {};
|
||||||
giftCard.status = 'FAILURE';
|
giftCard['status'] = 'FAILURE';
|
||||||
}
|
|
||||||
|
|
||||||
if (giftCard.status == 'PENDING' && count < 3) {
|
|
||||||
this.logger.debug("Waiting for payment confirmation");
|
|
||||||
this.checkTransaction(count + 1, dataSrc);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var now = moment().unix() * 1000;
|
var now = moment().unix() * 1000;
|
||||||
|
@ -304,9 +298,18 @@ export class BuyMercadoLibrePage {
|
||||||
newData.date = dataSrc.invoiceTime || now;
|
newData.date = dataSrc.invoiceTime || now;
|
||||||
newData.uuid = dataSrc.uuid;
|
newData.uuid = dataSrc.uuid;
|
||||||
|
|
||||||
|
if (giftCard.status == 'PENDING' && count < 3) {
|
||||||
|
this.logger.debug("Waiting for payment confirmation");
|
||||||
|
this.mercadoLibreProvider.savePendingGiftCard(newData, null, (err: any) => {
|
||||||
|
this.logger.debug("Saving new gift card with status: " + newData.status);
|
||||||
|
});
|
||||||
|
this.checkTransaction(count + 1, dataSrc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.mercadoLibreProvider.savePendingGiftCard(newData, null, (err: any) => {
|
this.mercadoLibreProvider.savePendingGiftCard(newData, null, (err: any) => {
|
||||||
this.onGoingProcessProvider.set('Comprando Vale-Presente', false, this.statusChangeHandler);
|
this.onGoingProcessProvider.set('Comprando Vale-Presente', false, this.statusChangeHandler);
|
||||||
this.logger.debug("Saving new gift card with status: " + newData.status);
|
this.logger.debug("Saved new gift card with status: " + newData.status);
|
||||||
this.mlGiftCard = newData;
|
this.mlGiftCard = newData;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { MercadoLibreCardDetailsPage } from '../mercado-libre-card-details/merca
|
||||||
import { MercadoLibreProvider } from '../../../../providers/mercado-libre/mercado-libre';
|
import { MercadoLibreProvider } from '../../../../providers/mercado-libre/mercado-libre';
|
||||||
import { ExternalLinkProvider } from '../../../../providers/external-link/external-link';
|
import { ExternalLinkProvider } from '../../../../providers/external-link/external-link';
|
||||||
import { PopupProvider } from '../../../../providers/popup/popup';
|
import { PopupProvider } from '../../../../providers/popup/popup';
|
||||||
|
import { TimeProvider } from '../../../../providers/time/time';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'page-mercado-libre-cards',
|
selector: 'page-mercado-libre-cards',
|
||||||
|
@ -17,11 +18,13 @@ import { PopupProvider } from '../../../../providers/popup/popup';
|
||||||
})
|
})
|
||||||
export class MercadoLibreCardsPage {
|
export class MercadoLibreCardsPage {
|
||||||
|
|
||||||
|
private updateGiftCard: boolean;
|
||||||
public giftCards: any;
|
public giftCards: any;
|
||||||
public card: any;
|
public card: any;
|
||||||
public invoiceId;
|
public invoiceId;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private timeProvider: TimeProvider,
|
||||||
private mercadoLibreProvider: MercadoLibreProvider,
|
private mercadoLibreProvider: MercadoLibreProvider,
|
||||||
private externalLinkProvider: ExternalLinkProvider,
|
private externalLinkProvider: ExternalLinkProvider,
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
|
@ -48,6 +51,7 @@ export class MercadoLibreCardsPage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.openCardModal(card);
|
this.openCardModal(card);
|
||||||
|
this.updateGiftCard = this.checkIfCardNeedsUpdate(card);
|
||||||
}
|
}
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
this.logger.warn(err);
|
this.logger.warn(err);
|
||||||
|
@ -58,6 +62,19 @@ export class MercadoLibreCardsPage {
|
||||||
this.externalLinkProvider.open(url);
|
this.externalLinkProvider.open(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private checkIfCardNeedsUpdate(card: any) {
|
||||||
|
// Continues normal flow (update card)
|
||||||
|
if (card.status == 'PENDING') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Check if card status FAILURE for 24 hours
|
||||||
|
if (card.status == 'FAILURE' && this.timeProvider.withinPastDay(card.date)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Success: do not update
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
private updateGiftCards(): Promise<any> {
|
private updateGiftCards(): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.mercadoLibreProvider.getPendingGiftCards((err: any, gcds: any) => {
|
this.mercadoLibreProvider.getPendingGiftCards((err: any, gcds: any) => {
|
||||||
|
@ -75,15 +92,18 @@ export class MercadoLibreCardsPage {
|
||||||
this.updateGiftCards().then(() => {
|
this.updateGiftCards().then(() => {
|
||||||
let gcds = this.giftCards;
|
let gcds = this.giftCards;
|
||||||
_.forEach(gcds, (dataFromStorage: any) => {
|
_.forEach(gcds, (dataFromStorage: any) => {
|
||||||
if (dataFromStorage.status == 'PENDING' || dataFromStorage.status == 'invalid') {
|
|
||||||
|
this.updateGiftCard = this.checkIfCardNeedsUpdate(dataFromStorage);
|
||||||
|
|
||||||
|
if (this.updateGiftCard) {
|
||||||
this.logger.debug("Creating / Updating gift card");
|
this.logger.debug("Creating / Updating gift card");
|
||||||
|
|
||||||
this.mercadoLibreProvider.createGiftCard(dataFromStorage, (err: any, giftCard: any) => {
|
this.mercadoLibreProvider.createGiftCard(dataFromStorage, (err: any, giftCard: any) => {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
this.logger.error('Error creating gift card:', err);
|
this.logger.error('Error creating gift card:', err);
|
||||||
giftCard = {};
|
giftCard = giftCard || {};
|
||||||
giftCard.status = 'FAILURE';
|
giftCard['status'] = 'FAILURE';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (giftCard.status != 'PENDING') {
|
if (giftCard.status != 'PENDING') {
|
||||||
|
@ -98,7 +118,7 @@ export class MercadoLibreCardsPage {
|
||||||
_.merge(newData, dataFromStorage, giftCard);
|
_.merge(newData, dataFromStorage, giftCard);
|
||||||
|
|
||||||
this.mercadoLibreProvider.savePendingGiftCard(newData, null, (err: any) => {
|
this.mercadoLibreProvider.savePendingGiftCard(newData, null, (err: any) => {
|
||||||
this.logger.debug("Saving new gift card");
|
this.logger.debug("Mercado Libre gift card updated");
|
||||||
this.updateGiftCards();
|
this.updateGiftCards();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue