Payment should be part of Transaction
This follows The SKPayment API, and makes our JS wrappers easier to implement.
This commit is contained in:
parent
635b753ecd
commit
2dd545ebda
5 changed files with 13 additions and 23 deletions
|
@ -40,6 +40,7 @@ struct Converter<in_app_purchase::Transaction> {
|
|||
dict.Set("transactionState", val.transactionState);
|
||||
dict.Set("errorCode", val.errorCode);
|
||||
dict.Set("errorMessage", val.errorMessage);
|
||||
dict.Set("payment", val.payment);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
};
|
||||
|
@ -82,9 +83,8 @@ void InAppPurchase::PurchaseProduct(const std::string& product_id,
|
|||
}
|
||||
|
||||
void InAppPurchase::OnTransactionUpdated(
|
||||
const in_app_purchase::Payment& payment,
|
||||
const in_app_purchase::Transaction& transaction) {
|
||||
Emit("transaction-updated", payment, transaction);
|
||||
Emit("transaction-updated", transaction);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
|
@ -32,7 +32,6 @@ class InAppPurchase: public mate::EventEmitter<InAppPurchase>,
|
|||
|
||||
// TransactionObserver:
|
||||
void OnTransactionUpdated(
|
||||
const in_app_purchase::Payment& payment,
|
||||
const in_app_purchase::Transaction& transaction) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -32,6 +32,7 @@ struct Transaction {
|
|||
int errorCode = 0;
|
||||
std::string errorMessage = "";
|
||||
std::string transactionState = "";
|
||||
Payment payment;
|
||||
};
|
||||
|
||||
// --------------------------- Classes ---------------------------
|
||||
|
@ -41,8 +42,7 @@ class TransactionObserver {
|
|||
TransactionObserver();
|
||||
virtual ~TransactionObserver();
|
||||
|
||||
virtual void OnTransactionUpdated(const Payment& payment,
|
||||
const Transaction& transaction) = 0;
|
||||
virtual void OnTransactionUpdated(const Transaction& transaction) = 0;
|
||||
|
||||
private:
|
||||
InAppTransactionObserver* obeserver_;
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
namespace {
|
||||
|
||||
using InAppTransactionCallback =
|
||||
base::RepeatingCallback<void(const in_app_purchase::Payment&,
|
||||
const in_app_purchase::Transaction&)>;
|
||||
base::RepeatingCallback<void(const in_app_purchase::Transaction&)>;
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -60,10 +59,6 @@ using InAppTransactionCallback =
|
|||
return;
|
||||
}
|
||||
|
||||
// Convert the payment.
|
||||
in_app_purchase::Payment paymentStruct;
|
||||
paymentStruct = [self skPaymentToStruct:transaction.payment];
|
||||
|
||||
// Convert the transaction.
|
||||
in_app_purchase::Transaction transactionStruct;
|
||||
transactionStruct = [self skPaymentTransactionToStruct:transaction];
|
||||
|
@ -71,7 +66,7 @@ using InAppTransactionCallback =
|
|||
// Send the callback to the browser thread.
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(callback_, paymentStruct, transactionStruct));
|
||||
base::Bind(callback_, transactionStruct));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,10 +92,6 @@ using InAppTransactionCallback =
|
|||
- (in_app_purchase::Payment)skPaymentToStruct:(SKPayment*)payment {
|
||||
in_app_purchase::Payment paymentStruct;
|
||||
|
||||
if (payment == nil) {
|
||||
return paymentStruct;
|
||||
}
|
||||
|
||||
if (payment.productIdentifier != nil) {
|
||||
paymentStruct.productIdentifier = [payment.productIdentifier UTF8String];
|
||||
}
|
||||
|
@ -121,10 +112,6 @@ using InAppTransactionCallback =
|
|||
(SKPaymentTransaction*)transaction {
|
||||
in_app_purchase::Transaction transactionStruct;
|
||||
|
||||
if (transaction == nil) {
|
||||
return transactionStruct;
|
||||
}
|
||||
|
||||
if (transaction.transactionIdentifier != nil) {
|
||||
transactionStruct.transactionIdentifier =
|
||||
[transaction.transactionIdentifier UTF8String];
|
||||
|
@ -152,6 +139,10 @@ using InAppTransactionCallback =
|
|||
] objectAtIndex:transaction.transactionState] UTF8String];
|
||||
}
|
||||
|
||||
if (transaction.payment != nil) {
|
||||
transactionStruct.payment = [self skPaymentToStruct:transaction.payment];
|
||||
}
|
||||
|
||||
return transactionStruct;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,6 @@ Emitted when a transaction has been updated.
|
|||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `payment` Object
|
||||
* `productIdentifier` String
|
||||
* `quantity` Integer
|
||||
* `transaction` Object
|
||||
* `transactionIdentifier` String
|
||||
* `transactionDate` String
|
||||
|
@ -25,6 +22,9 @@ Returns:
|
|||
* `transactionState` String - The transaction sate (`"purchasing"`, `"purchased"`, `"failed"`, `"restored"`, or `"deferred"`)
|
||||
* `errorCode` Integer
|
||||
* `errorMessage` String
|
||||
* `payment` Object
|
||||
* `productIdentifier` String
|
||||
* `quantity` Integer
|
||||
|
||||
## Methods
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue