Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add currency property in InApp.Product #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public void onProductDataResponse(ProductDataResponse response) {
product.productId = i.getSku();
product.title = i.getTitle();
product.description = i.getDescription();

product.currency = ""; // does not exist in amazon

String localizedPrice = i.getPrice();
String price = localizedPrice.replaceAll("[^\\d.]", "");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class InAppProduct {
*/
public String localizedPrice;

/**
* The currency code in ISO 4217 format.
*/
public String currency;

/**
* Transforms a product information into a JSON object.
*
Expand All @@ -49,6 +54,7 @@ public JSONObject toJSON() {
o.putOpt("description", description);
o.putOpt("localizedPrice", localizedPrice);
o.put("price", price);
o.put("currency", currency);
} catch (JSONException e) {
e.printStackTrace();
}
Expand All @@ -68,6 +74,7 @@ static InAppProduct fromJSON(JSONObject object) {
product.description = object.optString("description");
product.localizedPrice = object.optString("localizedPrice");
product.price = object.optDouble("price");
product.currency = object.optString("currency");
return product;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private InAppProduct JSONObjectToInapp(JSONObject object) {
product.localizedPrice = object.optString("price");
product.title = object.optString("title");
product.description = object.optString("description");
product.currency = object.optString("price_currency_code");
String price;
if (object.has("price_amount_micros")) {
price = String.valueOf(((float) object.optInt("price_amount_micros")) / 1000000);
Expand Down
19 changes: 12 additions & 7 deletions src/atomic/ios/appstore/LDInAppService.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu
NSError * error = nil;
if (response.invalidProductIdentifiers.count > 0) {
NSString * msg = @"Invalid products: ";
for (NSString * pid in response.invalidProductIdentifiers) {
msg = [msg stringByAppendingString:pid];
msg = [msg stringByAppendingString:@","];
}
error = MAKE_ERROR(0, msg);
for (NSString * pid in response.invalidProductIdentifiers) {
msg = [msg stringByAppendingString:pid];
msg = [msg stringByAppendingString:@","];
}
error = MAKE_ERROR(0, msg);
}
_completion(response.products, error);
[self dispose:request];
Expand All @@ -101,7 +101,7 @@ - (void)dispose:(SKRequest*)request {
LDInAppFetchDelegate * this = self;
//simulate CFAutoRelease for iOS 6
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
CFRelease((__bridge CFTypeRef)(this));
CFRelease((__bridge CFTypeRef)(this));
});
}

Expand Down Expand Up @@ -377,6 +377,11 @@ -(void) setLudeiServerValidationHandler

#pragma mark SKPaymentTransactionObserver

- (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)product {
NSLog(@"Payment Queue Product = %@", product);
return true;
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions NS_AVAILABLE_IOS(3_0)
{
if (!_started) {
Expand All @@ -398,7 +403,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran
[self notifyPurchaseStarted:transaction.payment.productIdentifier];
default:
break;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public void onProductDataResponse(ProductDataResponse response) {
product.productId = i.getSku();
product.title = i.getTitle();
product.description = i.getDescription();

product.currency = ""; // does not exist in amazon

String localizedPrice = i.getPrice();
String price = localizedPrice.replaceAll("[^\\d.]", "");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class InAppProduct {
*/
public String localizedPrice;

/**
* The currency code in ISO 4217 format.
*/
public String currency;

/**
* Transforms a product information into a JSON object.
*
Expand All @@ -49,6 +54,7 @@ public JSONObject toJSON() {
o.putOpt("description", description);
o.putOpt("localizedPrice", localizedPrice);
o.put("price", price);
o.put("currency", currency);
} catch (JSONException e) {
e.printStackTrace();
}
Expand All @@ -68,6 +74,7 @@ static InAppProduct fromJSON(JSONObject object) {
product.description = object.optString("description");
product.localizedPrice = object.optString("localizedPrice");
product.price = object.optDouble("price");
product.currency = object.optString("currency");
return product;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private InAppProduct JSONObjectToInapp(JSONObject object) {
product.localizedPrice = object.optString("price");
product.title = object.optString("title");
product.description = object.optString("description");
product.currency = object.optString("price_currency_code");
String price;
if (object.has("price_amount_micros")) {
price = String.valueOf(((float) object.optInt("price_amount_micros")) / 1000000);
Expand Down
2 changes: 1 addition & 1 deletion src/cordova/common/www/cocoon_inapps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/js/cocoon_inapps.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,15 @@
* @property {string} Cocoon.InApp.Product.description The description of the product.
* @property {number} Cocoon.InApp.Product.localizedPrice The price of the product in local currency.
* @property {number} Cocoon.InApp.Product.price The price of the product.
* @property {string} Cocoon.InApp.Product.currency The currency code in ISO 4217 format.
*/
extension.Product = {
productId: "productId",
title: "title",
description: "description",
localizedPrice: "localizedPrice",
price: "price"
price: "price",
currency: "currency"
};

/**
Expand Down