2014-10-10 2 views
1

Я хотел принять платежи из моего магазина, остающиеся на моем складе, и не хотел идти на paypal. Я получил токен доступа, используя curl, но как я мог использовать ниже код. Я думаю, что это код, который я должен использовать для оплаты.принять оплату в paypal с кредитной карты php

curl -v https://api.sandbox.paypal.com/v1/payments/payment \ 
-H 'Content-Type: application/json' \ 
-H 'Authorization: Bearer {accessToken}' \ 
-d '{ 
    "intent":"sale", 
    "redirect_urls":{ 
    "return_url":"http://<return URL here>", 
    "cancel_url":"http://<cancel URL here>" 
    }, 
    "payer":{ 
    "payment_method":"creditcard" 
    }, 
    "transactions":[ 
    { 
     "amount":{ 
     "total":"7.47", 
     "currency":"USD" 
     }, 
     "description":"This is the payment transaction description." 
    } 
    ] 
}' 

Мне просто нужно трюк, чтобы использовать это в локон и произвести оплату путем отправки данных в PayPal и получить в формате JSON

ответ

0

Вы можете использовать следующий код PHP для оплаты кредитной картой:

<?php 

//open connection 
$ch = curl_init(); 

$client="XXXXXXXXXXXXXXXXXXXXX"; 
$secret="XXXXXXXXXXXXXXXXXXXXX"; 

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token"); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $client.":".$secret); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); 

$result = curl_exec($ch); 

if(empty($result))die("Error: No response."); 
else 
{ 
    $json = json_decode($result); 
    print_r($json->access_token); 
} 

// Now doing txn after getting the token 

$ch = curl_init(); 

$data = '{ 
    "intent":"sale", 
    "redirect_urls":{ 
    "return_url":"http://<return URL here>", 
    "cancel_url":"http://<cancel URL here>" 
    }, 
    "payer": { 
    "payment_method": "credit_card", 
    "funding_instruments": [ 
     { 
     "credit_card": { 
      "number": "5500005555555559", 
      "type": "mastercard", 
      "expire_month": 12, 
      "expire_year": 2018, 
      "cvv2": 111, 
      "first_name": "Joe", 
      "last_name": "Shopper" 
     } 
     } 
    ] 
    }, 
    "transactions":[ 
    { 
     "amount":{ 
     "total":"7.47", 
     "currency":"USD" 
     }, 
     "description":"This is the payment transaction description." 
    } 
    ] 
} 
'; 

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment"); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer ".$json->access_token)); 

$result = curl_exec($ch); 


if(empty($result))die("Error: No response."); 
else 
{ 
    $json = json_decode($result); 
    print_r($json); 
} 


?> 

Ответ:

A015dVGr.q9WhQyXl-JnJnkJ.xcFkxJmHmUgCXwYqansoL0{"id":"PAY-58R21143N1956774RKQ365CQ","create_time":"2014-10-10T14:34:50Z","update_time":"2014-10-10T14:34:57Z","state":"approved","intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"mastercard","number":"xxxxxxxxxxxx5559","expire_month":"12","expire_year":"2018","first_name":"Joe","last_name":"Shopper"}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"description":"This is the payment transaction description.","related_resources":[{"sale":{"id":"3J048328N18783546","create_time":"2014-10-10T14:34:50Z","update_time":"2014-10-10T14:34:57Z","amount":{"total":"7.47","currency":"USD"},"state":"completed","parent_payment":"PAY-58R21143N1956774RKQ365CQ","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/3J048328N18783546","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/3J048328N18783546/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-58R21143N1956774RKQ365CQ","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-58R21143N1956774RKQ365CQ","rel":"self","method":"GET"}]}1 
+0

Можете ли вы дать мне типа по ГК, как визы. Они принимаются paypal –

Смежные вопросы