使用Paypal控制台。付款后登录数据向收款人发送电子邮件确认

问题描述 投票:0回答:1

我在 Paypal 交易后收到数据。该数据被写入console.log。我想做的是向客户发送一封确认电子邮件,但是我不知道如何使用 console.log 中的数据用于 php 邮件脚本。

console.log中的数据如下:

{
    "intent": "CAPTURE",
    "status": "COMPLETED",
    "purchase_units": [
        {
            "reference_id": "default",
            "amount": {
                "currency_code": "GBP",
                "value": "7.99",
                "breakdown": {
                    "item_total": {
                        "currency_code": "GBP",
                        "value": "7.99"
                    },
                    "shipping": {
                        "currency_code": "GBP",
                        "value": "0.00"
                    },
                    "handling": {
                        "currency_code": "GBP",
                        "value": "0.00"
                    },
                    "insurance": {
                        "currency_code": "GBP",
                        "value": "0.00"
                    },
                    "shipping_discount": {
                        "currency_code": "GBP",
                        "value": "0.00"
                    }
                }
            },
            "payee": {
                "email_address": "[email protected]",
                "merchant_id": "XMPRDEBVATPBG"
            },
            "description": "JHS Kingsman KSS11 Keyboard Bench in Black ",
            "items": [
                {
                    "name": "JHS Kingsman KSS11 Keyboard Bench in Black ",
                    "unit_amount": {
                        "currency_code": "GBP",
                        "value": "5.00"
                    },
                    "tax": {
                        "currency_code": "GBP",
                        "value": "0.00"
                    },
                    "quantity": "1"
                },
                {
                    "name": "Postage and Packaging",
                    "unit_amount": {
                        "currency_code": "GBP",
                        "value": "2.99"
                    },
                    "tax": {
                        "currency_code": "GBP",
                        "value": "0.00"
                    },
                    "quantity": "1"
                }
            ],
            "shipping": {
                "name": {
                    "full_name": "John Doe"
                },
                "address": {
                    "address_line_1": "Whittaker House",
                    "address_line_2": "2 Whittaker Avenue",
                    "admin_area_2": "Richmond",
                    "admin_area_1": "Surrey",
                    "postal_code": "TW9 1EH",
                    "country_code": "GB"
                }
            },
            "payments": {
                "captures": [
                    {
                        "id": "**5XA41291M3793842K**",
                        "status": "COMPLETED",
                        "amount": {
                            "currency_code": "GBP",
                            "value": "7.99"
                        },
                        "final_capture": true,
                        "seller_protection": {
                            "status": "ELIGIBLE",
                            "dispute_categories": [
                                "ITEM_NOT_RECEIVED",
                                "UNAUTHORIZED_TRANSACTION"
                            ]
                        },
                        "create_time": "2024-03-01T13:59:46Z",
                        "update_time": "2024-03-01T13:59:46Z"
                    }
                ]
            }
        }
    ],
    "payer": {
        "name": {
            "given_name": "John",
            "surname": "Doe"
        },
        "email_address": "[email protected]",
        "payer_id": "VJXBXRRPJU2L4",
        "address": {
            "country_code": "GB"
        }
    },
    "create_time": "2024-03-01T13:59:01Z",
    "update_time": "2024-03-01T13:59:46Z",
    "links": [
        {
            "href": "[https://api.sandbox.paypal.com/v2/checkout/orders/3KJ025674H470494E](https://api.sandbox.paypal.com/v2/checkout/orders/3KJ025674H470494E)",
            "rel": "self",
            "method": "GET"
        }
    ]
}

我可以接收数据如下:

onApprove: (data, actions) => { 

          return actions.order.capture().then(function(orderData) {
    
            // Successful capture! For dev/demo purposes:
    
            console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
              console.log(data);
    
            const transaction = orderData.purchase_units[0].payments.captures[0];
              const detail = orderData.purchase_units[0].items[0];
              const payee = orderData.purchase_units[0];

// alert(Transaction ${transaction.status}: ${transaction.id}\n\nSee console for all available details);
// When ready to go live, remove the alert and show a success message within this page. For example:

          const element = document.getElementById('paypal-button-container');
    
           element.innerHTML = 'Thank you for your payment! <br> Your Order ID is:  ';
              document.querySelector("#order_data").innerText =    transaction.id ;
          });
    
        }

这确实显示了交易 ID。

接下来我想做的是向客户发送一封电子邮件确认我已收到带有订单数据的订单。我的java不是很好,所以我想使用php脚本。

我想使用的php脚本如下:

 $emailsubject = 'Order Confirmation';

 
 $webmaster = '[email protected]';

 $Transaction = **transaction.id**;

 $email = **payee.payee.email_address**;

 $Product = **detail.name[]**;

     $fromAddress = "From: $webmaster\r\n" .

 "Reply-To: $email\r\n" .
 "X-Mailer: PHP/" . phpversion();

     $Body = <<<EOD

 Thank you for your order.
 Your transaction id = $Transaction
 Transaction Details:
 $Product

 EOD;

     $headers = "From: $email\r\n" .

 "Reply-To: $webmaster\r\n" .
 "X-Mailer: PHP/" . phpversion();   
 $headers .="content-type: text/html\r\n";

     $succes = mail($webmaster, $emailsubject, $Body, $fromAddress);

问题是我不知道如何在 php 邮件脚本中使用 console.log 中的数据(请参阅 php 脚本中的粗体文本)。抱歉,如果这是一个非常愚蠢的问题,但我不知道从哪里开始寻找。欢迎任何帮助

java php paypal paypal-ipn
1个回答
0
投票

actions.order.create() 和 actions.order.capture() 均已弃用,不应用于任何新集成。他们将日落(将来删除支持)。

更改您的代码以从后端创建和捕获订单。有关详细信息和示例,请参阅标准集成指南

只有成功捕获后,才会从后端发送确认电子邮件。

© www.soinside.com 2019 - 2024. All rights reserved.