feat: enable explicit IAP restoration (#21461)

This commit is contained in:
Shelley Vohr 2019-12-17 07:07:11 -08:00 committed by GitHub
parent 53957d47d6
commit dba8a0caa8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 23 deletions

View file

@ -85,6 +85,8 @@ void InAppPurchase::BuildPrototype(v8::Isolate* isolate,
prototype->SetClassName(gin::StringToV8(isolate, "InAppPurchase"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("canMakePayments", &in_app_purchase::CanMakePayments)
.SetMethod("restoreCompletedTransactions",
&in_app_purchase::RestoreCompletedTransactions)
.SetMethod("getReceiptURL", &in_app_purchase::GetReceiptURL)
.SetMethod("purchaseProduct", &InAppPurchase::PurchaseProduct)
.SetMethod("finishAllTransactions",

View file

@ -17,13 +17,15 @@ typedef base::OnceCallback<void(bool isProductValid)> InAppPurchaseCallback;
// --------------------------- Functions ---------------------------
bool CanMakePayments(void);
bool CanMakePayments();
void FinishAllTransactions(void);
void RestoreCompletedTransactions();
void FinishAllTransactions();
void FinishTransactionByDate(const std::string& date);
std::string GetReceiptURL(void);
std::string GetReceiptURL();
void PurchaseProduct(const std::string& productID,
int quantity,

View file

@ -141,6 +141,10 @@ bool CanMakePayments() {
return [SKPaymentQueue canMakePayments];
}
void RestoreCompletedTransactions() {
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
void FinishAllTransactions() {
for (SKPaymentTransaction* transaction in SKPaymentQueue.defaultQueue
.transactions) {

View file

@ -51,7 +51,7 @@ class TransactionObserver {
const std::vector<Transaction>& transactions) = 0;
private:
InAppTransactionObserver* obeserver_;
InAppTransactionObserver* observer_;
base::WeakPtrFactory<TransactionObserver> weak_ptr_factory_;

View file

@ -183,14 +183,14 @@ Transaction::Transaction(const Transaction&) = default;
Transaction::~Transaction() = default;
TransactionObserver::TransactionObserver() : weak_ptr_factory_(this) {
obeserver_ = [[InAppTransactionObserver alloc]
observer_ = [[InAppTransactionObserver alloc]
initWithCallback:base::BindRepeating(
&TransactionObserver::OnTransactionsUpdated,
weak_ptr_factory_.GetWeakPtr())];
}
TransactionObserver::~TransactionObserver() {
[obeserver_ release];
[observer_ release];
}
} // namespace in_app_purchase