-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a389a87
commit 5111cbf
Showing
6 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const sendPostMessage = (message: 'onSuccess' | 'onError' | 'onBack') => { | ||
window.top.postMessage(message); | ||
console.info(`${message} message sent`); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { InvoiceStatusChanged, PaymentCondition, PaymentStatusChanged } from 'checkout/paymentCondition'; | ||
import { last, sendPostMessage } from 'checkout/utils'; | ||
|
||
const handlePaymentStatusChanged = (condition: PaymentStatusChanged) => { | ||
switch (condition.status) { | ||
case 'captured': | ||
case 'processed': | ||
sendPostMessage('onSuccess'); | ||
break; | ||
case 'failed': | ||
sendPostMessage('onError'); | ||
break; | ||
} | ||
}; | ||
|
||
const handleInvoiceStatusChanged = (condition: InvoiceStatusChanged) => { | ||
switch (condition.status) { | ||
case 'paid': | ||
sendPostMessage('onSuccess'); | ||
break; | ||
} | ||
}; | ||
|
||
export function usePostMessage(conditions: PaymentCondition[]) { | ||
useEffect(() => { | ||
const lastCondition = last(conditions); | ||
switch (lastCondition.name) { | ||
case 'paymentProcessFailed': | ||
sendPostMessage('onError'); | ||
break; | ||
case 'paymentStatusChanged': | ||
handlePaymentStatusChanged(lastCondition); | ||
break; | ||
case 'invoiceStatusChanged': | ||
handleInvoiceStatusChanged(lastCondition); | ||
break; | ||
} | ||
}, [conditions]); | ||
} |
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