Payment should be part of Transaction

This follows The SKPayment API, and makes our JS wrappers easier to
implement.
This commit is contained in:
Cheng Zhao 2018-01-10 17:06:27 +09:00
parent 635b753ecd
commit 2dd545ebda
5 changed files with 13 additions and 23 deletions

View file

@ -40,6 +40,7 @@ struct Converter<in_app_purchase::Transaction> {
dict.Set("transactionState", val.transactionState); dict.Set("transactionState", val.transactionState);
dict.Set("errorCode", val.errorCode); dict.Set("errorCode", val.errorCode);
dict.Set("errorMessage", val.errorMessage); dict.Set("errorMessage", val.errorMessage);
dict.Set("payment", val.payment);
return dict.GetHandle(); return dict.GetHandle();
} }
}; };
@ -82,9 +83,8 @@ void InAppPurchase::PurchaseProduct(const std::string& product_id,
} }
void InAppPurchase::OnTransactionUpdated( void InAppPurchase::OnTransactionUpdated(
const in_app_purchase::Payment& payment,
const in_app_purchase::Transaction& transaction) { const in_app_purchase::Transaction& transaction) {
Emit("transaction-updated", payment, transaction); Emit("transaction-updated", transaction);
} }
} // namespace api } // namespace api

View file

@ -32,7 +32,6 @@ class InAppPurchase: public mate::EventEmitter<InAppPurchase>,
// TransactionObserver: // TransactionObserver:
void OnTransactionUpdated( void OnTransactionUpdated(
const in_app_purchase::Payment& payment,
const in_app_purchase::Transaction& transaction) override; const in_app_purchase::Transaction& transaction) override;
private: private:

View file

@ -32,6 +32,7 @@ struct Transaction {
int errorCode = 0; int errorCode = 0;
std::string errorMessage = ""; std::string errorMessage = "";
std::string transactionState = ""; std::string transactionState = "";
Payment payment;
}; };
// --------------------------- Classes --------------------------- // --------------------------- Classes ---------------------------
@ -41,8 +42,7 @@ class TransactionObserver {
TransactionObserver(); TransactionObserver();
virtual ~TransactionObserver(); virtual ~TransactionObserver();
virtual void OnTransactionUpdated(const Payment& payment, virtual void OnTransactionUpdated(const Transaction& transaction) = 0;
const Transaction& transaction) = 0;
private: private:
InAppTransactionObserver* obeserver_; InAppTransactionObserver* obeserver_;

View file

@ -18,8 +18,7 @@
namespace { namespace {
using InAppTransactionCallback = using InAppTransactionCallback =
base::RepeatingCallback<void(const in_app_purchase::Payment&, base::RepeatingCallback<void(const in_app_purchase::Transaction&)>;
const in_app_purchase::Transaction&)>;
} // namespace } // namespace
@ -60,10 +59,6 @@ using InAppTransactionCallback =
return; return;
} }
// Convert the payment.
in_app_purchase::Payment paymentStruct;
paymentStruct = [self skPaymentToStruct:transaction.payment];
// Convert the transaction. // Convert the transaction.
in_app_purchase::Transaction transactionStruct; in_app_purchase::Transaction transactionStruct;
transactionStruct = [self skPaymentTransactionToStruct:transaction]; transactionStruct = [self skPaymentTransactionToStruct:transaction];
@ -71,7 +66,7 @@ using InAppTransactionCallback =
// Send the callback to the browser thread. // Send the callback to the browser thread.
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, 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)skPaymentToStruct:(SKPayment*)payment {
in_app_purchase::Payment paymentStruct; in_app_purchase::Payment paymentStruct;
if (payment == nil) {
return paymentStruct;
}
if (payment.productIdentifier != nil) { if (payment.productIdentifier != nil) {
paymentStruct.productIdentifier = [payment.productIdentifier UTF8String]; paymentStruct.productIdentifier = [payment.productIdentifier UTF8String];
} }
@ -121,10 +112,6 @@ using InAppTransactionCallback =
(SKPaymentTransaction*)transaction { (SKPaymentTransaction*)transaction {
in_app_purchase::Transaction transactionStruct; in_app_purchase::Transaction transactionStruct;
if (transaction == nil) {
return transactionStruct;
}
if (transaction.transactionIdentifier != nil) { if (transaction.transactionIdentifier != nil) {
transactionStruct.transactionIdentifier = transactionStruct.transactionIdentifier =
[transaction.transactionIdentifier UTF8String]; [transaction.transactionIdentifier UTF8String];
@ -152,6 +139,10 @@ using InAppTransactionCallback =
] objectAtIndex:transaction.transactionState] UTF8String]; ] objectAtIndex:transaction.transactionState] UTF8String];
} }
if (transaction.payment != nil) {
transactionStruct.payment = [self skPaymentToStruct:transaction.payment];
}
return transactionStruct; return transactionStruct;
} }

View file

@ -15,9 +15,6 @@ Emitted when a transaction has been updated.
Returns: Returns:
* `event` Event * `event` Event
* `payment` Object
* `productIdentifier` String
* `quantity` Integer
* `transaction` Object * `transaction` Object
* `transactionIdentifier` String * `transactionIdentifier` String
* `transactionDate` String * `transactionDate` String
@ -25,6 +22,9 @@ Returns:
* `transactionState` String - The transaction sate (`"purchasing"`, `"purchased"`, `"failed"`, `"restored"`, or `"deferred"`) * `transactionState` String - The transaction sate (`"purchasing"`, `"purchased"`, `"failed"`, `"restored"`, or `"deferred"`)
* `errorCode` Integer * `errorCode` Integer
* `errorMessage` String * `errorMessage` String
* `payment` Object
* `productIdentifier` String
* `quantity` Integer
## Methods ## Methods