| 1 |
|
| 2 |
import * as Chrome from "@point_of_sale/../tests/pos/tours/utils/chrome_util"; |
| 3 |
import * as ReceiptScreen from "@point_of_sale/../tests/pos/tours/utils/receipt_screen_util"; |
| 4 |
import * as PaymentScreen from "@point_of_sale/../tests/pos/tours/utils/payment_screen_util"; |
| 5 |
import * as ProductScreen from "@point_of_sale/../tests/pos/tours/utils/product_screen_util"; |
| 6 |
import * as Dialog from "@point_of_sale/../tests/generic_helpers/dialog_util"; |
| 7 |
import { registry } from "@web/core/registry"; |
| 8 |
const response_from_adyen_on_pos_webhook = (session, ServiceID) => ({ |
| 9 |
SaleToPOIResponse: { |
| 10 |
MessageHeader: { |
| 11 |
MessageCategory: "Payment", |
| 12 |
MessageClass: "Service", |
| 13 |
MessageType: "Response", |
| 14 |
POIID: "my_adyen_terminal", |
| 15 |
ProtocolVersion: "3.0", |
| 16 |
SaleID: "Furniture Shop (ID: 1)", |
| 17 |
ServiceID, |
| 18 |
}, |
| 19 |
PaymentResponse: { |
| 20 |
POIData: { |
| 21 |
POIReconciliationID: "1000", |
| 22 |
POITransactionID: { |
| 23 |
TimeStamp: "2024-10-24T11:24:30.020Z", |
| 24 |
TransactionID: "4eU8001729769070017.SD3Q9TMJJTSSM475", |
| 25 |
}, |
| 26 |
}, |
| 27 |
PaymentReceipt: [], |
| 28 |
PaymentResult: { |
| 29 |
AmountsResp: { |
| 30 |
AuthorizedAmount: 1.04, |
| 31 |
Currency: "USD", |
| 32 |
}, |
| 33 |
CustomerLanguage: "en", |
| 34 |
OnlineFlag: true, |
| 35 |
PaymentAcquirerData: { |
| 36 |
AcquirerPOIID: "P400Plus-275319618", |
| 37 |
AcquirerTransactionID: { |
| 38 |
TimeStamp: "2024-10-24T11:24:30.020Z", |
| 39 |
TransactionID: "SD3Q9TMJJTSSM475", |
| 40 |
}, |
| 41 |
ApprovalCode: "123456", |
| 42 |
MerchantID: "OdooMP_POS", |
| 43 |
}, |
| 44 |
PaymentInstrumentData: { |
| 45 |
CardData: { |
| 46 |
CardCountryCode: "826", |
| 47 |
EntryMode: ["Contactless"], |
| 48 |
MaskedPan: "541333 **** 9999", |
| 49 |
PaymentBrand: "mc", |
| 50 |
SensitiveCardData: { |
| 51 |
CardSeqNumb: "33", |
| 52 |
ExpiryDate: "0228", |
| 53 |
}, |
| 54 |
}, |
| 55 |
PaymentInstrumentType: "Card", |
| 56 |
}, |
| 57 |
}, |
| 58 |
Response: { |
| 59 |
AdditionalResponse: |
| 60 |
"useless=true&metadata.pos_hmac=ba6c62413839eb32030a3ee6400af4d367b8fb889b54ea85dffcb5a13625c318", |
| 61 |
Result: "Success", |
| 62 |
}, |
| 63 |
SaleData: { |
| 64 |
SaleTransactionID: { |
| 65 |
TimeStamp: "2024-10-24T11:24:29.000Z", |
| 66 |
TransactionID: `921e7aa8-36b3-400c-a416-2b9a1eaf1283--${session}`, |
| 67 |
}, |
| 68 |
}, |
| 69 |
}, |
| 70 |
}, |
| 71 |
}); |
| 72 |
|
| 73 |
registry.category("web_tour.tours").add("PosAdyenTour", { |
| 74 |
steps: () => |
| 75 |
[ |
| 76 |
Chrome.startPoS(), |
| 77 |
Dialog.confirm("Open Register"), |
| 78 |
ProductScreen.addOrderline("Desk Pad"), |
| 79 |
ProductScreen.clickPayButton(), |
| 80 |
PaymentScreen.clickPaymentMethod("Adyen"), |
| 81 |
{ |
| 82 |
content: "Waiting for Adyen payment to be processed", |
| 83 |
trigger: ".electronic_status:contains('Waiting for card')", |
| 84 |
run: async function () { |
| 85 |
const payment_terminal = |
| 86 |
posmodel.getPendingPaymentLine("adyen").payment_method_id.payment_terminal; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
const resp = await fetch("/pos_adyen/notification", { |
| 95 |
method: "POST", |
| 96 |
headers: { |
| 97 |
"Content-Type": "application/json", |
| 98 |
}, |
| 99 |
body: JSON.stringify( |
| 100 |
response_from_adyen_on_pos_webhook( |
| 101 |
posmodel.config.current_session_id.id, |
| 102 |
payment_terminal.most_recent_service_id |
| 103 |
) |
| 104 |
), |
| 105 |
}); |
| 106 |
if (!resp.ok) { |
| 107 |
throw new Error("Failed to notify Adyen webhook"); |
| 108 |
} |
| 109 |
}, |
| 110 |
}, |
| 111 |
|
| 112 |
ReceiptScreen.isShown(), |
| 113 |
].flat(), |
| 114 |
}); |