main.qml Example File
paymentservice/assets/main.qml
import bb.cascades 1.0
import com.sample.payment 1.0
TabbedPane {
property int i: 0
property string receiptArea: ""
onActiveTabChanged: {
purchases.text = ""
purchaseId.text = ""
}
Tab {
title: qsTr ("Buy")
imageSource: "asset:///images/buy.png"
Page {
Container {
rightPadding: 10
leftPadding: 10
background: Color.Black
Container {
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Top
rightPadding: 100
layoutProperties: StackLayoutProperties {
spaceQuota: -1
}
ImageView {
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Top
topMargin: 20
imageSource: "asset:///images/goods_title.png"
preferredWidth: 200
preferredHeight: 100
}
}
Container {
id: imagine
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Top
topPadding: 5
rightPadding: 40
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
layoutProperties: StackLayoutProperties {
spaceQuota: -1
}
ImageView {
imageSource: "asset:///images/banana.png"
preferredWidth: 128
preferredHeight: 86
rightMargin: 30
}
ImageView {
imageSource: "asset:///images/leek.png"
preferredWidth: 128
preferredHeight: 86
rightMargin: 30
}
ImageView {
imageSource: "asset:///images/strawberries.png"
preferredWidth: 128
preferredHeight: 86
}
}
Container {
topMargin: 5
bottomMargin: 20
layoutProperties: StackLayoutProperties {
spaceQuota: -1
}
background: Color.create ("#615A5F")
Divider {
}
}
Container {
horizontalAlignment: HorizontalAlignment.Center
topPadding: 5
rightPadding: 40
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
layoutProperties: StackLayoutProperties {
spaceQuota: -1
}
translationX: 1000
Button {
text: qsTr ("BUY")
onClicked: {
receipt.text = ""
message.visible = false
paymentControl.purchase (paymentControl.id, paymentControl.sku, paymentControl.name, paymentControl.metadata)
}
}
Button {
text: qsTr ("SUB TERMS")
onClicked: {
paymentControl.getSubscriptionTerms (paymentControl.id, paymentControl.sku)
}
}
animations: [
TranslateTransition {
id: showButtons
toX: 0
duration: 1000
}
]
}
Container {
layoutProperties: StackLayoutProperties {
spaceQuota: 5
}
translationY: 1000
ListView {
dataModel: XmlDataModel {
source: "models/goods.xml"
}
listItemComponents: [
ListItemComponent {
type: "digitalgood"
DigitalGood {
}
}
]
onTriggered: {
clearSelection()
select(indexPath)
}
onSelectionChanged: {
resetSubscriptionText()
if(selected) {
receipt.text = ""
message.visible = false
var chosenItem = dataModel.data (indexPath)
paymentControl.id = chosenItem.id
paymentControl.sku = chosenItem.sku
paymentControl.name = chosenItem.name
paymentControl.metadata = chosenItem.metadata
paymentControl.getPrice (paymentControl.id, paymentControl.sku)
}
}
}
animations: [
TranslateTransition {
id: lists
toY: 0
duration: 1000
}
]
}
Container {
horizontalAlignment: HorizontalAlignment.Fill
layout: DockLayout {}
Label {
id: priceLabel
horizontalAlignment: HorizontalAlignment.Left
verticalAlignment: VerticalAlignment.Center
pivotY: preferredHeight / 2
text: qsTr ("$$$")
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.create ("#E138AA")
}
animations: [
SequentialAnimation {
id: priceAnim
animations: [
RotateTransition {
toAngleZ: 15
duration: 700 * 0.4
delay: 200
},
RotateTransition {
toAngleZ: -5
duration: 700 * 0.3
},
RotateTransition {
toAngleZ: 0
duration: 700 * 0.3
}
]
}
]
}
Label {
id: subscription
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Center
text: qsTr ("CHECK subscription")
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.White
}
onTouch: {
if ( event.isDown() )
paymentControl.checkSubscriptionStatus (paymentControl.id, paymentControl.sku)
}
}
}
MessageBox {
id: message
visible: false
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
onTouch: message.visible = false
}
Container {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Top
layoutProperties: StackLayoutProperties {
spaceQuota: 4
}
layout: DockLayout {}
Container {
background: Color.White
TextArea {
id: receipt
editable: false
hintText: ""
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.Black
}
}
}
}
attachedObjects: [
QTimer {
id: timer1
singleShot: false
onTimeout: {
animTextAreaText ();
i ++;
}
},
PaymentServiceControl {
id: paymentControl
property string id
property string sku
property string name
property string metadata
onPriceResponseSuccess: {
priceLabel.text = price;
priceAnim.play ()
}
onPurchaseResponseSuccess: {
i = 0
receiptArea = receiptString
timer1.start (50);
}
onExistingPurchasesResponseSuccess: {
purchases.text = receiptsString
}
onSubscriptionTermsResponseSuccess: {
message.text = qsTr ("Price: %1\nInitialPeriod: %2\nRenewalPrice: %3\nRenewalPeriod: %4").arg(price).arg(initialPeriod).arg(renewalPrice).arg(renewalPeriod)
message.visible = true
}
onCancelSubscriptionResponseSuccess: {
cancellations.text = (cancelled ? qsTr ("Canceled? yes") : qsTr ("Canceled? no"))
}
onCheckStatusResponseSuccess: {
subscription.textStyle.color = Color.Green
subscription.text = (status ? qsTr ("Active? yes") : qsTr("Active? no"))
}
onInfoResponseError: {
}
}
]
}
onCreationCompleted: animScreen ()
}
}
function animScreen () {
lists.play ();
showButtons.play ();
}
function animTextAreaText () {
receipt.text += receiptArea.charAt (i);
if (i >= receiptArea.length) {
timer1.stop ();
}
}
function resetSubscriptionText() {
subscription.textStyle.color = Color.White
subscription.text = qsTr ("CHECK subscription")
}
Tab {
title: qsTr ("Purchases")
imageSource: "asset:///images/purchases.png"
Page {
Container {
topPadding: 20
leftPadding: 20
rightPadding: 20
Button {
horizontalAlignment: HorizontalAlignment.Center
text: qsTr ("Purchases")
onClicked: paymentControl.getExisting (false);
}
TextArea {
id: purchases
editable: false
}
}
}
}
Tab {
title: qsTr ("Cancellation")
imageSource: "asset:///images/cancelpurchases.png"
Page {
Container {
topPadding: 20
leftPadding: 20
rightPadding: 20
Label {
text: qsTr ("Purchase ID")
textStyle {
base: SystemDefaults.TextStyles.TitleText
}
}
TextField {
id: purchaseId
horizontalAlignment: HorizontalAlignment.Fill
}
Button {
horizontalAlignment: HorizontalAlignment.Center
topMargin: 50
text: qsTr ("Cancel")
onClicked: {
paymentControl.cancelSubscription (purchaseId.text)
}
}
TextArea {
id: cancellations
editable: false
backgroundVisible: false
}
}
}
}
}