Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from applicationUsername to appAccountToken #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ const encodedKey = readFile(filePath) // Specific implementation may vary

const productId = "<product_id>"
const subscriptionOfferId = "<subscription_offer_id>"
const applicationUsername = "<application_username>"
const appAccountToken = "<app_account_token>"
const nonce = "<nonce>"
const timestamp = Date.now()
const signatureCreator = new PromotionalOfferSignatureCreator(encodedKey, keyId, bundleId)

const signature = signatureCreator.createSignature(productId, subscriptionOfferId, applicationUsername, nonce, timestamp)
const signature = signatureCreator.createSignature(productId, subscriptionOfferId, appAccountToken, nonce, timestamp)
console.log(signature)
```

Expand Down
6 changes: 3 additions & 3 deletions promotional_offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ export class PromotionalOfferSignatureCreator {
* {@link https://developer.apple.com/documentation/storekit/in-app_purchase/original_api_for_in-app_purchase/subscriptions_and_offers/generating_a_signature_for_promotional_offers Generating a signature for promotional offers}
* @param productIdentifier The subscription product identifier
* @param subscriptionOfferID The subscription discount identifier
* @param applicationUsername An optional string value that you define; may be an empty string
* @param appAccountToken An optional string value that you define; may be an empty string
* @param nonce A one-time UUID value that your server generates. Generate a new nonce for every signature.
* @param timestamp A timestamp your server generates in UNIX time format, in milliseconds. The timestamp keeps the offer active for 24 hours.
* @return The Base64 encoded signature
*/
public createSignature(productIdentifier: string, subscriptionOfferID: string, applicationUsername: string, nonce: string, timestamp: number): string {
public createSignature(productIdentifier: string, subscriptionOfferID: string, appAccountToken: string, nonce: string, timestamp: number): string {
const payload = this.bundleId + '\u2063' +
this.keyId + '\u2063' +
productIdentifier + '\u2063' +
subscriptionOfferID + '\u2063' +
applicationUsername.toLowerCase() + '\u2063'+
appAccountToken.toLowerCase() + '\u2063'+
nonce.toLowerCase() + '\u2063' +
timestamp;
const sign = createSign('SHA256')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readFile } from "../util"
describe('Promotional Offer Signature Creation Test', () => {
it('should create a non-null signature', async () => {
const signatureCreator = new PromotionalOfferSignatureCreator(readFile('tests/resources/certs/testSigningKey.p8'), "keyId", "bundleId");
const signature = signatureCreator.createSignature('productId', 'offerId', 'applicationUsername', "20fba8a0-2b80-4a7d-a17f-85c1854727f8", 1698148900000)
const signature = signatureCreator.createSignature('productId', 'offerId', 'appAccountToken', "20fba8a0-2b80-4a7d-a17f-85c1854727f8", 1698148900000)
expect(signature).toBeTruthy()
})
})