Пытаюсь внедрить плагин для ионного кордова InAppPurchase.
Функция плагина getReceipt () возвращает длинную строку, которую я должен декодировать.
Я прочитал эту статью https://scottbolinger.com/cordova-app-purchases-validating-subscriptions/ и сделал точно так, как там показано, но все равно это не работает.
Например вот мой код
import {Http, Headers, RequestOptions} from '@angular/http';
import { InAppPurchase } from '@ionic-native/in-app-purchase';
constructor(
public pay:InAppPurchase,
public http: Http
)
{
Restore()
{
let response = this.checkStatus().then(response =>{
console.log(response)
}).catch(err=>{
console.log(err)
});
}
}
checkStatus() {
return new Promise( (resolve, reject) => {
// first, ask Apple for the receipt. We get back an encrypted string.
this.pay.getReceipt()
.then( receipt => {
return receipt;
})
.then( receiptData => {
// next, validate the encoded receipt with Apple, and get back the human readable format
this.validateReceipt( receiptData ).then( receipt => {
console.log(receipt);
})
})
.catch( err => {
reject( err );
})
})
}
validateReceipt( receiptData ) {
return new Promise( (resolve ) => {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let data = {
'password': 'XXXXXXXXXXXXXXXXXXXXX', // the shared secret key for your in app purchase https://stackoverflow.com/questions/5022296/generate-shared-secret-key-in-itunes-connect-for-in-app-purchase
'receipt-data': receiptData
}
this.http.post( 'https://buy.itunes.apple.com/verifyReceipt', data, options )
.subscribe(response => {
let receipt = JSON.parse(response['_body']).receipt
resolve(receipt)
// purchases can be found at receipt.in_app <Array>
// will need to loop through them and get most recent, then work with expiration date
},
error => {
// probably a bad url or 404
console.log(error);
})
})
}
Проще говоря, я просто скопировал и вставил пример из статьи, просто внедрив в него свой общий пароль, и он мне ничего не дал. Кто знает, как можно решить проблему, помогите.