react-native-iap requestSubscription withOffer, Unable to Purchase (ios)

168 views Asked by At

if not use withOffer, it work.

if used withOffer, the purchase process was unsuccessful.

On TestFlight, When the requestSubscription is called, the product information will pop up, and the user name and password will also be requested.

Alert message ' Unable to Purchase, Contact the developer for more infomation ' after submit password.

My server code:

const APPLE_KEY_ID = 'ABCDEFG';
const APPLE_PRIVATE_KEY = `-----BEGIN PRIVATE KEY-----
MIGTAgEAQQg/L4AGXh56Yl07vfyIBAl290/n9JM0JQ+spzFhGzo+amvzSmjaVQ5X
AWo182SMBwwMCRx/LaN94MdvRm6gCgYIKoZIzj0FFQehRANCAASx+SB3wk7Yo9hi
Ig32T/ODxA2snpMlHGRh/BBJ30qnxOMAWCByqGSM49AgEGCCqGSM49AwEHBHkerw
xA2oOnYc
-----END PRIVATE KEY-----`;

const appBundleID = 'net.xxx.myapp';
const productIdentifier = 'vip_month_1';
const subscriptionOfferID = 'vip_free_1_month';

const signatureOffer = (applicationUsername) => {
    const nonce = uuidv4();
    const timestamp = new Date().getTime();
    
    const payload = appBundleID + '\u2063' +
                    APPLE_KEY_ID + '\u2063' +
                    productIdentifier + '\u2063' +
                    subscriptionOfferID + '\u2063' +
                    applicationUsername  + '\u2063'+
                    nonce + '\u2063' +
                    timestamp;

    const key = new ECKey(APPLE_PRIVATE_KEY, 'pem');
    const cryptoSign = key.createSign('SHA256');
    cryptoSign.update(payload);
    const signature = cryptoSign.sign('base64');

    return {
        identifier: subscriptionOfferID,
        keyIdentifier: APPLE_KEY_ID,
        nonce: nonce,
        signature: signature,
        timestamp: timestamp
    };
};


router.post('/signOffer', (req, res) => {
    let userName = req.body.userName;
    
    res.send({
        userName: userName,
        withOffer: signatureOffer(userName)
    });
});

The client code:

const signResult = await http.post('https://domain/signOffer', { userName: 'abc123' });

requestSubscription({
    sku: 'vip_month_1',
    appAccountToken: signResult.userName,
    withOffer: signResult.withOffer
});
0

There are 0 answers