Utilizando la API de Paypal y Pagseguro

1- Creamos una aplicación del tipo grid

2- Editamos los sgtes campos y creamos un nuevo campo llamado “info

  • Campo Customerid

3- Creamos en el evento onRecord

4- Creamos dos métodos PHP, call_pagseguro() y call_paypal()

  • Funcion call_pagseguro

$arr_settings = [
                    'gateway'    => 'pagseguro',
                    'environment' => 'sandbox',
                    'auth_email' => 'vitorjamil@gmail.com',
                    'auth_token' => '72AE21503DDA4840BE1DC7945F6D1CE1'
                 ];

sc_call_api('',$arr_settings);

$payment = new \PagSeguro\Domains\Requests\Payment();

sc_lookup(ds_cust, "SELECT contactname FROM customers WHERE customerid = '{customerid}' ");
$senderName = {ds_cust[0][0]};
$senderEmail = "c05075609506900394802@sandbox.pagseguro.com.br";
$resp_apl = str_replace("grid_orders_paywith","control_paywith_return",$_SERVER["PHP_SELF"]);
$redirectUrl = "http://" . $_SERVER["HTTP_HOST"]  . $resp_apl ;
$notificationUrl = "http://" . $_SERVER["HTTP_HOST"]  . $resp_apl . "?pagseguro=notification";

if (\PagSeguro\Configuration\Configure::getEnvironment()->getEnvironment() == "sandbox") {
        $url_type = "https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout";
} else {
        $url_type = "https://stc.pagseguro.uol.com.br/pagseguro/api/v2/checkout";    
}


$payment->setSender()->setName($senderName);

$payment->setSender()->setEmail($senderEmail);

$payment->setSender()->setPhone()->withParameters(
                11,
                56273440
            );

$payment->setSender()->setDocument()->withParameters(
                'CPF',
                '85744729054'
            );

$sItems = "SELECT products.productname, order_details.quantity, order_details.unitprice
FROM order_details INNER JOIN products ON order_details.productid = products.productid
WHERE orderid = ".{orderid};
sc_select(dsitems, $sItems);
    
$pos_item = 1;
if ({dsitems} === false)
{
    echo {dsitems_erro};
}
else
{
    while (!{dsitems}->EOF){        
        $payment->addItems()->withParameters(
            str_pad($pos_item, 4, "0", STR_PAD_LEFT),
            {dsitems}->fields[0],
            {dsitems}->fields[1],
            {dsitems}->fields[2]
        );
        $pos_item++;
        {dsitems}->MoveNext();
    }
    {dsitems}->Close();
}

$payment->setCurrency("BRL");

$payment->setExtraAmount(0.00);

$payment->setReference({orderid});

$payment->setRedirectUrl($redirectUrl);

$payment->setNotificationUrl($notificationUrl);


$payment->addPaymentMethod()->withParameters(
    PagSeguro\Enum\PaymentMethod\Group::CREDIT_CARD,
    PagSeguro\Enum\PaymentMethod\Config\Keys::MAX_INSTALLMENTS_NO_INTEREST,
    2
);

$payment->addPaymentMethod()->withParameters(
    PagSeguro\Enum\PaymentMethod\Group::CREDIT_CARD,
    PagSeguro\Enum\PaymentMethod\Config\Keys::MAX_INSTALLMENTS_LIMIT,
    6
);

$payment->acceptPaymentMethod()->groups(
    \PagSeguro\Enum\PaymentMethod\Group::CREDIT_CARD,
    \PagSeguro\Enum\PaymentMethod\Group::BALANCE
);

$payment->acceptPaymentMethod()->name(\PagSeguro\Enum\PaymentMethod\Name::DEBITO_ITAU);

$payment->excludePaymentMethod()->group(\PagSeguro\Enum\PaymentMethod\Group::BOLETO);

try {
    $response = $payment->register(
            \PagSeguro\Configuration\Configure::getAccountCredentials()
    );
    $transcode = substr($response, strpos($response, "code=") + 5);

    
} catch (Exception $e) {
    die($e->getMessage());
}


echo'<script type="text/javascript" src="'.$url_type.'/pagseguro.lightbox.js"> </script>';

echo '<script>
var transactionCode = "'.$transcode.'";
PagSeguroLightbox(
    {    code: "'.$transcode.'"},
    {    
        success : function(transactionCode) {        
            window.location.href = "'.$redirectUrl.'?pagseguro=return&orderid='.{orderid}.'&transcode="+transactionCode;
        },
        abort : function(transactionCode) {        
            window.location.href = "'.$redirectUrl.'?pagseguro=aborted&orderid='.{orderid}.'&transcode="+transactionCode;
        }
    }
);
</script>';
  • Funcion call_Paypal

$arr_settings = [
                    'gateway'    => 'paypal_express',
                    'username'    => 'vitorjamil-facilitator_api1.hotmail.com',
                    'password'    => 'PATZ87JJP4TTA8M5',
                    'signature'    => 'AFcWxV21C7fd0v3bYYYRCpSSRl31AiumnueMX6k4djKiUvF8HeI2RUZ1',
                    'testMode'    => 'TRUE'    
                 ];

$gateway = sc_call_api('',$arr_settings);

$resp_apl = str_replace("grid_orders_paywith","control_paywith_return",$_SERVER["PHP_SELF"]);

$response = $gateway->purchase(
array(
    'cancelUrl'=> 'http://' . $_SERVER["HTTP_HOST"] . $resp_apl . '?paypal=aborted&orderid='.{orderid},
    'returnUrl'=> 'http://' . $_SERVER["HTTP_HOST"] . $resp_apl . '?paypal=return&orderid='.{orderid},
    'amount' =>  {priceorder},
    'currency' => 'USD',
    'Description' => {lang_orders_fild_orderid}.' '.{priceorder}
    )

 )->send();
if ($response->isRedirect()) {
   // redirect to offsite payment gateway
   $response->redirect();
}
else {
   // payment failed: display message to customer
   echo $response->getMessage();
}

5- Procedemos a crear una aplicación de control.

6- Creamos los sgtes campos del tipo etiqueta dentro de la aplicación de control.

7- Ejecutamos la aplicación

  • PagSeguro

Compartir este tutorial

Tutoriales en la misma categoria

Tutorial: Gestión de archivos en la nube

Algunos de los servicios de almacenamiento de datos están listos para leer y almacenar de forma se...

Integración con WhatsApp

Para integrar WhastApp con ScriptCase, estaremos utilizando una API en específico que se llama...

Confirmación por Correo Electrónico

En este tutorial veremos cómo crear un formulario de confirmación de registro para programar curs...

Enviar múltiples SMS con la macro sc_send_sms

En este ejemplo estaremos viendo cómo podemos crear una aplicación que nos ayude  a enviar m...

Comentar este post