Precisa capturar e armazenar detalhes do receptor através do IPN através do Paypal Massa Pagar API

StackOverflow https://stackoverflow.com/questions/2615632

  •  26-09-2019
  •  | 
  •  

Pergunta

Esta é uma pergunta sobre o Paypal Massa Pagar IPN.Minha plataforma é PHP & mySQL.

Todo o apoio Paypal site, eu encontrei o IPN apenas para os pagamentos feitos.Eu preciso de um IPN em linhas semelhantes de Massa para Pagar, mas não conseguiu encontrá-lo.Também tentei experimentar já existentes Massa Pagar NVP código, mas que não quer trabalhar.

O que eu estou tentando fazer é que, para todos os destinatários para os quais o pagamento tiver sido enviada com êxito através de Massa de Pagar, eu quero gravar o seu e-mail, quantidade e unico na minha própria tabela de banco de dados.Se possível, eu quero capturar o status de pagamento, bem como, se ele tem sido um sucesso de falha e baseada na mesma, eu preciso fazer alguns em casa processamento.

O código existente em Massa pagar código abaixo:

<?php

$environment = 'sandbox';   // or 'beta-sandbox' or 'live'

/**
 * Send HTTP POST Request
 *
 * @param   string  The API method name
 * @param   string  The POST Message fields in &name=value pair format
 * @return  array   Parsed HTTP Response body
 */
function PPHttpPost($methodName_, $nvpStr_) {
    global $environment;

    // Set up your API credentials, PayPal end point, and API version.
    $API_UserName = urlencode('my_api_username');
    $API_Password = urlencode('my_api_password');
    $API_Signature = urlencode('my_api_signature');

    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {
        $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
    }
    $version = urlencode('51.0');

    // Set the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    // Turn off the server and peer verification (TrustManager Concept).
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);

    // Set the API operation, version, and API signature in the request.
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

    // Set the request as a POST FIELD for curl.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    // Get response from the server.
    $httpResponse = curl_exec($ch);

    if(!$httpResponse) {
        exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
    }

    // Extract the response details.
    $httpResponseAr = explode("&", $httpResponse);

    $httpParsedResponseAr = array();
    foreach ($httpResponseAr as $i => $value) {
        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {
            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
        }
    }

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
    }

    return $httpParsedResponseAr;
}

// Set request-specific fields.
$emailSubject =urlencode('example_email_subject');
$receiverType = urlencode('EmailAddress');
$currency = urlencode('USD');                           // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// Add request-specific fields to the request string.
$nvpStr="&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency";

$receiversArray = array();

for($i = 0; $i < 3; $i++) {
    $receiverData = array(  'receiverEmail' => "user$i@paypal.com",
                            'amount' => "example_amount",
                            'uniqueID' => "example_unique_id",
                            'note' => "example_note");
    $receiversArray[$i] = $receiverData;
}

foreach($receiversArray as $i => $receiverData) {
    $receiverEmail = urlencode($receiverData['receiverEmail']);
    $amount = urlencode($receiverData['amount']);
    $uniqueID = urlencode($receiverData['uniqueID']);
    $note = urlencode($receiverData['note']);
    $nvpStr .= "&L_EMAIL$i=$receiverEmail&L_Amt$i=$amount&L_UNIQUEID$i=$uniqueID&L_NOTE$i=$note";
}

// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('MassPay', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    exit('MassPay Completed Successfully: '.print_r($httpParsedResponseAr, true));


} else  {
    exit('MassPay failed: ' . print_r($httpParsedResponseAr, true));
}

?>

No código acima, como e onde posso adicionar código para capturar os campos que eu solicitados acima?Qualquer código que indica que a solução é altamente apreciado.

Muito obrigado.

Foi útil?

Solução

Eu estou mais familiarizado com Pagamentos Recorrentes, mas eu acho que o IPN resposta vai enviar de volta os valores que você está procurando.Apenas capturá-los para fora da matriz enviado de volta, colocá-los em algumas variáveis, e salvar no banco de dados.

$email   = $httpParsedResponseAr["receiver_email"];  
$amount  = $httpParsedResponseAr["mc_currency_x"];

Aqui estão os valores para a Massa de Pagar Variáveis
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables

Outras dicas

Geralmente, existem duas maneiras de obter esses dados, um é analisar as respostas da chamada que você faz para o MassPay diretamente e o outro está configurando o IPN para sua conta.

Você precisa configurar o IPN global, não consigo encontrar uma maneira de enviar o URL do IPN como uma variável nesta chamada.

Hth -ft

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top