wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[ljcom] r9429: LJSUP-6582. Custom Userheads: SMS paymen...

Committer: gprochaev
LJSUP-6582. Custom Userheads: SMS payments. Server side.

A   trunk/cgi-bin/LJ/Widget/IPPU/UserHeadSmsPay.pm
A   trunk/htdocs/js/widget_ippu/userheadsmspay.js
Added: trunk/cgi-bin/LJ/Widget/IPPU/UserHeadSmsPay.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/IPPU/UserHeadSmsPay.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/Widget/IPPU/UserHeadSmsPay.pm	2010-08-27 09:02:06 UTC (rev 9429)
@@ -0,0 +1,77 @@
+package LJ::Widget::IPPU::UserHeadSmsPay;
+
+use strict;
+use base qw(LJ::Widget::IPPU);
+use Carp qw(croak);
+
+sub need_res {
+    return qw( js/widgets/shopvgift.js stc/widgets/shopvgift.css );
+}
+
+sub authas { 1 }
+
+sub render_body {
+    my ($class, %opts) = @_;
+
+    return '';
+}
+
+sub handle_post {
+    my ($class, $post, %opts) = @_;
+
+    BML::set_language_scope('/pay/modify.bml');
+
+    my $remote = $class->get_effective_remote;
+    my $now = time();
+
+    my $uh = LJ::UserHead->get_userhead($post->{id});
+    die BML::ml('.error.invalidproduct') unless $uh;
+
+    die BML::ml('widget.vgiftsmspay.notauthorized') 
+        unless $uh->get_price == 1.99 && LJ::Pay::can_use_sup_sms($remote);
+
+    my $cartobj = LJ::Pay::Payment::new_cart($remote);
+
+    # Check recipient
+    my $recipient = $post->{to} || $remote->{user};
+    die BML::ml('.error.nousernamegiven') if $recipient eq "";
+
+    my $ou = LJ::load_user($recipient);
+    die BML::ml('.error.cantfinduser', {'user' => LJ::ehtml($recipient)})
+        unless $ou;
+    die BML::ml('.error.cantbuyforsyn') if $ou->{'journaltype'} eq 'Y';
+    die BML::ml('.error.cantbuyforrenamed') if $ou->{'journaltype'} eq 'R';
+    die BML::ml('.error.cantbuyduetoaccountstatus')
+        unless $ou->is_visible || $ou->is_memorial;
+
+    my $item = LJ::Pay::Payment::PayItem->new_memonly(item => 'userhead', subitem => 'uh-'.$post->{id}, qty => 1, amt => $uh->get_price,
+                                                      anon => ($post->{anongift} eq 'true') ? 1 : 0, rcptid => $ou->{'userid'});
+    my @errs;
+    my $can_be_added = $item->can_belong_to($cartobj, \@errs, undef, 'additem');
+    die LJ::bad_input(@errs) unless $can_be_added;
+
+    my $err_msg = $item->set_giveafter($post->{giveafter_yyyy}, $post->{giveafter_mm}, $post->{giveafter_dd}, $ou->timezone);
+    die $err_msg if $err_msg;
+    
+    # add the item
+    my $new_it = $cartobj->add_item(%{$item});
+
+    ## checkout cart to create the order
+    my $dbh = LJ::get_db_writer();
+    $dbh->do("UPDATE payments SET method=? WHERE payid=? AND used='C'", undef, 'sup_sms', $cartobj->{'payid'}) or die $DBI::errstr;
+
+    my $sms_order = $cartobj->{'payid'};
+
+    #To pay for the virtual gift, please SMS
+    my $to_pay = BML::ml("widget.userhead.sms.to_pay");
+
+    #to
+    my $to = BML::ml('widget.userhead.sms.to');
+
+    # Prices and conditions of use are available <a href='/sup/sms_tos_eng.bml' target=_blank>here</a>
+    my $prices = BML::ml("widget.userhead.sms.prices", {'aopts' => "href='$LJ::SITEROOT/sup/sms_tos.bml' target='_blank'"});
+    return (success => 1, divbody => "<div style='padding: 15px 30px; text-align: left;'><p>$to_pay</p><div style='font-size: 3em; color: #ff0000; margin-top: 5px; margin-bottom: 15px;'>LJ $sms_order</div> <p>$to</p> <div style='margin-left: 5px; font-size: 3em; line-height: .8em; color: #a1a1a1; padding-left: 16px; background: url(/img/sup/phone.gif) no-repeat left bottom;'>7069</div></p> <p style='margin-top: 20px;'>$prices</p></div>",);
+
+}
+
+1;

Added: trunk/htdocs/js/widget_ippu/userheadsmspay.js
===================================================================
--- trunk/htdocs/js/widget_ippu/userheadsmspay.js	                        (rev 0)
+++ trunk/htdocs/js/widget_ippu/userheadsmspay.js	2010-08-27 09:02:06 UTC (rev 9429)
@@ -0,0 +1,14 @@
+LJWidgetIPPU_UserheadSmsPay = new Class(LJWidgetIPPU, {
+	init: function (opts, params) {
+		opts.widgetClass = "IPPU::UserHeadSmsPay";
+		this.width = 400; // Use for resizing later
+		this.height = 300; // Use for resizing later
+		this.to = opts.to; // Use for filling To field later
+		LJWidgetIPPU_VGiftSmsPay.superClass.init.apply(this, arguments);
+	},
+	
+	onData: function (data)
+	{
+		$(data._widget_id).innerHTML = data.res.divbody;
+	}
+});

Tags: js, ljcom, pm, wisest-owl
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