Skip to content

Commit

Permalink
Merge pull request #85 from bosonprotocol/widget-callback-url
Browse files Browse the repository at this point in the history
feat: add new params to redemption widget to manage callbacks
  • Loading branch information
levalleux-ludo authored Oct 20, 2023
2 parents 8d6d392 + 1148531 commit f5b17ed
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 44 deletions.
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@bosonprotocol/react-kit": "^0.22.0-alpha.2",
"@bosonprotocol/react-kit": "^0.22.0-alpha.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
64 changes: 62 additions & 2 deletions public/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,23 @@ <h2>Redemption Widget</h2>
<button onclick="clearRedeemInputs(); setValue('input-redeem-exchange-id', '80'); setValue('select-redeem-widget-action', 'CANCEL_FORM')" >Example</button>
</td>
</tr>
<tr>
<td>DeliveryInfo</td>
<td>
<textarea id="input-delivery-info" onchange="updateRedeemButton('data-delivery-info', encodeURI(this.value))" rows="10" cols="30">
</textarea>
</td>
<td>
<button onclick="clearRedeemInputs(); setValue('input-redeem-show-overview', false, 'checked'); setValue('input-post-delivery-info-url', 'http://localhost:3666/deliveryInfo'); setValue('input-redeem-exchange-id', '133'); setValue('select-redeem-widget-action', 'CONFIRM_REDEEM'); setValue('input-delivery-info', fullDecodeUri('%7B%22name%22:%20%22TOTO%22,%20%22streetNameAndNumber%22:%20%221%20grand%20place%22,%20%22city%22:%20%22LILLE%22,%20%22state%22:%20%22NORD%22,%20%22zip%22:%20%2259000%22,%20%22country%22:%20%22FR%22,%20%22email%22:%20%[email protected]%22,%20%22phone%22:%20%22%2B33123456789%22%7D'))" >Example</button>
</td>
</tr>
<tr>
<td>PostDeliveryInfoURL</td>
<td>
<input type="url" id="input-post-delivery-info-url" onchange="updateRedeemButton('data-post-delivery-info-url', encodeURI(this.value))" size="30">
</td>
<td>
<button onclick="clearRedeemInputs(); setValue('input-post-delivery-info-url', 'http://localhost:3666')" >Example</button>
<button onclick="setValue('input-post-delivery-info-url', 'http://localhost:3666/deliveryInfo')" >Example</button>
</td>
</tr>
<tr>
Expand All @@ -125,7 +135,45 @@ <h2>Redemption Widget</h2>
</textarea>
</td>
<td>
<button onclick="clearRedeemInputs(); setValue('input-post-delivery-info-url', 'http://localhost:3666'); setValue('input-post-delivery-info-header', decodeURI('%7B%0A%20%20%22authorization%22:%20%22Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9%22,%0A%20%20%22another-header%22:%20%22*****%22%0A%7D'))" >Example</button>
<button onclick="setValue('input-post-delivery-info-url', 'http://localhost:3666/deliveryInfo'); setValue('input-post-delivery-info-header', fullDecodeUri('%7B%0A%20%20%22authorization%22:%20%22Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9%22,%0A%20%20%22another-header%22:%20%22*****%22%0A%7D'))" >Example</button>
</td>
</tr>
<tr>
<td>PostRedemptionSubmittedURL</td>
<td>
<input type="url" id="input-post-redemption-submitted-url" onchange="updateRedeemButton('data-post-redemption-submitted-url', encodeURI(this.value))" size="30">
</td>
<td>
<button onclick="setValue('input-post-redemption-submitted-url', 'http://localhost:3666/submitted')" >Example</button>
</td>
</tr>
<tr>
<td>PostRedemptionSubmittedHeader</td>
<td>
<textarea id="input-post-redemption-submitted-header" onchange="updateRedeemButton('data-post-redemption-submitted-headers', encodeURI(this.value))" rows="10" cols="30">
</textarea>
</td>
<td>
<button onclick="setValue('input-post-redemption-submitted-url', 'http://localhost:3666/submitted'); setValue('input-post-redemption-submitted-header', fullDecodeUri('%7B%0A%20%20%22authorization%22:%20%22Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9%22,%0A%20%20%22another-header%22:%20%22*****%22%0A%7D'))" >Example</button>
</td>
</tr>
<tr>
<td>PostRedemptionConfirmedURL</td>
<td>
<input type="url" id="input-post-redemption-confirmed-url" onchange="updateRedeemButton('data-post-redemption-confirmed-url', encodeURI(this.value))" size="30">
</td>
<td>
<button onclick="setValue('input-post-redemption-confirmed-url', 'http://localhost:3666/confirmed')" >Example</button>
</td>
</tr>
<tr>
<td>PostRedemptionConfirmedHeader</td>
<td>
<textarea id="input-post-redemption-confirmed-header" onchange="updateRedeemButton('data-post-redemption-confirmed-headers', encodeURI(this.value))" rows="10" cols="30">
</textarea>
</td>
<td>
<button onclick="setValue('input-post-redemption-confirmed-url', 'http://localhost:3666/confirmed'); setValue('input-post-redemption-confirmed-header', fullDecodeUri('%7B%0A%20%20%22authorization%22:%20%22Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9%22,%0A%20%20%22another-header%22:%20%22*****%22%0A%7D'))" >Example</button>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -162,11 +210,23 @@ <h2>Redemption Widget</h2>
setValue('select-redeem-exchange-state', 'Committed')
setValue('input-post-delivery-info-url', '')
setValue('input-post-delivery-info-header', '')
setValue('input-post-redemption-submitted-url', '')
setValue('input-post-redemption-submitted-header', '')
setValue('input-post-redemption-confirmed-url', '')
setValue('input-post-redemption-confirmed-header', '')
setValue('input-delivery-info', '')
}
function clearFinanceInputs() {
setValue('input-finance-seller-id', '')
updateFinanceButton('disabled', true)
}
function fullDecodeUri(s) {
const s2 = decodeURI(s);
if (s2 !== s) {
return fullDecodeUri(s2)
}
return s2
}
</script>
</body>
</html>
39 changes: 39 additions & 0 deletions public/scripts/boson-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ const constants = {
exchangeStateTag: "data-exchange-state",
showRedemptionOverviewTag: "data-show-redemption-overview",
widgetActionTag: "data-widget-action",
deliveryInfoTag: "data-delivery-info",
postDeliveryInfoUrlTag: "data-post-delivery-info-url",
postDeliveryInfoHeadersTag: "data-post-delivery-info-headers",
postRedemptionSubmittedUrlTag: "data-post-redemption-submitted-url",
postRedemptionSubmittedHeadersTag: "data-post-redemption-submitted-headers",
postRedemptionConfirmedUrlTag: "data-post-redemption-confirmed-url",
postRedemptionConfirmedHeadersTag: "data-post-redemption-confirmed-headers",
sellerIdTag: "data-seller-id",
configIdTag: "data-config-id",
accountTag: "data-account",
Expand Down Expand Up @@ -127,10 +132,22 @@ function bosonWidgetReload() {
showRedeemId.attributes[constants.showRedemptionOverviewTag]?.value;
const widgetAction =
showRedeemId.attributes[constants.widgetActionTag]?.value;
const deliveryInfo =
showRedeemId.attributes[constants.deliveryInfoTag]?.value;
const postDeliveryInfoUrl =
showRedeemId.attributes[constants.postDeliveryInfoUrlTag]?.value;
const postDeliveryInfoHeaders =
showRedeemId.attributes[constants.postDeliveryInfoHeadersTag]?.value;
const postRedemptionSubmittedUrl =
showRedeemId.attributes[constants.postRedemptionSubmittedUrlTag]?.value;
const postRedemptionSubmittedHeaders =
showRedeemId.attributes[constants.postRedemptionSubmittedHeadersTag]
?.value;
const postRedemptionConfirmedUrl =
showRedeemId.attributes[constants.postRedemptionConfirmedUrlTag]?.value;
const postRedemptionConfirmedHeaders =
showRedeemId.attributes[constants.postRedemptionConfirmedHeadersTag]
?.value;
const configId = showRedeemId.attributes[constants.configIdTag]?.value;
const account = showRedeemId.attributes[constants.accountTag]?.value;
bosonWidgetShowRedeem({
Expand All @@ -139,8 +156,13 @@ function bosonWidgetReload() {
exchangeState,
showRedemptionOverview,
widgetAction,
deliveryInfo,
postDeliveryInfoUrl,
postDeliveryInfoHeaders,
postRedemptionSubmittedUrl,
postRedemptionSubmittedHeaders,
postRedemptionConfirmedUrl,
postRedemptionConfirmedHeaders,
configId,
account
});
Expand All @@ -165,8 +187,25 @@ function bosonWidgetShowRedeem(args) {
value: args.showRedemptionOverview?.toString() // to allow passing either a real boolean or a string
},
{ tag: "widgetAction", value: args.widgetAction },
{ tag: "deliveryInfo", value: args.deliveryInfo },
{ tag: "postDeliveryInfoUrl", value: args.postDeliveryInfoUrl },
{ tag: "postDeliveryInfoHeaders", value: args.postDeliveryInfoHeaders },
{
tag: "postRedemptionSubmittedUrl",
value: args.postRedemptionSubmittedUrl
},
{
tag: "postRedemptionSubmittedHeaders",
value: args.postRedemptionSubmittedHeaders
},
{
tag: "postRedemptionConfirmedUrl",
value: args.postRedemptionConfirmedUrl
},
{
tag: "postRedemptionConfirmedHeaders",
value: args.postRedemptionConfirmedHeaders
},
{ tag: "configId", value: args.configId },
{ tag: "account", value: args.account }
]);
Expand Down
Loading

0 comments on commit f5b17ed

Please sign in to comment.