14.9 C
London
Monday, September 9, 2024

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


if not use withOffer, it work.

if used withOffer, the acquisition course of was unsuccessful.

On TestFlight, When the requestSubscription is known as, the product data will pop up, and the person identify and password will even be requested.

Alert message ‘ Unable to Buy, Contact the developer for extra 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 = 'internet.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.replace(payload);
    const signature = cryptoSign.signal('base64');

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


router.put up('/signOffer', (req, res) => {
    let userName = req.physique.userName;
    
    res.ship({
        userName: userName,
        withOffer: signatureOffer(userName)
    });
});

The consumer code:

const signResult = await http.put up('https://area/signOffer', { userName: 'abc123' });

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

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here