Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is issue in my code Sandbox paypal future payment

I have alredy enable future payments permission in my app and using developer dashboard.but not working yet please find error http://developer.paypal.com/ and log in https://developer.paypal.com/developer/accountStatus there you can see what permits you have.

 $data = array(
                "intent" => "authorize",
                "payer" => array(
                    "payment_method" => "paypal"
                ),
                "transactions" => array(
                    array("amount" => array(
                        "currency" => "USD",
                        "total" => "1.88"
                    ),
                        "description" => "future of sauces")
                ));

        $data_string = json_encode($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
        $headers = array(
            'Content-Type: application/json',
            'PayPal-Client-Metadata-Id: d6743cbb53ea4470a53bfe458f0cb885',
            'Authorization: Bearer A103.B7d5318JDS6NA1zGh02avjCx16oxnBPadUat5z9SlGVGEiOhoAeMuqyz0anGSICS.FAkzECypTS1IXfemHcpVa5yyrGu',
        );
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        //curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        $result = curl_exec($ch);
        $information = curl_getinfo($ch);
        curl_close($ch);
        print_r($information);
        die;

Out put here

{"name":"PERMISSION_DENIED","message":"No permission for the requested operation","information_link":"https://developer.paypal.com/docs/api/#PERMISSION_DENIED","debug_id":"5b39efd4cf370"}Array
(
    [url] => https://api.sandbox.paypal.com/v1/payments/payment
    [content_type] => application/json
    [http_code] => 403
    [header_size] => 592
like image 755
Mohd Zubair Khan Avatar asked Mar 07 '16 06:03

Mohd Zubair Khan


People also ask

How do I test PayPal payments with Sandbox?

During the test phase, use the sandbox endpoints and your sandbox account details in each PayPal API request that you make. Create and manage your set of sandbox accounts from the sandbox Accounts page. Use the Sandbox test site to review the transactions associated with the calls you make using your sandbox accounts.

Why do I keep getting an error message on PayPal?

There are many reasons why a student may encounter an error message while using the PayPal checkout - they could be seeing an error due to insufficient funds, a processing issue or outage on PayPal's side, the student's bank blocking the purchase for security reasons, or a number of other reasons.

How do I test failed transactions in the PayPal Sandbox?

Go to the developer.paypal.com home page. Log into the Dashboard if you are not already and click the pull-down menu beneath your name to select Dashboard . Under the Sandbox heading in the left navigation column, click on Accounts . Locate the sandbox account for which you wish to enable negative testing.

Is PayPal Sandbox real money?

In Sandbox mode, the PayPal gateway functions exactly the same as in Live Mode except transactions do not involve real money. To run sandbox mode you'll need a developer account from https://developer.paypal.com.


1 Answers

I made a Paypal Module, hope this code would help you.

$result_json = json_decode($result);

/* Check if authentication is valid */
if (isset($result_json->access_token))
{
    $enc_data = json_encode($data);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/payments/payment');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, !in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')));
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $enc_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Authorization: Bearer '.$result_json->access_token,
        'PayPal-Client-Metadata-Id: ************'
    ));

    $result = curl_exec($ch);
    $json_result = json_decode($result);
    curl_close($ch);
}

json_encode($data) there are additional information that may not be useful for the transaction you might trying to do but it is an example.

{
    "intent": "sale",
    "payer": {
        "payment_method": "credit_card",
        "payer_info": {
            "email": "...",
            "shipping_address": {
                [...]
            }
        },
        "funding_instruments": [
            {
                "credit_card": {
                    [...]
                    }
                }
            }
        ]
    },
    "transactions": [
        {
            "amount": {
                "total": 32.91,
                "currency": "USD"
            },
            "item_list": {
                "items": [
                    {
                        "quantity": 1,
                        "name": "Product Name",
                        "price": 16.51,
                        "currency": "USD"
                    },
                    {
                        "quantity": 1,
                        "name": "Product Name 2",
                        "price": "16.40",
                        "currency": "USD"
                    },
                    {
                        "quantity": 1,
                        "name": "Shipping",
                        "price": 0,
                        "currency": "USD"
                    }
                ],
                "shipping_address": {
                    [...]
                }
            }
        }
    ]
}
like image 179
mmoustai Avatar answered Sep 30 '22 15:09

mmoustai