Committer: nnikulochkina
LJSUP-14234: Implement server part for shop payment pagesU trunk/bin/upgrading/en_LJ.dat U trunk/bin/upgrading/ru.dat U trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm U trunk/cgi-bin/LJ/Widget/CreditCard.pm U trunk/cgi-bin/LJ/Widget/Shop/Cart.pm
Modified: trunk/bin/upgrading/en_LJ.dat =================================================================== --- trunk/bin/upgrading/en_LJ.dat 2012-11-12 11:24:52 UTC (rev 12878) +++ trunk/bin/upgrading/en_LJ.dat 2012-11-12 12:45:32 UTC (rev 12879) @@ -6915,6 +6915,8 @@ pay.cc.form.cardnumber.bubble-lite|staleness=1 pay.cc.form.cardnumber.bubble-lite=Enter your card number. %card_type% card numbers are 16 digits long. +pay.cc.form.cardnumber.bubble-lite.new=Enter your card number. [[card_type]] card numbers are 16 digits long. + pay.cc.form.cardnumber.bubble-lite.americanexpress|staleness=1 pay.cc.form.cardnumber.bubble-lite.americanexpress=Enter your card number. American Express card numbers are 15 digits long. @@ -6954,6 +6956,8 @@ pay.cc.form.cvv2.bubble-lite=Enter the security code from the back of your card. %card_type% has a 3 digit security code. <a [[aopts]] target=_blank>See an example</a>. +pay.cc.form.cvv2.bubble-lite.new=Enter the security code from the back of your card. [[card_type]] has a 3 digit security code. <a [[aopts]] target=_blank>See an example</a>. + pay.cc.form.cvv2.bubble-lite.americanexpress=Enter the security code from the back of your card. American Express has a 4 digit security code. <a [[aopts]] target=_blank>See an example</a>. pay.cc.form.cvv2.bubble-warning.americanexpress|staleness=1 Modified: trunk/bin/upgrading/ru.dat =================================================================== --- trunk/bin/upgrading/ru.dat 2012-11-12 11:24:52 UTC (rev 12878) +++ trunk/bin/upgrading/ru.dat 2012-11-12 12:45:32 UTC (rev 12879) @@ -27794,6 +27794,8 @@ pay.cc.form.cardnumber.bubble-lite=Введите номер своей банковской карты. Номера карт %card_type% содержат 16 цифр. +pay.cc.form.cardnumber.bubble-lite.new=Введите номер своей банковской карты. Номера карт [[card_type]] содержат 16 цифр. + pay.cc.form.cardnumber.bubble-lite.americanexpress=Введите номер своей банковской карты. Номера карт American Express содержат 15 цифр. pay.cc.form.cardnumber.bubble-warning.americanexpress=Введен неверный номер карты. Номера карт American Express содержат 15 цифр. @@ -27824,6 +27826,8 @@ pay.cc.form.cvv2.bubble-lite=Введите код безопасности, указанный на обратной стороне вашей карты. Код безопасности карт %card_type% содержит 3 цифры. <a [[aopts]] target=_blank>Образец</a>. +pay.cc.form.cvv2.bubble-lite.new=Введите код безопасности, указанный на обратной стороне вашей карты. Код безопасности карт [[card_type]] содержит 3 цифры. <a [[aopts]] target=_blank>Образец</a>. + pay.cc.form.cvv2.bubble-lite.americanexpress=Введите код безопасности, указанный на обратной стороне вашей карты. Код безопасности карт American Express содержит 4 цифры. <a [[aopts]] target=_blank>Образец</a>. pay.cc.form.cvv2.bubble-warning.americanexpress=Введен неверный код безопасности. Код безопасности карт American Express содержит 4 цифры. Modified: trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm =================================================================== --- trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm 2012-11-12 11:24:52 UTC (rev 12878) +++ trunk/cgi-bin/LJ/Pay/Method/CreditCard.pm 2012-11-12 12:45:32 UTC (rev 12879) @@ -3,6 +3,8 @@ use strict; use base qw(LJ::Pay::Method); +use LJ::DengiOnline; + sub code { 'cc' } sub group { 'credit_card' } @@ -13,9 +15,15 @@ name => 'Credit Cards', code_name => 'credit_card', shop_method => 'cc', - img_src => $LJ::IMGPREFIX.'/shop/payment/visa.png', + img_src => { + Visa => $LJ::IMGPREFIX.'/shop/payment/visa.png', + MasterCard => $LJ::IMGPREFIX.'/shop/payment/mastercard.png', + AmEx => $LJ::IMGPREFIX.'/shop/payment/amex.png', + Discover => $LJ::IMGPREFIX.'/shop/payment/discover.png', + }, func => sub { &LJ::DengiOnline::credit_card; }, id => 60, + types => [qw(Visa MasterCard AmEx Discover)], } } @@ -31,22 +39,57 @@ $amt_total = '1.00' if $amt_total <= 0 and $has_coppa; my $amt_charge = sprintf("%0.02f", $amt_total); - my $err = ''; - my $html = - "<form method='post' action='$LJ::SSLROOT/pay/cc.bml?c=$cart_id' id='ccform'>" - . LJ::html_hidden("amt_charge", $amt_charge) - . LJ::Widget::CreditCard::render( - LJ::Pay::RecBill->valid_countries, - $err, - { LJ::Request->post_params }, # only get method - undef, - { - 'cvv2' => 1, - 'has_coppa' => $has_coppa, - } - ) - . "</form>"; + my ($err, $html); + # TODO: type + my $type = LJ::Request->get_param('type'); + + # TODO: err + #$self->ml_error('error.invalidform') + # unless $type; + + my @params = ( + LJ::Pay::RecBill->valid_countries, + $err, + { LJ::Request->post_params }, # only get method + undef, + { + 'cvv2' => 1, + 'has_coppa' => $has_coppa, + 'amt_charge' => $amt_charge, + 'type' => $type, + } + ); + + if (LJ::is_enabled('dengionline')) { + if ( grep /$type/, @LJ::DENGIONLINE_VALID_CARDS) { + my $result = LJ::DengiOnline->create_bill ( + cart_id => $cart_id, + shop_method => code(), + ); + + unless ($result && $result->{status} && + $result->{status} eq 'OK') { + LJ::Request->redirect("$LJ::SITEROOT/shop/cart.bml?pay_err=1&cart=$cart_id"); + return; + } + + $html = LJ::Widget::CreditCard::render_iframe('url' => $result->{url}); + + } else { + + $html = LJ::Widget::CreditCard::render_form(@params); + + } + } else { + $err = ''; + $html = + "<form method='post' action='$LJ::SSLROOT/pay/cc.bml?c=$cart_id' id='ccform'>" + . LJ::html_hidden("amt_charge", $amt_charge) + . LJ::Widget::CreditCard::render(@params) + . "</form>"; + } + return { cc_payment_widget => $html }; } Modified: trunk/cgi-bin/LJ/Widget/CreditCard.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/CreditCard.pm 2012-11-12 11:24:52 UTC (rev 12878) +++ trunk/cgi-bin/LJ/Widget/CreditCard.pm 2012-11-12 12:45:32 UTC (rev 12879) @@ -7,6 +7,8 @@ sub need_res { qw( stc/widgets/widget-layout.css stc/widgets/credit-card.css ) } +use LJ::HTML::Template; + # whatever page loads this should be including # pay.css and pay.js sub render { @@ -304,6 +306,102 @@ return $ret; } + +sub render_form { + my ( $countries, $err, $POST, $card, $opts ) = @_; + + $opts ||= {}; + + my $remote = LJ::get_remote(); + + LJ::need_res(need_res()); + + # init some vars + my ($name, $exp_m, $exp_y, @exp_yrs); + if ( $card ) { + $name = $card->get_name_first() . " " . $card->get_name_last(); + ($exp_y, $exp_m) = $card->get_exp(); + } + + my $year = (gmtime())[5]; + $year += 1900; + push @exp_yrs, $year + $_ for (0..10); + + # country + my $profile_country = $remote && $remote->prop('country'); + my $countryval = ($card ? $card->get_country : $POST->{country}) || $profile_country; + + # load US and Canadian states + my (%states); + LJ::load_codes({ state => \%states }); + $states{''} = LJ::Lang::ml('pay.cc.form.state.uscanadaonly'); + + # find a state value from a stored card or post value, unless + # it is a known US state + my $stateval = $card ? $card->get_state : $POST->{state_other}; + $stateval = '' if $countryval =~ /^(US)$/ && $states{$stateval}; + + my $ml_cardnumber = $opts->{type} ne 'AmEx' ? + LJ::Lang::ml('pay.cc.form.cardnumber.bubble-lite.new', {card_type => $opts->{type}}) : + LJ::Lang::ml('pay.cc.form.cardnumber.bubble-lite.americanexpress'); + + my $template = LJ::HTML::Template->new( + { use_expr => 1 }, # force HTML::Template::Pro with Expr support + filename => "$ENV{'LJHOME'}/templates/Widgets/shop/credit_card.tmpl", + die_on_bad_params => 0, + strict => 0, + ) or die "Can't open template: $!"; + $template->param( + %$opts, + 'cc_num' => $POST->{cc_num} || ($LJ::IS_DEV_SERVER && '4111111111111111'), + 'show_cvv2' => $opts->{cvv2}, + 'cc_cvv2' => $POST->{cc_cvv2} || ($LJ::IS_DEV_SERVER && '123'), + 'exp_m' => $POST->{exp_m}, + 'exp_months' => [map { {month => sprintf("%02d", $_), value => $_} } (1..12)], + 'exp_y' => $POST->{exp_y} || ($LJ::IS_DEV_SERVER && 2015), + 'exp_yrs' => [map { {year => $_, value => $_} } @exp_yrs], + 'name_full' => $name || $POST->{name_full} || ($LJ::IS_DEV_SERVER && 'Name on Card'), + 'country' => $countryval || 'US', + 'countries' => [ map { { value => $_, name => $countries->{$_} } } sort { $countries->{$a} cmp $countries->{$b} } keys %$countries], + 'addr' => ( $card ? $card->get_addr() : $POST->{addr} ) || ($LJ::IS_DEV_SERVER && 'Billing Address'), + 'city' => ( $card ? $card->get_city() : $POST->{city}) || ($LJ::IS_DEV_SERVER && 'City'), + 'state' => ( $card ? $card->get_state() : $POST->{state} || ($LJ::IS_DEV_SERVER && "AL") ), + 'states' => [ map { {value => $_, name => $states{$_}} } sort { $states{$a} cmp $states{$b} } keys %states], + 'stateval' => $stateval, + 'postal_code' => ( $card ? $card->get_postal_code() : $POST->{postal_code} ) || ($LJ::IS_DEV_SERVER && '12345'), + 'email' => ( $card ? $card->get_email() : $POST->{email} ) || ($remote && $remote->email_raw), + 'ml_cardnumber' => $ml_cardnumber, + ); + + + if ($opts->{cvv2}) { + my $ml_var = $opts->{type} eq 'AmEx' ? + 'pay.cc.form.cvv2.bubble-lite.americanexpress' : + 'pay.cc.form.cvv2.bubble-lite.new'; + my $card_type = $opts->{type}; + $template->param( + 'ml_cc_cvv2' => LJ::Lang::ml($ml_var, {aopts => "href='$LJ::SSLROOT/pay/cvv2.bml'", card_type => $card_type} ) + ); + } + + return $template->output; +} + + +sub render_iframe { + my %opts = @_; + + my $template = LJ::HTML::Template->new( + { use_expr => 1 }, # force HTML::Template::Pro with Expr support + filename => "$ENV{'LJHOME'}/templates/Shop/DengiOnline/CreditCard.tmpl", + die_on_bad_params => 0, + strict => 0, + ) or die "Can't open template: $!"; + $template->param( %opts ); + return $template->output; +} + + # Will also set state to value of state_other if non-US sub validate { my ($POST) = @_; Modified: trunk/cgi-bin/LJ/Widget/Shop/Cart.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/Shop/Cart.pm 2012-11-12 11:24:52 UTC (rev 12878) +++ trunk/cgi-bin/LJ/Widget/Shop/Cart.pm 2012-11-12 12:45:32 UTC (rev 12879) @@ -348,8 +348,10 @@ LJ::Request->delete_cookie('cart'); } + # TODO: type LJ::Request->redirect("$LJ::SSLROOT/shop/checkout.bml?cart=" . - $cart->get_cart_as_string); + $cart->get_cart_as_string . + "&type=".LJ::Request->post_param('type')); } # repeat order