sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[ljcom] r10757: OPSC-346: LJ Shop interface updates to d...

Committer: vtroitsky
OPSC-346: LJ Shop interface updates to deal with payments from applications
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem.pm
U   trunk/cgi-bin/LJ/Pay/Payment.pm
U   trunk/cgi-bin/LJ/Widget/Payment.pm
U   trunk/cgi-bin/LJ/Widget/Shop/Cart.pm
U   trunk/cgi-bin/LJ/Widget/Shop/History.pm
U   trunk/htdocs/pay/index.bml.text.local
U   trunk/htdocs/stc/shop/shop.css
U   trunk/templates/Shop/Cart.tmpl
U   trunk/templates/Shop/CartTable.tmpl
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem.pm	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem.pm	2011-07-12 03:56:58 UTC (rev 10757)
@@ -48,6 +48,9 @@
     'tokens'        => 'LJ::Pay::Payment::PayItem::WalletTokens',
     'userhead'      => 'LJ::Pay::Payment::PayItem::UserHead',
     'donate'        => 'LJ::Pay::Payment::PayItem::Donate',
+    'appitem'       => 'LJ::Pay::Payment::PayItem::AppItem',
+    'royalty'       => 'LJ::Pay::Payment::PayItem::Royalty',
+
 );
 
 my @FREEZABLE_CLASSES = qw/
@@ -391,6 +394,10 @@
     return 0; # default value
 }
 
+sub is_visible {
+    return 1; # always visible in cart
+}
+
 sub error_must_use_tangible_method {
     ''
 }

Modified: trunk/cgi-bin/LJ/Pay/Payment.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment.pm	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/cgi-bin/LJ/Pay/Payment.pm	2011-07-12 03:56:58 UTC (rev 10757)
@@ -2059,7 +2059,7 @@
     my $dbh = LJ::get_db_writer();
     my $res = $dbh->selectall_arrayref(qq{
         SELECT * FROM payments
-        WHERE userid=? AND (forwhat="cart" OR forwhat="recbill")
+        WHERE userid=? AND (forwhat="cart" OR forwhat="recbill" OR forwhat="appbill")
         ORDER BY payid DESC
     }, { 'Slice' => {} }, $userid);
 

Modified: trunk/cgi-bin/LJ/Widget/Payment.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Payment.pm	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/cgi-bin/LJ/Widget/Payment.pm	2011-07-12 03:56:58 UTC (rev 10757)
@@ -332,7 +332,7 @@
     my @items = $cart->get_items;
 
     # alright, let's figure what should items display
-    @items = sort { $b->{'amt'} <=> $a->{'amt'} } @items;
+    @items = sort { $b->{'amt'} <=> $a->{'amt'} } grep { $_->is_visible() } @items;
 
     my @items_display;
 
@@ -388,7 +388,35 @@
             'method' => $method_class && $method_class->name_generic,
         );
     }
+    # add information from AppPayment
+    my %appbill_info = ();
+    if ($cart->get_forwhat eq 'appbill') {
+        # Load AppPayment for cart to get additional info
+        my $app_payment = LJ::API::Payments::AppPayment->new(cart_obj => $cart);
+        my $app = $app_payment->app;
+        my $submitted_time = $app_payment->get_submitted_time;
 
+        my $method_code = $cart->get_method;
+        my $method_class = LJ::Pay::Method->class_by_code($method_code);
+
+
+        # Show information about the application payment
+        %appbill_info = (
+            'cart_appbill' => 1,
+            'app' => ($app ? LJ::Lang::ml('pay.cart.application.name', { app_name => $app->name, app_url => $app->href }) : 'APPLICATION'),
+            'description' => $app_payment->get_message,
+            'orderid' => $app_payment->get_order_id,
+            'is_sandbox' => $app_payment->get_is_sandbox,
+            'date_paid' => LJ::TimeUtil->fancy_time_format($submitted_time, 'min'),
+            'status' => $app_payment->get_status,
+            'status_string' => LJ::Lang::ml('pay.cart.application.status.'.$app_payment->get_status),
+          #  'status_string' => LJ::Lang::ml('shop.cart.appbill.state.'.$app_payment->get_state),
+            'type' => $app_payment->get_type,
+            'method' => $method_class && $method_class->name_generic,
+            'message' => $app_payment->get_response_message,
+        );
+        $appbill_info{'message'} = $app_payment->get_response_message if ($app_payment->get_response_message);
+    }
     # compile data
     return {
         'items' => \@items_display,
@@ -398,6 +426,7 @@
         'can_checkout' => $cart->get_forwhat eq 'cart' && $cart->can_checkout,
         'cart_valid' => $cart->recheck,
         %paid_info,
+        %appbill_info,
     };
 
 }

Modified: trunk/cgi-bin/LJ/Widget/Shop/Cart.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Shop/Cart.pm	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/cgi-bin/LJ/Widget/Shop/Cart.pm	2011-07-12 03:56:58 UTC (rev 10757)
@@ -63,7 +63,7 @@
     my $remote = LJ::get_remote();
 
     # prepare flags "show dollars" and "show tokens"
-    $self->{'price_show_dollars'} = 1;
+    $self->{'price_show_dollars'} = ($cart->get_forwhat eq 'appbill' ? 0 : 1);
     $self->{'price_show_tokens'} =
         LJ::Pay::Wallet->is_user_eligible($remote) &&
         !LJ::Pay::Payment::PayItem::WalletTokens->present_in($cart);
@@ -224,6 +224,12 @@
         unless $self->cart->get_forwhat eq 'cart';
 }
 
+sub assert_cart_appbill {
+    my ($self) = @_;
+    $self->ml_error('shop.cart.error.nonappbill')
+         unless $self->cart->get_forwhat eq 'appbill';
+}
+
 sub process_post_request {
     my ($self) = @_;
 
@@ -398,6 +404,23 @@
         return LJ::Request->redirect($cart2->cart_link);
     }
 
+    if ($act eq 'deliver') {
+        $self->assert_cart_appbill;
+        $self->assert_cart_paid;
+        # TODO: Ensure we can rediliver the appbill
+
+        return LJ::Request->redirect_to_self;
+    }
+
+    if ($act eq 'refund') {
+        $self->assert_cart_appbill;
+        $self->assert_cart_paid;
+
+        # TODO: Ensure we can refund the appbill
+
+        return LJ::Request->redirect_to_self;
+    }
+
     $self->ml_error('error.invalidform');
 
 }

Modified: trunk/cgi-bin/LJ/Widget/Shop/History.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Shop/History.pm	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/cgi-bin/LJ/Widget/Shop/History.pm	2011-07-12 03:56:58 UTC (rev 10757)
@@ -43,8 +43,30 @@
             sprintf('$%.2f USD', $cart->get_amount);
 
         my $forwhat = $cart->get_forwhat;
-        my $forwhat_string = LJ::Lang::ml("shop.history.forwhat.$forwhat") || "[$forwhat]";
+        my $forwhat_string;
 
+        if($forwhat eq 'appbill') {
+            my $app_payment;
+            eval {
+                $app_payment = LJ::API::Payments::AppPayment->new(cart_obj => $cart);
+            };
+            if($@) {
+                $forwhat_string = "[ERROR PAYMENT]";
+            } else {
+                my $app = $app_payment->app;    # get application object
+
+                # override status_string for appbill payments
+               # my $state = $app_payment->get_state;
+               # $status_string = LJ::Lang::ml("shop.cart.appbill.state.$state");
+                $status_string = LJ::Lang::ml('pay.cart.application.status.'.$app_payment->get_status);
+
+                $forwhat_string = ($app ? LJ::Lang::ml("shop.history.forwhat.appbill", { app_name => $app->name, app_url => $app->href }) || "[appbill]" : "[NO APP]");
+                $status_string .= ' '.LJ::Lang::ml("shop.cart.appbill.sandbox") if ($app_payment->get_is_sandbox);
+            }
+        } else {
+            $forwhat_string = LJ::Lang::ml("shop.history.forwhat.$forwhat") || "[$forwhat]";
+        }
+
         push @ret, {
             'date'          => LJ::TimeUtil->fancy_time_format($datesent, 'day'),
             'string'        => $cart->get_cart_as_string,
@@ -87,10 +109,11 @@
         my $token_xfer = 0;
         if ($logitem->action eq ACTION_ADD) {
             my $buyer_userid = $logitem->cart->get_userid;
-            if ($logitem->userid == $buyer_userid) {
+            my $cart = $logitem->cart;
+            my $is_royalty = LJ::Pay::Payment::PayItem::Royalty->present_in($cart);
+            if ($logitem->userid == $buyer_userid && !$is_royalty) {
                 $des = LJ::Lang::ml('wallet.widget.history.des.buy');
             } else {
-                my $cart = $logitem->cart;
                 if ($logitem->item->get_anon || !$buyer_userid) {
                     $des = LJ::Lang::ml('wallet.widget.history.des.anon');
                 } else {
@@ -107,6 +130,16 @@
                             'from' => $buyer->ljuser_display,
                             'url'  => ( $entry && $entry->valid ) ? $entry->url : '',
                         });
+                    } elsif ($is_royalty) { 
+                        my $app_payment = LJ::API::Payments::AppPayment->new(cart_obj => $cart);
+                        my $app = $app_payment->app;
+                        my $item = $cart->get_item(LJ::Pay::Payment::PayItem::Royalty->item);
+                        $des = LJ::Lang::ml('wallet.widget.history.des.rcvd_royalty', {
+                            'percent' => $item->get_subitem,
+                            'app_name' => $app->name,
+                            'app_url' => $app->href,
+                            'from' => $buyer->ljuser_display,
+                        });
                     } else {
                         $des = LJ::Lang::ml('wallet.widget.history.des.rcvd', {
                             'from' => $buyer->ljuser_display,
@@ -139,6 +172,17 @@
                     'to' => $rcpt->ljuser_display,
                     'url' => ( $entry && $entry->valid ) ? $entry->url : '',
                 });
+            } elsif (LJ::Pay::Payment::PayItem::AppItem->present_in($cart)) {
+                my @items = $cart->get_items;
+                my $app = $items[0]->get_app;
+                my $lj_app = ($app ? $app->ljapp_display : 'NO APPLICATION');
+                my $cart_link = $cart->cart_link;
+                $des = LJ::Lang::ml('wallet.widget.history.des.appitem', {
+                    'lj_app' => $lj_app,
+                    'app_url' => $app->href,
+                    'app_name' => $app->name,
+                    'cart_link' => $cart_link,
+                });
             } else {
                 my $cart_link = $cart->cart_link;
                 $des = LJ::Lang::ml('wallet.widget.history.des.order', {

Modified: trunk/htdocs/pay/index.bml.text.local
===================================================================
--- trunk/htdocs/pay/index.bml.text.local	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/htdocs/pay/index.bml.text.local	2011-07-12 03:56:58 UTC (rev 10757)
@@ -38,6 +38,8 @@
 
 .note.norefund=All purchases, including but not limited to unused portions of paid account time and gift certificates, are non-refundable.
 
+.note.sandbox.payment=This is the test payment, so no actual fund transfer was performed.
+
 .paidfor.header=Paid for
 
 .paidfor.text=This order has been paid for on [[date]].

Modified: trunk/htdocs/stc/shop/shop.css
===================================================================
--- trunk/htdocs/stc/shop/shop.css	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/htdocs/stc/shop/shop.css	2011-07-12 03:56:58 UTC (rev 10757)
@@ -1376,6 +1376,12 @@
 	.b-cart-successful {
 		color: #428C20;
 		}
+    .b-cart-inprogress {
+        color: #a9a93c
+        }
+    .b-cart-failed {
+        color: #a94f3c
+        }
 	.b-cart-paidinfo {
 		margin:0 0 10px;
 		}

Modified: trunk/templates/Shop/Cart.tmpl
===================================================================
--- trunk/templates/Shop/Cart.tmpl	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/templates/Shop/Cart.tmpl	2011-07-12 03:56:58 UTC (rev 10757)
@@ -3,6 +3,41 @@
 
 <div class="b-cart">
 <TMPL_UNLESS name="empty_cart">
+     <TMPL_IF name="cart_appbill">
+        <table class="b-cart-paidinfo">
+                <tr>
+                    <th><TMPL_VAR expr="ml('shop.cart.appbill_info.app')"></th>
+                    <td><TMPL_VAR app></td>
+                </tr>
+                <tr>
+                    <th><TMPL_VAR expr="ml('shop.cart.appbill_info.orderid')"></th>
+                    <td><TMPL_VAR orderid></td>
+                </tr>
+                <tr>
+                    <th><TMPL_VAR expr="ml('shop.cart.appbill_info.description')"></th>
+                    <td><TMPL_VAR description></td>
+                </tr>
+                <tr>
+					<th><TMPL_VAR expr="ml('shop.cart.paid_info.date')"></th>
+					<td><TMPL_VAR date_paid></td>
+				</tr>
+				<tr>
+					<th><TMPL_VAR expr="ml('shop.cart.paid_info.method')"></th>
+					<td><TMPL_VAR method></td>
+				</tr>
+				<tr>
+					<th><TMPL_VAR expr="ml('shop.cart.paid_info.status')"></th>
+					<td class="b-cart-<TMPL_VAR status>"><TMPL_VAR expr="status_string"> <TMPL_IF name="is_sandbox"> <TMPL_VAR expr="ml('shop.cart.appbill.sandbox')"></TMPL_IF></td>
+				</tr>
+                <TMPL_IF name="message">
+                <tr>
+                    <th><TMPL_VAR expr="ml('shop.cart.appbill_info.message')"></th>
+                    <td><TMPL_VAR message></td>
+                </tr>
+                </TMPL_IF>
+
+        </table>
+     <TMPL_ELSE>
 	 <TMPL_IF name="cart_paid">
 		<table class="b-cart-paidinfo">
 				<tr>
@@ -19,6 +54,7 @@
 				</tr>
 		</table>
 	 </TMPL_IF>
+     </TMPL_IF>
 	 <form action="" method="post">
 		<TMPL_VAR form_auth>
 		<input type="hidden" name="act" value="delete">
@@ -87,7 +123,11 @@
 			 </TMPL_UNLESS>
 		</div>
 	</div>
+    <TMPL_IF name="cart_appbill">
+        <TMPL_IF name="is_sandbox"><p class="b-bubble b-bubble-alert b-bubble-intext"><TMPL_VAR expr="ml('/pay/index.bml.note.sandbox.payment')"></p></TMPL_IF>
+    <TMPL_ELSE>
 	<p class="b-bubble b-bubble-alert b-bubble-intext"><TMPL_VAR expr="ml('/pay/index.bml.note.norefund')"></p>
+    </TMPL_IF>
 	<TMPL_IF name="allow_repeat">
 		<div class="b-cart-repeat">
 		<form action="" method="post">
@@ -98,4 +138,4 @@
 		</div>
 	</TMPL_IF>
 </TMPL_UNLESS>
-</div>
\ No newline at end of file
+</div>

Modified: trunk/templates/Shop/CartTable.tmpl
===================================================================
--- trunk/templates/Shop/CartTable.tmpl	2011-07-12 03:40:20 UTC (rev 10756)
+++ trunk/templates/Shop/CartTable.tmpl	2011-07-12 03:56:58 UTC (rev 10757)
@@ -13,6 +13,7 @@
 				<input type="checkbox" name="delete" value="<TMPL_VAR id>" id="delete-<TMPL_VAR id>" />
 				<label for="delete-<TMPL_VAR id>"><TMPL_VAR name></label>
 			<TMPL_ELSE>
+                <TMPL_IF name="image_url"><img src="<TMPL_VAR image_url>"></TMPL_IF>
 				<TMPL_VAR name>
 			</TMPL_UNLESS>
 		</td>

Tags: css, ljcom, local, pm, sunnyman, tmpl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments