Skip to content

Commit 9b5601c

Browse files
committed
Allow purchase.payment to be undefined
1 parent d75eb1f commit 9b5601c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

client/lib/purchases/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export function isOneTimePurchase( purchase: Purchase ) {
512512
}
513513

514514
export function isPaidWithPaypal( purchase: Purchase ) {
515-
return 'paypal' === purchase.payment.type;
515+
return 'paypal' === purchase.payment?.type;
516516
}
517517

518518
export function isPaidWithCredits( purchase: Purchase ) {
@@ -764,15 +764,15 @@ export function isSubscription( purchase: Purchase ): boolean {
764764
}
765765

766766
export function isPaidWithCreditCard( purchase: Purchase ) {
767-
return 'credit_card' === purchase.payment.type && hasCreditCardData( purchase );
767+
return 'credit_card' === purchase.payment?.type && hasCreditCardData( purchase );
768768
}
769769

770770
export function isPaidWithPayPalDirect( purchase: Purchase ) {
771-
return 'paypal_direct' === purchase.payment.type && purchase.payment.expiryDate;
771+
return 'paypal_direct' === purchase.payment?.type && purchase.payment.expiryDate;
772772
}
773773

774774
function hasCreditCardData( purchase: Purchase ) {
775-
return Boolean( purchase.payment.creditCard?.expiryDate );
775+
return Boolean( purchase.payment?.creditCard?.expiryDate );
776776
}
777777

778778
export function shouldAddPaymentSourceInsteadOfRenewingNow( purchase: Purchase ) {
@@ -836,7 +836,7 @@ export function shouldRenderExpiringCreditCard( purchase: Purchase ) {
836836
}
837837

838838
export function monthsUntilCardExpires( purchase: Purchase ) {
839-
const creditCard = purchase.payment.creditCard;
839+
const creditCard = purchase.payment?.creditCard;
840840
const expiry = moment( creditCard?.expiryDate, 'MM/YY' );
841841
return expiry.diff( moment(), 'months' );
842842
}
@@ -857,16 +857,16 @@ export function subscribedWithinPastWeek( purchase: Purchase ) {
857857
*/
858858
export function paymentLogoType( purchase: Purchase ): string | null | undefined {
859859
if ( isPaidWithCreditCard( purchase ) ) {
860-
return purchase.payment.creditCard?.displayBrand
860+
return purchase.payment?.creditCard?.displayBrand
861861
? purchase.payment.creditCard?.displayBrand
862-
: purchase.payment.creditCard?.type;
862+
: purchase.payment?.creditCard?.type;
863863
}
864864

865865
if ( isPaidWithPayPalDirect( purchase ) ) {
866866
return 'placeholder';
867867
}
868868

869-
return purchase.payment.type || null;
869+
return purchase.payment?.type || null;
870870
}
871871

872872
export function isAgencyPartnerType( partnerType: string ) {

client/me/purchases/purchases-list-in-dataviews/purchases-data-field.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ export function getPurchasesFieldDefinitions( {
176176
operators: [ 'is' as Operator ],
177177
},
178178
getValue: ( { item }: { item: Purchases.Purchase } ) => {
179-
return item.payment.storedDetailsId ?? '';
179+
return item.payment?.storedDetailsId ?? '';
180180
},
181181
render: ( { item }: { item: Purchases.Purchase } ) => {
182182
let isBackupMethodAvailable = false;
183183

184184
if ( backupPaymentMethods ) {
185185
const backupPaymentMethodsWithoutCurrentPurchase = backupPaymentMethods.filter(
186186
// A payment method is only a back up if it isn't already assigned to the current purchase
187-
( paymentMethod ) => item.payment.storedDetailsId !== paymentMethod.stored_details_id
187+
( paymentMethod ) => item.payment?.storedDetailsId !== paymentMethod.stored_details_id
188188
);
189189

190190
isBackupMethodAvailable = backupPaymentMethodsWithoutCurrentPurchase.length >= 1;

client/me/purchases/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function canEditPaymentDetails( purchase: Purchase ): boolean {
2727
}
2828

2929
export function getChangePaymentMethodPath( siteSlug: string, purchase: Purchase ): string {
30-
if ( isPaidWithCreditCard( purchase ) && purchase.payment.creditCard ) {
30+
if ( isPaidWithCreditCard( purchase ) && purchase.payment?.creditCard ) {
3131
return changePaymentMethod( siteSlug, purchase.id, purchase.payment.creditCard.id );
3232
}
3333

packages/data-stores/src/purchases/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface Purchase {
4444
partnerName: string | undefined;
4545
partnerSlug: string | undefined;
4646
partnerType: string | undefined;
47-
payment: PurchasePayment | PurchasePaymentWithCreditCard | PurchasePaymentWithPayPal;
47+
payment: PurchasePayment | PurchasePaymentWithCreditCard | PurchasePaymentWithPayPal | undefined;
4848
pendingTransfer: boolean;
4949
priceText: string;
5050
priceTierList?: Array< PurchasePriceTier >;

0 commit comments

Comments
 (0)