Created
July 26, 2016 10:12
-
-
Save marcelo2605/37f16f5e1a82424e54904a55ea146642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once('PagSeguroLibrary/PagSeguroLibrary.php'); | |
function generate_pagseguro($user_id){ | |
// Instantiate a new payment request | |
$paymentRequest = new PagSeguroPaymentRequest(); | |
// Set the currency | |
$paymentRequest->setCurrency("BRL"); | |
// Add an item for this payment request | |
$paymentRequest->addItem('0001', 'Anuidade', 1, 150.00); | |
// Set a reference code for this payment request. It is useful to identify this payment | |
// in future notifications. | |
$paymentRequest->setReference("REF123"); | |
// Set shipping information for this payment request | |
//$sedexCode = PagSeguroShippingType::getCodeByType('SEDEX'); | |
//$paymentRequest->setShippingType($sedexCode); | |
/*$paymentRequest->setShippingAddress( | |
'01452002', | |
'Av. Brig. Faria Lima', | |
'1384', | |
'apto. 114', | |
'Jardim Paulistano', | |
'São Paulo', | |
'SP', | |
'BRA' | |
);*/ | |
// Set your customer information. | |
$paymentRequest->setSender( | |
'João Comprador', | |
'[email protected]', | |
'11', | |
'56273440', | |
'CPF', | |
'156.009.442-76' | |
); | |
// Set the url used by PagSeguro to redirect user after checkout process ends | |
//$paymentRequest->setRedirectUrl("http://wordpress.local/pagseguro"); | |
// Add checkout metadata information | |
//$paymentRequest->addMetadata('PASSENGER_CPF', '15600944276', 1); | |
//$paymentRequest->addMetadata('GAME_NAME', 'DOTA'); | |
//$paymentRequest->addMetadata('PASSENGER_PASSPORT', '23456', 1); | |
// Another way to set checkout parameters | |
//$paymentRequest->addParameter('notificationURL', 'http://www.lojamodelo.com.br/nas'); | |
//$paymentRequest->addParameter('senderBornDate', '07/05/1981'); | |
//$paymentRequest->addIndexedParameter('itemId', '0003', 3); | |
//$paymentRequest->addIndexedParameter('itemDescription', 'Notebook Preto', 3); | |
//$paymentRequest->addIndexedParameter('itemQuantity', '1', 3); | |
//$paymentRequest->addIndexedParameter('itemAmount', '200.00', 3); | |
// Add installment without addition per payment method | |
//$paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 6, 'MAX_INSTALLMENTS_NO_INTEREST'); | |
// Add installment limit per payment method | |
//$paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 8, 'MAX_INSTALLMENTS_LIMIT'); | |
// Add and remove a group and payment methods | |
//$paymentRequest->acceptPaymentMethodGroup('CREDIT_CARD', 'DEBITO_ITAU'); | |
//$paymentRequest->excludePaymentMethodGroup('BOLETO', 'BOLETO'); | |
try { | |
/* | |
* #### Credentials ##### | |
* Replace the parameters below with your credentials | |
* You can also get your credentials from a config file. See an example: | |
* $credentials = new PagSeguroAccountCredentials("[email protected]", | |
* "E231B2C9BCC8474DA2E260B6C8CF60D3"); | |
*/ | |
// seller authentication | |
$credentials = PagSeguroConfig::getAccountCredentials(); | |
// application authentication | |
//$credentials = PagSeguroConfig::getApplicationCredentials(); | |
//$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3"); | |
// Register this payment request in PagSeguro to obtain the payment URL to redirect your customer. | |
$url = $paymentRequest->register($credentials); | |
add_user_meta( $user_id, 'pagseguro', $url, true ); | |
return $url; | |
} catch (PagSeguroServiceException $e) { | |
die($e->getMessage()); | |
} | |
} | |
add_action( 'user_register', 'register_pagseguro', 10, 1 ); | |
function register_pagseguro( $user_id ) { | |
$pagseguro_url = generate_pagseguro($user_id); | |
wp_redirect( $pagseguro_url ); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment