How to link PayPal webhook and user? - php

I think I'm over looking something incredibly simple here.
When I create a new billing agreement through the PayPal PHP SDK I'm returned to my store by the following URL..
/paypal-success?success=true&token=EC-3K353628LH3197445
I have created a WebHook for the Subscription Created event that posts JSON as follows
{
"id": "WH-5UR49681MC703253M-3S161814MB664705V",
"event_version": "1.0",
"create_time": "2018-03-17T17:21:47.120Z",
"resource_type": "Agreement",
"event_type": "BILLING.SUBSCRIPTION.CREATED",
"summary": "A billing subscription was created",
"resource": {
"agreement_details": {
"outstanding_balance": {
"value": "0.00"
},
"num_cycles_remaining": "0",
"num_cycles_completed": "0",
"next_billing_date": "2018-03-17T10:00:00Z",
"last_payment_date": "2018-03-17T17:21:44Z",
"last_payment_amount": {
"value": "1.00"
},
"final_payment_due_date": "1970-01-01T00:00:00Z",
"failed_payment_count": "0"
},
"description": "x",
"links": [{
"href": "api.sandbox.paypal.com/v1/payments/billing-agreements/I-55KA5N9GPPJW",
"rel": "self",
"method": "GET"
}],
"shipping_address": {
"recipient_name": "test buyer",
"line1": "Spitalfields Arts Market, 112 Brick Lane,",
"city": "London",
"state": "London",
"postal_code": "E1 6RL",
"country_code": "GB"
},
"id": "I-55KA5N9GPPJW",
"state": "Active",
"payer": {
"payment_method": "paypal",
"status": "verified",
"payer_info": {
"email": "jamie-buyer#x.com",
"first_name": "test",
"last_name": "buyer",
"payer_id": "Q3TZFN4F7NHJ6",
"shipping_address": {
"recipient_name": "test buyer",
"line1": "Spitalfields Arts Market, 112 Brick Lane,",
"city": "London",
"state": "London",
"postal_code": "E1 6RL",
"country_code": "GB"
}
}
},
"plan": {
"curr_code": "USD",
"links": [],
"payment_definitions": [{
"type": "REGULAR",
"frequency": "Month",
"frequency_interval": "1",
"amount": {
"value": "49.99"
},
"cycles": "0",
"charge_models": [{
"type": "TAX",
"amount": {
"value": "0.00"
}
},
{
"type": "SHIPPING",
"amount": {
"value": "0.00"
}
}]
}],
"merchant_preferences": {
"setup_fee": {
"value": "1.00"
},
"auto_bill_amount": "YES",
"max_fail_attempts": "0"
}
},
"start_date": "2018-03-17T00:00:00Z"
},
"links": [{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-5UR49681MC703253M-3S161814MB664705V",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-5UR49681MC703253M-3S161814MB664705V/resend",
"rel": "resend",
"method": "POST"
}]
}
That token generated when the user is redirected back to my store does not appear to be in the WebHooks JSON.
How do you link your PayPal users once they are redirected back to your store to the incoming WebHooks?

The token returned in your success url is used to activate the agreement after the user accepts the agreement on PayPal. Once you activate the agreement you can retrieve the agreement id. That id is in your web hook under resources/id. "id": "I-55KA5N9GPPJW". There may be a better way to deal with this but I created a subscription table that associates the agreement id to the user id and a transactions table that has the agreement id and the associated webhook information.

Related

Paypal Integration in PHP checkout/v2/UpdateOrder REFERENCE_ID_NOT_FOUND

I try to implement paypal express checkout in a way that users are able to manipulate their order after they logged in with Paypal and when they are done, click "bux now" and the actual payment is capured.
To do so, I created the order with paypal before with intend "Authorize". The user logs into paypal and comes back to my shop to manage the order. When done, I want to use paypals updateOrder Call to apply the users changes. But It always bounces with error REFERENCE_ID_NOT_FOUND.
Here is the documentation:
https://developer.paypal.com/api/orders/v2/#orders_patch
Here is, what I send to Paypal.
[{
"op": "replace",
"path": "\/purchase_units\/#reference_id=='default'",
"value": [{
"reference_id": "2295037",
"description": "Your order at Shop",
"custom_id": "Shop Id 2295037",
"soft_descriptor": "Shopname",
"invoice_id": "2295037",
"amount": {
"currency_code": "EUR",
"value": 59.98,
"breakdown": {
"item_total": {
"currency_code": "EUR",
"value": 50.4
},
"shipping": {
"currency_code": "EUR",
"value": 0
},
"discount": {
"currency_code": "EUR",
"value": 0
},
"tax_total": {
"currency_code": "EUR",
"value": 9.58
}
}
},
"items": [{
"name": "Product 1",
"description": "Product Descr. 1",
"sku": "1019879",
"unit_amount": {
"currency_code": "EUR",
"value": 16.8
},
"tax": {
"currency_code": "EUR",
"value": 3.19
},
"quantity": "1",
"category": "PHYSICAL_GOODS"
}, {
"name": "Product 2",
"description": "Product Descr. 2",
"sku": "1024593",
"unit_amount": {
"currency_code": "EUR",
"value": 33.61
},
"tax": {
"currency_code": "EUR",
"value": 6.38
},
"quantity": "1",
"category": "PHYSICAL_GOODS"
}],
"shipping": {
"name": {
"full_name": "John Doe"
},
"address": {
"address_line_1": "Badensche Str. 24",
"address_line_2": "",
"admin_area_2": "Berlin",
"postal_code": "10715",
"country_code": "DE"
}
}
}]
}]
The answer from Paypal is "REFERENCE_ID_NOT_FOUND". Paypal itself suggests 'default' if there is only one purchase unit (which it is). I also tried to replace 'default' with the reference_id in our system (which was provided with the createOrder call) or paypal´s own transactionId (which is provided through the endpoint anyway). The error is always the same.
How can I change this call so that Paypal accepts it and updates the order in its system?
It turned out, that I had a mistake by sending the value as an array insterad of an object. With the shops own reference Id it worked after fixing this issue.
The Error code-Reposne by paypal was misleading:
"value": [{
->
"value": {

Magento 2 Register and login REST API

I'm creating an app for magento2 with Rest API. I'm facing the below issues.
Im able to create the user through REST API
auth Berear token : bbiotqwwj04prtja2oum5gvfsqt8dnjh
API : Register
URL : http://demo-acm-2.bird.eu/rest/all/V1/customers
method : POST
Request Body
{
"customer": {
"email": "pradeep123#gmail.com",
"firstname": "Abc",
"lastname": "Xyz",
"storeId": 1
},
"password": "Qwe#123123"
}
Response
{
"id": 3,
"group_id": 1,
"created_at": "2020-04-18 12:30:40",
"updated_at": "2020-04-18 12:30:40",
"created_in": "Default Store View",
"email": "pradeep123#gmail.com",
"firstname": "Abc",
"lastname": "Xyz",
"store_id": 1,
"website_id": 1,
"addresses": [],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
}
}
But when I try to login with the same user to get token it gives me a message like an error. Is there any other way to get a user token/login with rest api in magento2
API: Login
URL: http://demo-acm-2.bird.eu/rest/all/V1/integration/customer/token
method : POST
Request Body
{
"username" : "pradeep123#gmail.com",
"password" : "Qwe#123123"
}
Response
{
"message": "You did not sign in correctly or your account is temporarily disabled."
}
Customer Registration API
API Name: Customer Registration API
Description: Create customer account. Perform necessary business operations like sending email.
API URL: {baseurl}/rest/V1/customers
Method: POST
Body:
{
"customer": {
"email": "testtest123#gmail.com",
"firstname": "Kavin",
"lastname": "Peter",
"addresses": [{
"defaultShipping": true,
"defaultBilling": true,
"firstname": "Kavin",
"lastname": "Peter",
"region": {
"regionCode": "NY",
"region": "New York",
"regionId":43
},
"postcode": "10755",
"street": ["123 Oak Ave"],
"city": "Purchase",
"telephone": "1234567890",
"countryId": "US"
}],
"extension_attributes": {
"is_subscribed": true
},
"custom_attributes": [
{
"attribute_code": "customer_mobile",
"value": "1234567890"
}
]
},
"password": "test123"
}
Response:
{
"id": 55,
"group_id": 1,
"default_billing": "32",
"default_shipping": "32",
"created_at": "2020-08-29 12:10:14",
"updated_at": "2020-08-29 12:10:31",
"created_in": "Default Store View",
"email": "testtest123#gmail.com",
"firstname": "Kavin",
"lastname": "Peter",
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 32,
"customer_id": 55,
"region": {
"region_code": "NY",
"region": "New York",
"region_id": 43
},
"region_id": 43,
"country_id": "US",
"street": [
"123 Oak Ave"
],
"telephone": "1234567890",
"postcode": "10755",
"city": "Purchase",
"firstname": "Kavin",
"lastname": "Peter",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": true
},
"custom_attributes": [
{
"attribute_code": "customer_mobile",
"value": "1234567890"
}
]
}
Login API
API Name: Login API
Description: Create access token for the customer credentials.
API URL: {baseurl}/rest/V1/integration/customer/token
Method: POST
Body:
{
"username": "kirti.nariya#magedelight.com",
"password": "test#$123"
}
Response:
"bdw1x6cb3ntbdj6d4pqfzr8xksjezkv2"

creating invoice is not working through Paypal REST API

I am facing the problem to create the PayPal invoice through the REST API. I got the access token by using auth API of https://api.sandbox.paypal.com/v1/oauth2/token. I am passing the token in the HEADER to create an invoice in the create invoice API of https://api.sandbox.paypal.com/v1/invoicing/invoices/.
Header:
Below is my JSON body.
{
"merchant_info": {
"email": "krpdas-facilitator#gmail.com",
"first_name": "prabhu",
"last_name": "kr",
"business_name": "prabhu kr",
"phone": {
"country_code": "91",
"national_number": "2222233333"
},
"address": {
"line1": "xxxxxxxxxxx,xxxxxxx",
"city": "xxxxxxx",
"state": "xxxxxx",
"postal_code": "888888",
"country_code": "IN"
}
},
"billing_info": [
{
"email": "lalith-facilitator#abacies.com",
"business_name": "test facilitator",
"additional_info": "test facilitator's Test Store",
"address": {
"line1": "1 Main St",
"city": "San Jose",
"state": "CA",
"postal_code": "95131",
"country_code": "US"
}
}
],
"shipping_info": {
"first_name": "Lalith",
"last_name": "Kumar",
"address": {
"line1": "1234 Main Street",
"city": "Anytown",
"state": "CA",
"postal_code": "98765",
"country_code": "US"
}
},
"items": [
{
"name": "Zoom System wireless headphones",
"quantity": 2,
"unit_price": {
"currency": "USD",
"value": "120"
},
"tax": {
"name": "Tax",
"percent": 8
}
},
{
"name": "Bluetooth speaker",
"quantity": 1,
"unit_price": {
"currency": "USD",
"value": "145"
},
"tax": {
"name": "Tax",
"percent": 8
}
}
],
"discount": {
"percent": 1
},
"shipping_cost": {
"amount": {
"currency": "USD",
"value": "10"
}
},
"note": "Thank you for your business.",
"terms": "No refunds after 30 days."
}
I tried with changing the access token and merchant email ids. But always I am getting the same error as 401 unauthorized. I am following the documentation of https://developer.paypal.com/docs/api/invoicing/.
ERROR:
{
"name": "AUTHORIZATION_ERROR",
"message": "Authorization error occurred.",
"information_link": "https://developer.paypal.com/docs/api/invoicing/#errors",
"debug_id": "f89a30f937ced"
}
Scope:
"scope": "https://api.paypal.com/v1/payments/.*
https://uri.paypal.com/services/payments/refund
https://uri.paypal.com/services/applications/webhooks
https://uri.paypal.com/services/payments/payment/authcapture
https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*
https://uri.paypal.com/services/disputes/read-seller
https://uri.paypal.com/services/subscriptions
https://uri.paypal.com/services/disputes/read-buyer
https://api.paypal.com/v1/vault/credit-card openid
https://uri.paypal.com/services/disputes/update-seller
https://uri.paypal.com/services/payments/realtimepayment",

PHP Getting a value from a Multi Layered JSON Array

I seem to be having some trouble with JSON arrays. I was wondering if someone could please assist me.
I have the following JSON Array, and I want to get the figure in invoice_number
$json = '
{
"id": "PAY-7MP775806F4135612LLCHE4I",
"intent": "sale",
"state": "approved",
"cart": "9KA22662P3559221J",
"payer":
{
"payment_method": "paypal",
"status": "VERIFIED",
"payer_info":
{
"email": "accounts-buyer#traxprint.com",
"first_name": "test",
"last_name": "buyer",
"payer_id": "ZR6SRXGS252RG",
"shipping_address":
{
"recipient_name": "test buyer",
"line1": "1 Cheeseman Ave Brighton East",
"city": "Melbourne",
"state": "Victoria",
"postal_code": "3001",
"country_code": "AU"
},
"phone": "0364424947",
"country_code": "AU"
}
},
"transactions":
[
{
"amount":
{
"total": "3.00",
"currency": "USD",
"details":
{
"subtotal": "3.00"
}
},
"payee":
{
"merchant_id": "DSTEYCMCDUL3Y"
},
"description": "Payment description",
"invoice_number": "abc1231522823790",
"item_list":
{
"items":
[
{
"name": "Subscribe",
"sku": "sub1",
"price": "3.00",
"currency": "USD",
"tax": "0.00",
"quantity": 1
}
],
"shipping_address":
{
"recipient_name": "test buyer",
"line1": "1 Cheeseman Ave Brighton East",
"city": "Melbourne",
"state": "Victoria",
"postal_code": "3001",
"country_code": "AU"
}
},
"related_resources":
[
{
"sale":
{
"id": "41B66647LJ233225Y",
"state": "completed",
"amount":
{
"total": "3.00",
"currency": "USD",
"details":
{
"subtotal": "3.00"
}
},
"payment_mode": "INSTANT_TRANSFER",
"protection_eligibility": "ELIGIBLE",
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"transaction_fee":
{
"value": "0.37",
"currency": "USD"
},
"parent_payment": "PAY-7MP775806F4135612LLCHE4I",
"create_time": "2018-04-04T06:36:59Z",
"update_time": "2018-04-04T06:36:59Z",
"links":
[
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/41B66647LJ233225Y",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/41B66647LJ233225Y/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7MP775806F4135612LLCHE4I",
"rel": "parent_payment",
"method": "GET"
}
]
}
}
]
}
],
"create_time": "2018-04-04T06:36:33Z",
"links":
[
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7MP775806F4135612LLCHE4I",
"rel": "self",
"method": "GET"
}
]
}';
The code I was trying to use is but it comes up with error Undefined property: stdClass::$invoice_number
$decoded = json_decode($json);
echo $Info = $decoded->transactions[0]->payee->invoice_number;
Could someone please tell me why this does not work?
Thanks
Robert
echo $Info = $decoded->transactions[0]->invoice_number;

I want to insert item meta in in order through rest API in WooCommerce

I created one text field through WC Field Factory with the name of "Camper Name"
Showing in this product
Now the problem is when I'm filling this field from frontend and placing order this field show in Woocommerce Order API when I'm retrieving data but when I'm trying to insert meta through creating Order API then not going in order and when I'm retrieving order show "meta"[] empty. Can anyone help to resolve this issue?
Here I'm try to create order through POSTMAN
{
"payment_method": "cod",
"payment_method_title": "Direct Bank Transfer",
"set_paid": true,
"billing": {
"first_name": "Ram",
"last_name": "Kumar",
"address_1": "969 Market",
"address_2": "",
"city": "Vsp",
"state": "AP",
"postcode": "530016",
"country": "India",
"email": "ramkumar#example.com",
"phone": "(986) 444-5555"
},
"shipping": {
"first_name": "Ram",
"last_name": "Kumar",
"address_1": "969 Market",
"address_2": "",
"city": "Vsp",
"state": "AP",
"postcode": "530016",
"country": "India"
},
"line_items": [
{
"product_id": 938,
"quantity": 1,
"meta": [
{
"key": "Camper Name",
"label":"Camper Name",
"value":"furqan fazlani"
}
]
},
{
"product_id": 262,
"quantity": 5
}
],
"shipping_lines": [
{
"method_id": "flat_rate",
"method_title": "Flat Rate",
"total": 2
}
]
}

Categories