Skip to content

Commit

Permalink
pass application key (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rheber authored May 17, 2024
1 parent 8930e55 commit f0790e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions spiff-connect/public/js/create-design-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const htmlDecode = input => {
return document.documentElement.textContent;
};

const spiffAppendCreateDesignButton = (wooProductId, integrationProductId, currencyCode, redirectUrl, buttonConfig) => {
const spiffAppendCreateDesignButton = (wooProductId, integrationProductId, currencyCode, redirectUrl, buttonConfig, applicationKey) => {
const product = new window.Spiff.IntegrationProduct(integrationProductId);
const buttonClass = "test-create-design";

Expand All @@ -13,17 +13,18 @@ const spiffAppendCreateDesignButton = (wooProductId, integrationProductId, curre
const button = createButton(buttonConfig.personalizeButtonText, buttonConfig, buttonClass);
container.appendChild(button);

button.onclick = () => showSpiffTransaction(product, currencyCode, wooProductId, redirectUrl);
button.onclick = () => showSpiffTransaction(product, currencyCode, wooProductId, redirectUrl, applicationKey);
});
});

product.confirmActive();
};

const showSpiffTransaction = ( product, currencyCode, wooProductId, redirectUrl) => {
const showSpiffTransaction = (product, currencyCode, wooProductId, redirectUrl, applicationKey) => {
const hostedExperienceOptions = {
presentmentCurrency: currencyCode,
product: product,
product,
applicationKey: applicationKey ?? undefined,
};
const hostedExperience = new window.Spiff.HostedExperience(hostedExperienceOptions);
hostedExperience.on("complete", async (result) => {
Expand Down
5 changes: 3 additions & 2 deletions spiff-connect/spiff-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function spiff_append_create_design_button_on_product_page() {
'width' => esc_attr(get_option('spiff_width') ?: "100%"),
'height' => esc_attr(get_option('spiff_height') ?: "50px")
));

$application_key = esc_js(get_option('spiff_application_key'));

if ($product->get_meta('spiff_enabled') === 'yes') {
?>
Expand All @@ -365,7 +365,8 @@ function spiff_append_create_design_button_on_product_page() {
"<?php echo $integration_product_id_js; ?>",
"<?php echo $currency_code; ?>",
"<?php echo $cart_url; ?>",
<?php echo $button_config; ?>
<?php echo $button_config; ?>,
"<?php echo $application_key ?>"
)
</script>
<?php
Expand Down

0 comments on commit f0790e4

Please sign in to comment.