简体   繁体   中英

Php curl for PayPal adaptive payments preaproval key

New to PHP, trying to add PayPal's adaptive payment option to a site I am building.

I need to format this following code found at PayPal into php curl :

curl -s --insecure
-H "X-PAYPAL-SECURITY-USERID: api_username"
-H "X-PAYPAL-SECURITY-PASSWORD: api_password"
-H "X-PAYPAL-SECURITY-SIGNATURE: api_signature"
-H "X-PAYPAL-REQUEST-DATA-FORMAT: NV"
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV"
-H "X-PAYPAL-APPLICATION-ID: app_id"
https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval  -d
"cancelUrl=http://your_cancel_url
&currencyCode=USD
&endingDate=2009-12-13T08%3A00%3A00.000Z
&maxAmountPerPayment=200.00
&maxNumberOfPayments=30
&maxTotalAmountOfAllPayments=1500.00
&pinType=NOT_REQUIRED
&requestEnvelope.errorLanguage=en_US
&returnUrl=http://your_return_url
&startingDate=2009-07-13T07%3A00%3A00.000Z
&senderEmail=sender@domain

Came up with the following :

    $ch = curl_init();

    paypal_url = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval';
    paypal_header_options = array();
    paypal_header_options[] = "X-PAYPAL-SECURITY-USERID: api_username";
    paypal_header_options[] = "X-PAYPAL-SECURITY-PASSWORD: api_password";
    paypal_header_options[] = "X-PAYPAL-SECURITY-SIGNATURE: api_signature";
    paypal_header_options[] = "X-PAYPAL-REQUEST-DATA-FORMAT: NV";
    paypal_header_options[] = "X-PAYPAL-RESPONSE-DATA-FORMAT: NV";
    paypal_header_options[] = "X-PAYPAL-APPLICATION-ID: app_id";


    curl_setopt($ch, CURLOPT_URL, paypal_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, paypal_header_options);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    paypal_response = curl_exec($ch);

    curl_close($ch);

so my question is where does this go :

    "cancelUrl=http://your_cancel_url
    &currencyCode=USD
    &endingDate=2009-12-13T08%3A00%3A00.000Z
    &maxAmountPerPayment=200.00
    &maxNumberOfPayments=30
    &maxTotalAmountOfAllPayments=1500.00
    &pinType=NOT_REQUIRED
    &requestEnvelope.errorLanguage=en_US
    &returnUrl=http://your_return_url
    &startingDate=2009-07-13T07%3A00%3A00.000Z
    &senderEmail=sender@domain

and what is -d ? I have searched but wasn't able to find and answer.

You need to push that data inside the post parameter fields as below:

$paypal_data_d = 'cancelUrl=...&senderEmail=sender@domain';
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $paypal_data_d); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM