1 – We create an application of the grid type
2 – We edit the following fields and create a new field called “info“
- Campo Customerid
3 – We create in the onRecord event
4 – We create two PHP methods, call_pagseguro () and call_paypal ()
- Function 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>';
- Function 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 – We proceed to create a control application.
6 – We create the following label type fields within the control application.
7 – We execute the application
- PagSeguro
Comment this post