0

i have website with credit`s user, when have to user credits he can convert them to really money,

for exmple: i am the user and i have 500 credits, 1 credit == 1$ the user press on "convert to dollars" button, and he insert paypal email to sent the money.

now i need way to do automatic payment from my paypal account to paypal email he should be insert before.

i am try to use the mass payment but this not accept to all users, only to specific users.

 * 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($environment,$methodName_, $nvpStr_)
{
    // Set up your API credentials, PayPal end point, and API version.
    // How to obtain API credentials:
    // https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics#id084E30I30RO
    $API_UserName = ('mail');
    $API_Password = ('passapi');
    $API_Signature = ('signture');
    $API_Endpoint = "https://svcs.paypal.com/AdaptivePayments/Pay";
    if("sandbox" == $environment || "beta-sandbox" === $environment)
    {
        $API_Endpoint = "https://svcs.$environment.paypal.com/AdaptivePayments/Pay";
    }
    $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_HTTPHEADER, array(
        "X-PAYPAL-SECURITY-USERID: {$API_UserName}",
        "X-PAYPAL-SECURITY-PASSWORD: {$API_Password}",
        "X-PAYPAL-SECURITY-SIGNATURE: {$API_Signature}",
        "X-PAYPAL-REQUEST-DATA-FORMAT: NV",
        "X-PAYPAL-RESPONSE-DATA-FORMAT: NV"
    ));

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

    // Set the API operation, version, and API signature in the request.
    $nvpreq = $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;
}

how i can do it?

thanks for helps!

2 Answers2

0

You can use the MassPay API or the Adative Payments (Pay) API to do this. When you say "i am try to use the mass payment but this not accept to all users, only to specific users", I am not sure what you mean by this. Can you explain this a bit more.

PP_MTS_Chad
  • 7,311
  • 1
  • 15
  • 20
0

Have a look at PayPal Adaptive Payments IMPLICIT Pay API
Using Adaptive Payments you can create a so-called 'Implicit Payment'.

Implicit approval payments are payments where the sender and the API caller are using the same account. Because PayPal draws the funds for the payment from your own account, there is no approval necessary, and as such there is no visible flow for implicit approval payments.

The following diagram shows the basic flow of control during an implicitly approved payment operation:

AP Implicit flow

The following items correspond to the circled numbers in the diagram:

  1. Your site or device sends a Pay request to PayPal.
    Note: A web flow is not required.
  2. PayPal responds with a key that you use for other API operations.

If you'd like to explore this further, I would recommend reading up on Adaptive Payments in the Adaptive Payments getting started guide and the Adaptive Payments developer guide.

Note: You can use AppID APP-80W284485P519543T in the Sandbox environment for testing purposes.

Community
  • 1
  • 1
Robert
  • 19,326
  • 3
  • 58
  • 59