-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: changed architecture for PMM and changed delete button
- Loading branch information
1 parent
4f1357e
commit 6b5282f
Showing
19 changed files
with
541 additions
and
172 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,71 @@ | ||
@react.component | ||
let make = (~savedMethods: array<PaymentType.customerMethods>) => { | ||
let make = (~savedMethods: array<PaymentType.customerMethods>, ~setSavedMethods) => { | ||
open CardUtils | ||
open Utils | ||
|
||
let getWalletBrandIcon = (obj: PaymentType.customerMethods) => { | ||
switch obj.paymentMethodType { | ||
| Some("apple_pay") => <Icon size=brandIconSize name="apple_pay_saved" /> | ||
| Some("google_pay") => <Icon size=brandIconSize name="google_pay_saved" /> | ||
| Some("paypal") => <Icon size=brandIconSize name="paypal" /> | ||
| _ => <Icon size=brandIconSize name="default-card" /> | ||
} | ||
let {iframeId} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys) | ||
let {config} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom) | ||
let switchToCustomPod = Recoil.useRecoilValueFromAtom(RecoilAtoms.switchToCustomPod) | ||
let logger = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom) | ||
|
||
let removeSavedMethod = paymentMethodId => { | ||
savedMethods->Array.filter(savedMethod => { | ||
savedMethod.paymentMethodId !== paymentMethodId | ||
}) | ||
} | ||
|
||
let handleDelete = (paymentItem: PaymentType.customerMethods) => { | ||
handlePostMessage([ | ||
("fullscreen", true->JSON.Encode.bool), | ||
("param", "paymentloader"->JSON.Encode.string), | ||
("iframeId", iframeId->JSON.Encode.string), | ||
]) | ||
open Promise | ||
PaymentHelpers.deletePaymentMethod( | ||
~ephemeralKey=config.ephemeralKey, | ||
~paymentMethodId=paymentItem.paymentMethodId, | ||
~logger, | ||
~switchToCustomPod, | ||
) | ||
->then(res => { | ||
let dict = res->getDictFromJson | ||
let paymentMethodId = dict->getString("payment_method_id", "") | ||
let isDeleted = dict->getBool("deleted", false) | ||
|
||
if isDeleted { | ||
logger.setLogInfo( | ||
~value="Successfully Deleted Saved Payment Method", | ||
~eventName=DELETE_SAVED_PAYMENT_METHOD, | ||
(), | ||
) | ||
setSavedMethods(_ => paymentMethodId->removeSavedMethod) | ||
} else { | ||
logger.setLogInfo( | ||
~value="Failed to delete Saved Payment Method", | ||
~eventName=DELETE_SAVED_PAYMENT_METHOD, | ||
(), | ||
) | ||
} | ||
handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) | ||
resolve() | ||
}) | ||
->catch(err => { | ||
let exceptionMessage = err->formatException->JSON.stringify | ||
logger.setLogError( | ||
~value=`Error Deleting Saved Payment Method: ${exceptionMessage}`, | ||
~eventName=DELETE_SAVED_PAYMENT_METHOD, | ||
(), | ||
) | ||
handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) | ||
resolve() | ||
}) | ||
->ignore | ||
} | ||
|
||
savedMethods | ||
->Array.mapWithIndex((obj, i) => { | ||
let brandIcon = switch obj.paymentMethod { | ||
| "wallet" => getWalletBrandIcon(obj) | ||
| _ => | ||
getCardBrandIcon( | ||
switch obj.card.scheme { | ||
| Some(ele) => ele | ||
| None => "" | ||
}->getCardType, | ||
""->CardThemeType.getPaymentMode, | ||
) | ||
} | ||
<SavedMethodItem key={i->Int.toString} paymentItem=obj brandIcon /> | ||
let brandIcon = obj->getPaymentMethodBrand | ||
<SavedMethodItem key={i->Int.toString} paymentItem=obj brandIcon handleDelete /> | ||
}) | ||
->React.array | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.