Merchant API integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
We would like to link our CRM system with PayPal API to receive payments from
our clients. So, first, accordingly to this manual links:
- https://developer.paypal.com/api/rest/authentication/
- https://developer.paypal.com/api/payments/v1/
we make test to create payment by sending HTTP requests to REST API like this (code snippets):
-------------------------------- Create test payment -------------------------------------
my $payment = http_request({
'URL' => "https://api-m.paypal.com/v1/payments/payment",
'method' => 'POST',
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => sprintf("%s %s", $TOKEN_TYPE, $TOKEN)
],
'data' => JSON::XS->new->encode(<TEST_PAYMENT_DATA>) <-------- See below
});
--------------------------------- TEST PAYMENT DATA --------------------------------------
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "1.00",
"currency": "USD",
"details": {
"subtotal": "1.00",
"tax": "0.00",
"shipping": "0.00",
"handling_fee": "0.00",
"shipping_discount": "0.00",
"insurance": "0.00"
}
},
"description": "Hosting services",
"invoice_number": "12341234123",
"item_list": {
"items": [
{
"name": "Hosting services",
"description": "Hosting services",
"quantity": "1",
"price": "1",
"tax": "0.00",
"sku": "0",
"currency": "USD"
}
]
}
}
],
"note_to_payer": "Contact us for any questions on your order.",
"redirect_urls": {
"return_url": "https://<CRM-HOST>/success",
"cancel_url": "https://<CRM-HOST>/fail"
}
}
As result we receive JSON data like this:
{
"intent" : "sale",
"note_to_payer" : "Contact us for any questions on your order.",
"create_time" : "2022-03-30T04:36:09Z",
"links" : [
{
"rel" : "self",
"href" : "https://api.paypal.com/v1/payments/payment/PAYID-MJB54OI54M31022JP788392W",
"method" : "GET"
},
{
"method" : "REDIRECT",
"rel" : "approval_url",
"href" : "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4PK884140U315324E"
},
{
"rel" : "execute",
"href" : "https://api.paypal.com/v1/payments/payment/PAYID-MJB54OI54M31022JP788392W/execute",
"method" : "POST"
}
],
"payer" : {
"payment_method" : "paypal"
},
"state" : "created",
"transactions" : [
{
"item_list" : {
"items" : [
{
"currency" : "USD",
"name" : "Hosting services",
"quantity" : 1,
"price" : "1.00",
"tax" : "0.00",
"description" : "Hosting services",
"sku" : "0"
}
]
},
"description" : "Hosting services",
"related_resources" : [],
"amount" : {
"details" : {
"subtotal" : "1.00",
"handling_fee" : "0.00",
"insurance" : "0.00",
"shipping_discount" : "0.00",
"shipping" : "0.00",
"tax" : "0.00"
},
"currency" : "USD",
"total" : "1.00"
},
"invoice_number" : "12341234123" <---- for test
}
],
"id" : "PAYID-MJB54OI54M31022JP788392W"
}
Next we go to received HATEOAS link:
{
"method" : "REDIRECT",
"rel" : "approval_url",
"href" : "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4PK884140U315324E"
}
log in and pay...
As result, money is not credited to the account, and
less minute later we receive callback from PayPal system and hook it:
{
"create_time" : "2022-03-30T04:42:22.823Z",
"event_type" : "PAYMENTS.PAYMENT.CREATED",
"event_version" : "1.0",
"id" : "WH-9LT6144975397733D-5DM501304A030602R",
"links" : [
{
"href" : "https://api.paypal.com/v1/notifications/webhooks-events/WH-9LT6144975397733D-5DM501304A030602R",
"method" : "GET",
"rel" : "self"
},
{
"href" : "https://api.paypal.com/v1/notifications/webhooks-events/WH-9LT6144975397733D-5DM501304A030602R/resend",
"method" : "POST",
"rel" : "resend"
}
],
"resource" : {
"cart" : "4PK884140U315324E",
"create_time" : "2022-03-30T04:36:09Z",
"id" : "PAYID-MJB54OI54M31022JP788392W",
"intent" : "sale",
"links" : [
{
"href" : "https://api.paypal.com/v1/payments/payment/PAYID-MJB54OI54M31022JP788392W",
"method" : "GET",
"rel" : "self"
},
{
"href" : "https://api.paypal.com/v1/payments/payment/PAYID-MJB54OI54M31022JP788392W/execute",
"method" : "POST",
"rel" : "execute"
},
{
"href" : "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4PK884140U315324E",
"method" : "REDIRECT",
"rel" : "approval_url"
}
],
"note_to_payer" : "Contact us for any questions on your order.",
"payer" : {
"payer_info" : {
"country_code" : "UA",
"email" : "<email>",
"first_name" : "<first_name>",
"last_name" : "<last_name>",
"middle_name" : "<middle_name>",
"payer_id" : "2EPCWJT2RDRGC",
"shipping_address" : {
"city" : "<city>",
"country_code" : "<contry_code>",
"default_address" : false,
"disable_for_transaction" : false,
"line1" : "<address>",
"postal_code" : "<code>",
"preferred_address" : false,
"primary_address" : false,
"recipient_name" : "<recipient_name>",
"state" : ""
}
},
"payment_method" : "paypal",
"status" : "VERIFIED"
},
"redirect_urls" : {
"cancel_url" : "https://<CRM-HOST>/fail",
"return_url" : "https://<CRM-HOST>/success?paymentId=PAYID-MJB54OI54M31022JP788392W"
},
"state" : "created",
"transactions" : [
{
"amount" : {
"currency" : "USD",
"details" : {
"handling_fee" : "0.00",
"insurance" : "0.00",
"shipping" : "0.00",
"shipping_discount" : "0.00",
"subtotal" : "1.00",
"tax" : "0.00"
},
"total" : "1.00"
},
"description" : "Hosting services",
"invoice_number" : "12341234123",
"item_list" : {
"items" : [
{
"currency" : "USD",
"description" : "Hosting services",
"name" : "Hosting services",
"price" : "1.00",
"quantity" : 1,
"sku" : "0",
"tax" : "0.00"
}
],
"shipping_address" : {
"city" : "<city>",
"country_code" : "<contry_code>",
"default_address" : false,
"disable_for_transaction" : false,
"line1" : "<address>",
"postal_code" : "<code>",
"preferred_address" : false,
"primary_address" : false,
"recipient_name" : "<recipient_name>",
"state" : ""
}
},
"payee" : {
"email" : "<payee_email>",
"merchant_id" : "P39D3PDZTX9DG"
},
"related_resources" : []
}
],
"update_time" : "2022-03-30T04:42:22Z"
},
"resource_type" : "payment",
"summary" : "Checkout payment is created and approved by buyer"
}
Help us please, what should we do next to success pay?
Thank you!
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Using Paypal Smart Buttons for checkout sometimes fails with Debit/ Credit Cards Form in Braintree Client-side Integration (JS, iOS, Android SDKs)
- Sandbox account not generating IPNs in Sandbox Environment
- Pending Transaction - CLearly Declined by Merchant in PayPal Payments Standard
- When PayPai and CRM are integrated, it is not authorized to initiate PayPai from CRM. in REST APIs
- Need help to integrate PayPal Checkout (PPCP) with OpenCart? in PayPal Upgrade Community