$versions{'PayPalBasic-mgr_lib.pl'} = '06.6.00.0000';
# PayPal Processing Gateway
#
# For the PayPal Processing Standard/Basic Gateway
# Very Basic Buy Now Button version
#
#####################################################################
#
# AgoraCart and all associated files, except where noted, are
# Copyright 2001 to Present jointly by K-Factor Technologies, Inc.
# and by C E Mayo (aka Mister Ed) at AgoraCart.com & K-Factor.net
#
# Licensed 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.
#
# This copyright notice may not be removed or altered in any way.
#
#######################################################################
#                    Order Form Definition Variables
#######################################################################
add_codehook( 'gateway_admin_screen',   'PayPalBasic_mgr_check' );
add_codehook( 'gateway_admin_settings', 'PayPalBasic_settings' );
$mc_gateways .= '|PayPalBasic::PayPal - Basic';
##############################################################################
sub PayPalBasic_settings {
    local ($custom_logic);
    if ( $sc_gateway_name eq 'PayPalBasic' ) {

        $PayPalBasic_top_message_temp = my_escape( $in{'PayPalBasic_top_message'} );
        $PayPalBasic_shipping_message_temp = my_escape( $in{'PayPalBasic_shipping_message'} );
        $use_custom_logic = my_escape( $in{'sc_use_custom_PayPalBasic_url_logic'} );
        $custom_logic = my_escape( $in{'sc_custom_PayPalBasic_url_logic'} );
        $PayPalBasic_verify_message_temp = my_escape( $in{'PayPalBasic_verify_message'} );
        $PayPalBasic_tos_display_address_temp = my_escape( $in{'PayPalBasic_tos_display_address'} );
        $sc_order_ok_tmp = my_escape( $in{'PayPalBasic_order_ok_final_msg_tbl'} );

        open( GATEWAY, "> $gateway_settings" )
          || my_die("Can't Open $gateway_settings");
        print( GATEWAY
              "\$PayPalBasic_gateway_username = \'$in{'PayPalBasic_gateway_username'}\';\n" );
        print( GATEWAY "\$PayPalBasic_change = \"$in{'PayPalBasic_change'}\";\n" );
        print( GATEWAY "\$PayPalBasic_order_script_url = \"$in{'order_url'}\";\n" );
        print( GATEWAY "\$PayPalBasic_order_name = \'$in{'order_name'}\';\n" );
        print( GATEWAY "\$PayPalBasic_order_number = \'$in{'order_number'}\';\n" );
        print( GATEWAY "\$PayPalBasic_currency_id = \"$in{'PayPalBasic_currency_id'}\";\n" );
        print( GATEWAY "\$PayPalBasic_address_override = \'$in{'PayPalBasic_address_override'}\';\n" );
        print( GATEWAY "\$PayPalBasic_top_message = qq'$PayPalBasic_top_message_temp';\n" );
        print( GATEWAY "\$PayPalBasic_special_message = qq'$PayPalBasic_special_message';\n" );
        print( GATEWAY "\$sc_use_custom_PayPalBasic_url_logic = qq'$use_custom_logic';\n" );
        print( GATEWAY "\$sc_custom_PayPalBasic_url_logic = qq`$custom_logic`;\n" );
        print( GATEWAY "\$PayPalBasic_verify_message = qq'$PayPalBasic_verify_message_temp';\n" );
        print( GATEWAY "\$PayPalBasic_display_checkout_tos = \"$in{'PayPalBasic_display_checkout_tos'}\";\n" );
        print( GATEWAY "\$PayPalBasic_tos_display_address = qq'$PayPalBasic_tos_display_address_temp';\n" );
        print( GATEWAY "\$PayPalBasic_order_ok_final_msg_tbl = qq'$sc_order_ok_tmp';\n" );
        print( GATEWAY "\$PayPalBasic_email_template = \"$in{'PayPalBasic_email_template'}\";\n" );
        print( GATEWAY "\$PayPalBasic_admin_email_template = \"$in{'PayPalBasic_admin_email_template'}\";\n" );
        print( GATEWAY "\$PayPalBasic_verifytable = \"$in{'PayPalBasic_verifytable'}\";\n" );
        print( GATEWAY "\$PayPalBasic_thankstable = \"$in{'PayPalBasic_thankstable'}\";\n" );
        print( GATEWAY "#\n1\;# We are a Library\n" );
        close(GATEWAY);
    }
}
##############################################################################
sub PayPalBasic_mgr_check {
    if ( $sc_gateway_name eq 'PayPalBasic' ) {
        print_PayPalBasic_mgr_form();
        call_exit();
    }
}
##############################################################################
sub print_PayPalBasic_mgr_form {

    local ($my_PayPalBasic_order_name)   = $PayPalBasic_order_name;
    local ($my_PayPalBasic_order_number) = $PayPalBasic_order_number;

    if ( $PayPalBasic_display_checkout_tos eq '' ) {
        $PayPalBasic_display_checkout_tos = 'yes';
    }

    print &$manager_page_header( 'PayPal Standard - Basic', '', '', '', '' );

    $mc_email_admin_plates = read_templatedirs($sc_emailPlates_dir, 'admin_emailPlate');
    $mc_email_plates = read_templatedirs($sc_emailPlates_dir, 'emailPlate');
    $mc_verifytable_plates = read_templatedirs($sc_cartverifyplates_dir, 'verifyTable');
    $mc_thanktable_plates = read_templatedirs($sc_thankyouplates_dir, 'thanksTable');


    print <<ENDOFTEXT;
<h1 class='mgr-page-title'>PayPal Standard - Basic</h1>
<p><br></p>

<p class="well"><b>How this solution works:</b> This is solution is a legacy solution using a basic implementation of PayPal Standard where the customer is sent to the PayPal website to complete the payment after filling out some order information in the cart checkout. Once the customer clicks on the final button of the cart, they are directed to the PayPal website to make payment. By default there is no way to confirm that payment has been received, so once they leave the cart to go to PayPal.com, an email receipt is sent to you and to your customer for the order. We advise that you make sure to note this process in the message areas of this payment solution. Also make sure to manually correlate any payments and orders so that they match up. Notices via email come from PayPal and from your AgoraCart store so that is how you can match up those orders and payments. If you need confirmed payments and a little more automation in payment processing, we suggest using PayPal IPN or newer.</p>
<p><br></p>

ENDOFTEXT

if ( $in{'system_edit_success'} ) {
$page_output .= qq|
<div class="row col-xs-12 col-sm-12 col-md-12 col-lg-12 hidden-xs">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 bg-success">
<h4 class="text-primary mgr-center">payPal Basic settings have been successfully updated</h4>
</div>
</div>
<p><br><br><br><br><br></p>
|;
}

print <<ENDOFTEXT;

<form action="manager.cgi" method="post"><input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">


<p><b>PayPal Email Address: &nbsp; <a data-toggle="collapse" href="#ppbEmail" aria-expanded="false" aria-controls="ppbEmail"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="PayPalBasic_gateway_username" type="email" class="form-control" maxlength="128" value="$PayPalBasic_gateway_username" required></p>
<div class="collapse" id="ppbEmail">
  <div class="well">
    <p>Can be your primary or any other confirmed email address linked to your paypal account.</p>
    <p><b>Recommendation:</b> Use a secondary email address not used to login at PayPal.</p>
  </div>
</div>

<p><hr></p>

<p><b>Select Customer Email Template - Successful Order: &nbsp; <a data-toggle="collapse" href="#ppbCustMailPlate" aria-expanded="false" aria-controls="ppbCustMailPlate"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="PayPalBasic_email_template">
<option selected>$PayPalBasic_email_template</option>
$mc_email_plates
</select></p>
<div class="collapse" id="ppbCustMailPlate">
    <div class="well">
    <p>This is the template (emailPlate) that is used to create the confirmation email sent to the customer after a successful order & payment is received.</p>
    </div>
</div>

<p><br></p>

<p><b>Select Site Admin Email Template - Successful Order: &nbsp; <a data-toggle="collapse" href="#ppipnAdminMailPlate" aria-expanded="false" aria-controls="ppipnAdminMailPlate"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="PayPalBasic_admin_email_template">
<option selected>$PayPalBasic_admin_email_template</option>
$mc_email_admin_plates
</select></p>
<div class="collapse" id="ppipnAdminMailPlate">
    <div class="well">
    <p>This is the template (emailPlate) that is used to create the confirmation email sent to you (the admin) after a successful order & payment is received.</p>
    </div>
</div>

<p><hr></p>

<p><b>Select the Verify Table Template for the Checkout Verify Page: &nbsp; <a data-toggle="collapse" href="#ppbVerifyCheckoutTemp" aria-expanded="false" aria-controls="ppbVerifyCheckoutTemp"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="PayPalBasic_verifytable" required>
<option>$PayPalBasic_verifytable</option>
$mc_verifytable_plates
</select></p>
<div class="collapse" id="ppbVerifyCheckoutTemp">
    <div class="well">
        <p>This is the template used to generate the verify page that the customer uses to verify their order information.</p>
        <p>It is the page displayed immediately before going to the the hosted payment page at PayPal.com</p>
    </div>
</div>

<p><hr></p>

<p><b>Select the Thankyou Table Template for the Successful Payment Return Page: &nbsp; <a data-toggle="collapse" href="#ppbThanksTemp" aria-expanded="false" aria-controls="ppbThanksTemp"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="PayPalBasic_thankstable" required>
<option>$PayPalBasic_thankstable</option>
$mc_thanktable_plates
</select></p>
<div class="collapse" id="ppbThanksTemp">
    <div class="well">
        <p>This is the template used to generate the thankyou page that the customer lands on at your store after completing their payment at the hosted form at PayPal.com.</p>
    </div>
</div>

<p><hr></p>

<p><b>PayPal URL (to submit to): &nbsp; <a data-toggle="collapse" href="#ppbURL" aria-expanded="false" aria-controls="ppbURL"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="order_url" type="text" class="form-control" maxlength="128" value="$PayPalBasic_order_script_url" required></p>
<div class="collapse" id="ppbURL">
  <div class="well">
    <p>Default: https://www.paypal.com/xclick/business</p>
  </div>
</div>

<p><hr></p>

<p><b>The Order Name to display on the PayPal site: &nbsp; <a data-toggle="collapse" href="#ppbOname" aria-expanded="false" aria-controls="ppbOname"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="order_name" type="text" class="form-control" maxlength="128" value="$my_PayPalBasic_order_name" required></p>
<div class="collapse" id="ppbOname">
  <div class="well">
    <p></p>
  </div>
</div>

<p><hr></p>

<p><b>The Order number/identificatio to display on the PayPal site: &nbsp; <a data-toggle="collapse" href="#ppbOnumber" aria-expanded="false" aria-controls="ppbOnumber"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="order_number" type="text" class="form-control" maxlength="128" value="$my_PayPalBasic_order_number" required></p>
<div class="collapse" id="ppbOnumber">
  <div class="well">
    <p></p>
  </div>
</div>

<p><hr></p>


<p><b>PayPal Currency: &nbsp; <a data-toggle="collapse" href="#ppbCurrency" aria-expanded="false" aria-controls="ppbCurrency"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="PayPalBasic_currency_id">
<option selected>$PayPalBasic_currency_id</option>
<option>USD</option>
<option>AUD</option>
<option>CAD</option>
<option>GBP</option>
<option>EUR</option>
<option>JPY</option>
</select></p>
<div class="collapse" id="ppbCurrency">
    <div class="well">
    <p>Defines the currency to use at the PayPal site, as well as what is used for the amounts sent to PayPal.</p>
    </div>
</div>

<p><hr></p>

<p><b>Shipping Address Suppression: &nbsp; <a data-toggle="collapse" href="#ppbShipSup" aria-expanded="false" aria-controls="ppbhipSup"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="PayPalBasic_address_override">
<option selected>$PayPalBasic_address_override</option>
<option>1</option>
<option>0</option>
</select></p>
<div class="collapse" id="ppbhipSup">
    <div class="well">
    <p>Select '1' to prevent the customer from selecting a different shipping address on the paypal site.</p>
    </div>
</div>

<p><hr></p>

<p><b>Top Message - in the PayPalBasic order form: &nbsp; <a data-toggle="collapse" href="#ppbTopMessage" aria-expanded="false" aria-controls="ppbTopMessage"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><textarea name="PayPalBasic_top_message" type="text" class="form-control" maxlength="400" rows=3 wrap=on>$PayPalBasic_top_message</textarea></p>
<div class="collapse" id="ppbTopMessage">
  <div class="well">
    <p>Allows you to place a message above the Payment Information form areas.</p>
    <p>HTML formatting (for text color, font, spacing, etc) is accepted.</p>
    <p>Leave blank if not needed.</p>
  </div>
</div>

<p><hr></p>

<p><b>Special Message - in the PayPalBasic order form: &nbsp; <a data-toggle="collapse" href="#ppbSpecialMessage" aria-expanded="false" aria-controls="ppbSpecialMessage"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><textarea name="PayPalBasic_special_message" type="text" class="form-control" maxlength="400" rows=3 wrap=on>$PayPalBasic_special_message</textarea></p>
<div class="collapse" id="ppbSpecialMessage">
  <div class="well">
    <p>Allows you to place a message above the Special Notes (aka XComment areas) of the order form, usually the last section towards the bottom of the form.</p>
    <p>HTML formatting (for text color, font, spacing, etc) is accepted.</p>
    <p>Leave blank if not needed.</p>
  </div>
</div>

<p><hr></p>

<p><b>Display ToS &amp; Refund Policy checkbox? &nbsp; <a data-toggle="collapse" href="#ppbDisplayTOS" aria-expanded="false" aria-controls="ppbDisplayTOS"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="PayPalBasic_display_checkout_tos">
<option>$PayPalBasic_display_checkout_tos</option>
<option>yes</option>
<option>no</option>
</select></p>
<div class="collapse" id="ppbDisplayTOS">
    <div class="well">
    <p><b>yes</b> displays <b>Terms of Service and Refund Policy</b> checkbox, and the field is set as <i>required</i> in order for customer to proceed with the additional checkout steps.</p>
    <p><b>no</b> nothing is displayed.</p>
    <p><b>Best Practice:</b> set to <i>YES</i>. Some countries and/or payment processors require customers to be notified of the return and shipping policies, and this is a good place to remind them to read and agree your store/site policies.</p>
    </div>
</div>

<p><br></p>

<p><b>Business address &amp; contact information for your business: &nbsp; <a data-toggle="collapse" href="#ppbTOSaddress" aria-expanded="false" aria-controls="ppbTOSaddress"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><textarea name="PayPalBasic_tos_display_address" type="text" class="form-control" maxlength="400" rows=5 wrap=on>$PayPalBasic_tos_display_address</textarea></p>
<div class="collapse" id="ppbTOSaddress">
  <div class="well">
    <p>Displays the required business address and contact information if the <b>Display TOS</b> option is enabled above.</p>
    <p>Should be legal address for the business location for full disclosure and other privacy requirements mandated by credit card companies as well as government enitities that require such notices.</p>
    <p>HTML formatting (for text color, font, spacing, etc) is accepted.</p>
  </div>
</div>

<p><hr></p>

<p><b>Top Message - on the PayPal Basic order verification page: &nbsp; <a data-toggle="collapse" href="#ppbTopMessageVerifyPage" aria-expanded="false" aria-controls="ppbTopMessageVerifyPage"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><textarea name="PayPalBasic_order_ok_final_msg_tbl" type="text" class="form-control" maxlength="400" rows=3 wrap=on>$PayPalBasic_order_ok_final_msg_tbl</textarea></p>
<div class="collapse" id="ppbTopMessageVerifyPage">
  <div class="well">
    <p>Displays a top message on the order form confirmation page (where customer verifies form submission/details), the page just before going to the actual payment gateway.</p>
    <p>HTML formatting (for text color, font, spacing, etc) is accepted.</p>
    <p>Leave blank if not needed.</p>
  </div>
</div>

<p><br></p>

<h3 class='mgr-page-title'>Custom PayPal URL Logic:</h3>

<p><b>Use the custom PayPal URL logic? &nbsp; <a data-toggle="collapse" href="#ppbCustLogic" aria-expanded="false" aria-controls="ppbDCustLogic"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 20px;"></span><select name="sc_use_custom_PayPalBasic_url_logic">
<option>$sc_use_custom_PayPalBasic_url_logic</option>
<option>yes</option>
<option>no</option>
</select></p>
<div class="collapse" id="ppbCustLogic">
    <div class="well">
    <p>If yes, enter the custom logic below and set this option to 'yes'.</p>
    </div>
</div>

<p><br></p>


<p><b>Custom PayPal URL Logic: &nbsp; <a data-toggle="collapse" href="#ppbTopMessageVerifyPage" aria-expanded="false" aria-controls="ppbTopMessageVerifyPage"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><textarea name="sc_custom_PayPalBasic_url_logic" type="text" class="form-control" maxlength="400" rows=3 wrap=on>$sc_custom_PayPalBasic_url_logic</textarea></p>
<div class="collapse" id="ppbTopMessageVerifyPage">
  <div class="well">
    <p>This is where you can customize the information appended to the end of the URL that the customer is sent to at PayPal.com. It replaces the other payment information that is send by default.</p>
  </div>
</div>

<p><br></p>

<input type="hidden" name="system_edit_success" value="yes">
<input name="GatewaySettings" type="hidden" value="Submit">
<input type="hidden" name="gateway" value="PayPalBasic">
<button class="btn btn-primary btn-lg mgr-center" style="display: block;">Submit PayPal Basic Updates</button>
<p><br><br><br></p>
</form>


ENDOFTEXT

}
##############################################################################
1;
