Skip to content

Commit

Permalink
[types] [doc] [fix] Make sure product_id is given preference + Update…
Browse files Browse the repository at this point in the history
… readme file formatting + Mark some interfaces as internal.
  • Loading branch information
swashata committed Nov 24, 2024
1 parent 1b1f096 commit 2b39be3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ export default function App() {

## Testing with the Sandbox

This sample code uses PHP to generate the token and timestamp but you can
use the same approach in any server-side environment which will protect
the secret key.
This sample code uses PHP to generate the token and timestamp but you can use
the same approach in any server-side environment which will protect the secret
key.

1. Go to the Developer Dashboard.
2. Under Plans click on the "Get Checkout Code" button.
3. Go to the Sandbox tab.
4. Copy the code to generate the `sandbox_token` and `timestamp` values and
output them for the Javascript to use.
4. Copy the code to generate the `sandbox_token` and `timestamp` values and
output them for the Javascript to use.

Example:

Expand All @@ -324,13 +324,12 @@ $sandbox_token = md5(
);
```


```js
const config = {
// ...
sandbox: {
token: '<?php echo $sandbox_token; ?>',
ctx: '<?php echo $timestamp; ?>'
ctx: '<?php echo $timestamp; ?>',
},
};
```
Expand Down
20 changes: 20 additions & 0 deletions src/lib/checkout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,24 @@ describe('CheckoutPopup', () => {

expect(new URL(iFrame.src).searchParams.get('plugin_id')).toBe('1');
});

test('prefers product_id over plugin_id', () => {
const checkout = new Checkout({
plugin_id: 1,
product_id: 2,
public_key: 'pk_123456',
license_key: 'sk_R-5E2+%20BD:.kp*(Oq2aodhzZ1Jw',
} as any);
checkout.open();

const guid = checkout.getGuid();

const iFrame = screen.queryByTestId(
`fs-checkout-page-${guid}`
) as HTMLIFrameElement;

expect(iFrame).toBeInTheDocument();

expect(new URL(iFrame.src).searchParams.get('plugin_id')).toBe('2');
});
});
2 changes: 1 addition & 1 deletion src/lib/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Checkout {
this.options = {
...popupOptions,
public_key,
plugin_id: plugin_id ?? product_id,
plugin_id: product_id ?? plugin_id,
};

this.guid = generateGuid();
Expand Down
4 changes: 4 additions & 0 deletions src/lib/contracts/CheckoutPopupOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,17 @@ export interface CheckoutPopupEvents {

/**
* All options (parameters and events) required and supported by the Freemius Checkout.
*
* @internal
*/
export interface CheckoutPopupOptions
extends CheckoutPopupParams,
CheckoutPopupEvents {}

/**
* Accept any arbitrary key-value pair to be passed to the checkout.
*
* @internal
*/
export interface CheckoutPopupArbitraryParams {
[key: Exclude<string, keyof CheckoutPopupOptions>]: any;
Expand Down

0 comments on commit 2b39be3

Please sign in to comment.