What I need:
make promotional offers work with subscription. Offer a subscription discount when the user meets certain criteria, which is decided client-side.
What I do:
- add SKProductDiscount instance to SKMutablePayment
- initialize it with
- discount ID (from App Store)
- private key ID (p8 downloaded from App Store)
- nonce (generated by server, unique)
- signature (generated by server on demand; read, only when the purchase is requested)
- timestamp (generated by server, moments before the transaction)
- add the payment to the queue
- make sure that application username field of SKMutablePayment contains the same hashed user ID as the signature
What I get:
- the purchase popup show the price with discount, followed by the regular price that will become active when discounted period expires
- after confirming the purchase, the 'Unable to purchase' popup is shown
- transaction update callback logs SKPaymentTransaction::error set to ErrorCode:12, which corresponds to InvalidSignature
What I ask:
- how is it possible that the discount price is shown correctly, while the signature is invalid? Discount ID is specified in the signature, so the fact that the price is correct makes me think that the platform did in fact decode the signature successfully.
- what can possibly be wrong with the following code, that generates the signature server-side
product = args['product']
offer = args['offer']
bundle_id = args['bundle_id']
application_username = args['application_username'] if 'application_username' in args else ''
key_id = args['key_id']
nonce = uuid.uuid4()
timestamp = int(round(time.time() * 1000))
payload = '\u2063'.join([bundle_id,
key_id,
product,
offer,
application_username,
str(nonce),
str(timestamp)])
pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, CERT)
signature = OpenSSL.crypto.sign(pkey, payload, "sha256")
encoded_signature = base64.b64encode(signature)
return {
'signature': str(encoded_signature),
'nonce': str(nonce),
'timestamp': str(timestamp),
'key_id': key_id
}Many thanks in advance