Index: content/container/payment-processor.html =================================================================== --- content/container/payment-processor.html (revision 0) +++ content/container/payment-processor.html (revision 0) @@ -0,0 +1,299 @@ + + + +Sample: Payment Processor + + + + + + + + +
+
+
+
+

+ This panel is in an iframe from another page in the same container domain:
+ +

+
App Name:

+
App Spec:

+
+
Payment Type:

+
Amount:

+
Message:

+
Items:

+
Ordered Time:

+
+ + +
+
+
+ + + Property changes on: content\container\payment-processor.html ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:eol-style + native Index: content/container/payment-records-processor.html =================================================================== --- content/container/payment-records-processor.html (revision 0) +++ content/container/payment-records-processor.html (revision 0) @@ -0,0 +1,388 @@ + + + +Sample: Payment Records Processor + + + + + + + + +
+
+
+
+

+ This panel is in an iframe from another page in the same container domain:
+ +

+ +
App Name:

+
App Spec:

+ +

+ +
+ +
+ + +
+
+
+ + + Property changes on: content\container\payment-records-processor.html ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:eol-style + native Index: content/container/sample-payment-container.html =================================================================== --- content/container/sample-payment-container.html (revision 0) +++ content/container/sample-payment-container.html (revision 0) @@ -0,0 +1,110 @@ + + + +Sample: Virtual Currency Payment + + + + + + + + +
+

OpenSocial Virtual Currency Proposal Revision #4 Demo

+ +

opensocial.requestPayment
opensocial.requestPaymentRecords

+
For detail, please checkout proposal doc, + discussion thread, and + code project. +
+

+ This page is a container page:
+ +

+
+
+ +
+
+ + + + + + + + + + + + Property changes on: content\container\sample-payment-container.html ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:eol-style + native Index: content/container/sample-payment.xml =================================================================== --- content/container/sample-payment.xml (revision 0) +++ content/container/sample-payment.xml (revision 0) @@ -0,0 +1,164 @@ + + + + + + + + + + + + #main {font-size:13px;} + .t {width:300px; margin-left:3px;} + .f {border-collapse:collapse;margin-left:10px;} + .f tbody tr td {font-size:12px;font-weight:bold;white-space:nowrap;vertical-align:top;} + .f tbody tr td span {font-size:10px;white-space:normal;} + .desc {color:#007F7F;} + + + + +
+

+ Here is the app domain inside the gadget iframe, usually different from container domain:
+ +

+


+ +
+ Make a Payment Request:
+ + + + + +
Amount:
Message:
Parameters:
Payment Type: + + +
+ +
+ + +
+ +
+ Make a Payment Records Request:
+ + + +
Max:
+ +
+ +
+ ]]> +
+
+ + Property changes on: content\container\sample-payment.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:eol-style + native Index: features/src/main/javascript/features/features.txt =================================================================== --- features/src/main/javascript/features/features.txt (revision 950850) +++ features/src/main/javascript/features/features.txt (working copy) @@ -51,6 +51,7 @@ features/opensocial-data-context/feature.xml features/opensocial-data/feature.xml features/opensocial-jsonrpc/feature.xml +features/opensocial-payment/feature.xml features/opensocial-reference/feature.xml features/opensocial-templates/feature.xml features/osapi/feature.xml Index: features/src/main/javascript/features/opensocial-base/feature.xml =================================================================== --- features/src/main/javascript/features/opensocial-base/feature.xml (revision 950850) +++ features/src/main/javascript/features/opensocial-base/feature.xml (working copy) @@ -26,5 +26,6 @@ + Index: features/src/main/javascript/features/opensocial-base/jsonpayment.js =================================================================== --- features/src/main/javascript/features/opensocial-base/jsonpayment.js (revision 0) +++ features/src/main/javascript/features/opensocial-base/jsonpayment.js (revision 0) @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*global opensocial */ + +/** + * Base interface for json based payment objects. + * NOTE: This class is mainly copied from jsonactivity.js + * + * @private + * @constructor + */ +var JsonPayment = function(opt_params, opt_skipConversions) { + opt_params = opt_params || {}; + if (!opt_skipConversions) { + JsonPayment.constructArrayObject(opt_params, 'items', JsonBillingItem); + } + opensocial.Payment.call(this, opt_params); +}; +JsonPayment.inherits(opensocial.Payment); + +JsonPayment.prototype.toJsonObject = function() { + var jsonObject = JsonPayment.copyFields(this.fields_); + + var oldBillingItems = jsonObject['items'] || []; + var newBillingItems = []; + for (var i = 0; i < oldBillingItems.length; i++) { + newBillingItems[i] = oldBillingItems[i].toJsonObject(); + } + jsonObject['items'] = newBillingItems; + + return jsonObject; +}; + + +// TODO: Split into separate class +var JsonBillingItem = function(opt_params) { + opensocial.BillingItem.call(this, opt_params); +}; +JsonBillingItem.inherits(opensocial.BillingItem); + +JsonBillingItem.prototype.toJsonObject = function() { + return JsonPayment.copyFields(this.fields_); +}; + + +// TODO: Pull this method into a common class, it is from jsonperson.js +JsonPayment.constructArrayObject = function(map, fieldName, className) { + var fieldValue = map[fieldName]; + if (fieldValue) { + for (var i = 0; i < fieldValue.length; i++) { + fieldValue[i] = new className(fieldValue[i]); + } + } +}; + +// TODO: Pull into common class as well +JsonPayment.copyFields = function(oldObject) { + var newObject = {}; + for (var field in oldObject) { + newObject[field] = oldObject[field]; + } + return newObject; +}; + Property changes on: features\src\main\javascript\features\opensocial-base\jsonpayment.js ___________________________________________________________________ Added: svn:mime-type + text/javascript Added: svn:eol-style + native Index: features/src/main/javascript/features/opensocial-jsonrpc/jsonrpccontainer.js =================================================================== --- features/src/main/javascript/features/opensocial-jsonrpc/jsonrpccontainer.js (revision 950850) +++ features/src/main/javascript/features/opensocial-jsonrpc/jsonrpccontainer.js (working copy) @@ -54,6 +54,14 @@ gadgets.rpc.register('shindig.requestShareApp_callback', JsonRpcContainer.requestShareAppCallback_); + + // For opensocial virtual currency extension. + gadgets.rpc.register('shindig.requestPayment_callback', + JsonRpcContainer.requestPaymentCallback_); + // For opensocial virtual currency extension. + gadgets.rpc.register('shindig.requestPaymentRecords_callback', + JsonRpcContainer.requestPaymentRecordsCallback_); + }; var JsonRpcRequestItem = function(rpc, opt_processData) { @@ -79,6 +87,115 @@ return this.environment_; }; + /** + * For OpenSocial VirtualCurrency Ext. + * The function invokes the whole process of a payment request. It calls the + * payment processor open function in parent container. + * + * @param {opensocial.Payment} payment The Payment object. + * @param {function(opensocial.ResponseItem)=} opt_callback The finishing + * callback function. + * @private + */ + JsonRpcContainer.prototype.requestPayment = function(payment, opt_callback) { + if (!payment) { + if (opt_callback) { + opt_callback(new opensocial.ResponseItem(null, payment, + opensocial.Payment.ResponseCode.MALFORMED_REQUEST, + 'Payment object is undefined.')); + } + return; + } + + var callbackId = "cId_" + Math.random(); + callbackIdStore[callbackId] = opt_callback; + // The rpc target is registered in container payment processor page. + gadgets.rpc.call('..', 'shindig.requestPayment', + null, + callbackId, + payment.toJsonObject()); + }; + + /** + * For OpenSocial VirtualCurrency Ext. The callback function of receives the + * returned results from the parent container. + * + * @param {Object.} paymentJson A jsonpayment object with + * parameters filled. + * @private + */ + JsonRpcContainer.requestPaymentCallback_ = function(callbackId, paymentJson) { + callback = callbackIdStore[callbackId]; + if (callback) { + var errorCode = opensocial.Payment.ResponseCode[ + paymentJson[opensocial.Payment.Field.RESPONSE_CODE]]; + var message = paymentJson[opensocial.Payment.Field.RESPONSE_MESSAGE]; + + paymentJson[opensocial.Payment.Field.RESPONSE_CODE] = errorCode; + var payment = new JsonPayment(paymentJson, false); + var responseItem = new opensocial.ResponseItem( + null, + payment, + (errorCode == opensocial.Payment.ResponseCode.OK ? null : errorCode), + message); + callback(responseItem); + } + }; + + /** + * For OpenSocial VirtualCurrency Ext. + * The function invokes the payment records panel in parent container. + * + * @param {function(opensocial.ResponseItem)=} opt_callback The finishing + * callback function. + * @param {Object.=} + * opt_params Additional parameters to pass to the request. + * @private + */ + JsonRpcContainer.prototype.requestPaymentRecords = function(opt_callback, + opt_params) { + var callbackId = "cId_" + Math.random(); + callbackIdStore[callbackId] = opt_callback; + + // The rpc target is registered in container payment records page. + gadgets.rpc.call('..', 'shindig.requestPaymentRecords', + null, callbackId, opt_params); + }; + + /** + * For OpenSocial VirtualCurrency Ext. The callback function of receives the + * returned results from the parent container. + * + * @param {Object.} opt_resultParams The fields set with + * result parameters. + * @private + */ + JsonRpcContainer.requestPaymentRecordsCallback_ = function(callbackId, + recordsJson) { + callback = callbackIdStore[callbackId]; + if (callback) { + + var errorCode = opensocial.Payment.ResponseCode[ + recordsJson[opensocial.Payment.Field.RESPONSE_CODE]]; + var message = recordsJson[opensocial.Payment.Field.RESPONSE_MESSAGE]; + + var records = []; + var payments = recordsJson['payments']; + for (var orderId in payments) { + records.push(new JsonPayment(payments[orderId], false)); + } + + var responseItem = new opensocial.ResponseItem( + null, + records, + (errorCode == opensocial.Payment.ResponseCode.OK ? null : errorCode), + message); + callback(responseItem); + } + }; + + + JsonRpcContainer.prototype.requestShareApp = function(recipientIds, reason, opt_callback, opt_params) { var callbackId = "cId_" + Math.random(); @@ -440,6 +557,14 @@ return new JsonRpcRequestItem(rpc); }; + JsonRpcContainer.prototype.newPayment = function(opt_params) { + return new JsonPayment(opt_params, true); + }; + + JsonRpcContainer.prototype.newBillingItem = function(opt_params) { + return new JsonBillingItem(opt_params); + }; + JsonRpcContainer.prototype.invalidateCache = function() { var rpc = { method : "cache.invalidate" }; var invalidationKeys = { invalidationKeys : ["@viewer"] }; Index: features/src/main/javascript/features/opensocial-payment/feature.xml =================================================================== --- features/src/main/javascript/features/opensocial-payment/feature.xml (revision 0) +++ features/src/main/javascript/features/opensocial-payment/feature.xml (revision 0) @@ -0,0 +1,27 @@ + + + + opensocial-payment + core.io + rpc + +