Skip to content

Commit 3245d33

Browse files
committed
fix(dia-backend-num): truncate reciept_id
1 parent 8033938 commit 3245d33

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/app/shared/dia-backend/num/dia-backend-num.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpClient } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
33
import { defer } from 'rxjs';
44
import { concatMap } from 'rxjs/operators';
5+
import { truncateReceipt } from '../../../utils/in-app-purchase';
56
import { DiaBackendAuthService } from '../auth/dia-backend-auth.service';
67
import { BASE_URL, BUBBLE_API_URL } from '../secret';
78

@@ -19,7 +20,7 @@ export class DiaBackendNumService {
1920
concatMap(headers => {
2021
const formData = new FormData();
2122
formData.set('points', pointsToAdd.toString());
22-
formData.set('receipt_id', receiptId);
23+
formData.set('receipt_id', truncateReceipt(receiptId));
2324
return this.httpClient.post<DiaBackendNumPointPurchaseResult>(
2425
`${BASE_URL}/api/v3/num/points/purchase/`,
2526
formData,

src/app/utils/in-app-purchase.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { isDevMode } from '@angular/core';
22
import { IAPProduct } from '@awesome-cordova-plugins/in-app-purchase-2/ngx';
33
import { CaptureInAppProductIds } from '../shared/in-app-store/in-app-store.service';
44

5+
export function truncateReceipt(recipt: string) {
6+
const preferredMaxLength = 1024;
7+
const receiptMaxLength = Math.min(recipt.length, preferredMaxLength);
8+
return recipt.substring(0, receiptMaxLength);
9+
}
10+
511
/**
612
* Usefull to see in app product state changes in console for better debugging.
713
* It will pring to console only in dev mode aka isDevMode() === true

0 commit comments

Comments
 (0)