代码之家  ›  专栏  ›  技术社区  ›  Sharma Vikram

PayPal模块的Magento 2 REST api

  •  2
  • Sharma Vikram  · 技术社区  · 6 年前

    我正在创建一个电子商务应用程序使用 REST api作为后端和 在前端技术方面。

    我已经成功地集成了添加/更新/删除/列表api

    我使用贝宝的支付方式,得到成功的响应后,从贝宝,我需要存储贝宝响应到Magento 2数据库,但它返回了一个错误。

    我需要post请求的参数名。

     "message": "No such entity with %fieldName = %fieldValue",
    "parameters": {
        "fieldName": "cartId",
        "fieldValue": null
    }
    

    发布URL

    http://127.0.0.1/magento2/index.php/rest/V1/carts/mine/payment-information
    

        {
        "email": "vikram.sharma@xymob.in",
        "cartId": 2,
        "billing_address": {
                        "email": "vikram.sharma@xymob.in",
                    "region": "New York",
                    "region_id": 43,
                    "region_code": "NY",
                        "country_id": "US",
                        "street": ["123 Oak Ave"],
                        "postcode": "10577",
                        "city": "Purchase",
                        "telephone": "512-555-1111",
                        "firstname": "Jane",
                        "lastname": "Doe"
             },
        "paymentMethod": {
            "method": "paypal_express",
            "additional_data": {
                "paypal_express_payment_payload": "{\"id\":\"PAY-3F734824YB370341TLOQNO3Y\",\"intent\":\"sale\",\"state\":\"approved\",\"cart\":\"9W5899822J563802S\",\"create_time\":\"2018-09-18T10:50:31Z\",\"payer\":{\"payment_method\":\"paypal\",\"status\":\"VERIFIED\",\"payer_info\":{\"email\":\"vikramdummy-buyer@outlook.com\",\"first_name\":\"test\",\"middle_name\":\"test\",\"last_name\":\"buyer\",\"payer_id\":\"CAQR5B2LGGB9S\",\"country_code\":\"US\",\"shipping_address\":{\"recipient_name\":\"test buyer\",\"line1\":\"1 Main St\",\"city\":\"San Jose\",\"state\":\"CA\",\"postal_code\":\"95131\",\"country_code\":\"US\"}}},\"transactions\":[{\"amount\":{\"total\":\"102.00\",\"currency\":\"USD\",\"details\":{}},\"item_list\":{\"items\":[{\"name\":\"SATA HardDisk\",\"price\":\"1.00\",\"currency\":\"USD\",\"quantity\":2},{\"name\":\"Logitech Mouse\",\"price\":\"100.00\",\"currency\":\"USD\",\"quantity\":1}]},\"related_resources\":[{\"sale\":{\"id\":\"7CM65242K9229980W\",\"state\":\"completed\",\"payment_mode\":\"INSTANT_TRANSFER\",\"protection_eligibility\":\"ELIGIBLE\",\"parent_payment\":\"PAY-3F734824YB370341TLOQNO3Y\",\"create_time\":\"2018-09-18T10:50:29Z\",\"update_time\":\"2018-09-18T10:50:29Z\",\"amount\":{\"total\":\"102.00\",\"currency\":\"USD\",\"details\":{\"subtotal\":\"102.00\"}}}}]}]}",
                "paypal_express_checkout_token": "EC-9W5899822J563802S",
                "paypal_express_checkout_redirect_required": false,
                "paypal_express_checkout_payer_id": "CAQR5B2LGGB9S"
            }
        }
    }
    

    Rest api for order place , Magento swagger

    这是我的PHP curl代码邮递员:-

     <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "http://127.0.0.1/magento2/index.php/rest/V1/carts/mine/payment-information",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "{\n  \"email\": \"vikram.sharma@xymob.in\",\n  \"billing_address\": {\n              \"email\": \"vikram.sharma@xymob.in\",\n              \"region\": \"New York\",\n              \"region_id\": 43,\n              \"region_code\": \"NY\",\n              \"country_id\": \"US\",\n              \"street\": [\"123 Oak Ave\"],\n              \"postcode\": \"10577\",\n              \"city\": \"Purchase\",\n              \"telephone\": \"512-555-1111\",\n              \"firstname\": \"Jane\",\n              \"lastname\": \"Doe\"\n     },\n    \"paymentMethod\": {\n    \"method\": \"paypal_express\",\n    \"additional_data\": {\n      \"paypal_express_payment_payload\": \"{\\\"id\\\":\\\"PAY-3F734824YB370341TLOQNO3Y\\\",\\\"intent\\\":\\\"sale\\\",\\\"state\\\":\\\"approved\\\",\\\"cart\\\":\\\"9W5899822J563802S\\\",\\\"create_time\\\":\\\"2018-09-18T10:50:31Z\\\",\\\"payer\\\":{\\\"payment_method\\\":\\\"paypal\\\",\\\"status\\\":\\\"VERIFIED\\\",\\\"payer_info\\\":{\\\"email\\\":\\\"vikramdummy-buyer@outlook.com\\\",\\\"first_name\\\":\\\"test\\\",\\\"middle_name\\\":\\\"test\\\",\\\"last_name\\\":\\\"buyer\\\",\\\"payer_id\\\":\\\"CAQR5B2LGGB9S\\\",\\\"country_code\\\":\\\"US\\\",\\\"shipping_address\\\":{\\\"recipient_name\\\":\\\"test buyer\\\",\\\"line1\\\":\\\"1 Main St\\\",\\\"city\\\":\\\"San Jose\\\",\\\"state\\\":\\\"CA\\\",\\\"postal_code\\\":\\\"95131\\\",\\\"country_code\\\":\\\"US\\\"}}},\\\"transactions\\\":[{\\\"amount\\\":{\\\"total\\\":\\\"102.00\\\",\\\"currency\\\":\\\"USD\\\",\\\"details\\\":{}},\\\"item_list\\\":{\\\"items\\\":[{\\\"name\\\":\\\"SATA HardDisk\\\",\\\"price\\\":\\\"1.00\\\",\\\"currency\\\":\\\"USD\\\",\\\"quantity\\\":2},{\\\"name\\\":\\\"Logitech Mouse\\\",\\\"price\\\":\\\"100.00\\\",\\\"currency\\\":\\\"USD\\\",\\\"quantity\\\":1}]},\\\"related_resources\\\":[{\\\"sale\\\":{\\\"id\\\":\\\"7CM65242K9229980W\\\",\\\"state\\\":\\\"completed\\\",\\\"payment_mode\\\":\\\"INSTANT_TRANSFER\\\",\\\"protection_eligibility\\\":\\\"ELIGIBLE\\\",\\\"parent_payment\\\":\\\"PAY-3F734824YB370341TLOQNO3Y\\\",\\\"create_time\\\":\\\"2018-09-18T10:50:29Z\\\",\\\"update_time\\\":\\\"2018-09-18T10:50:29Z\\\",\\\"amount\\\":{\\\"total\\\":\\\"102.00\\\",\\\"currency\\\":\\\"USD\\\",\\\"details\\\":{\\\"subtotal\\\":\\\"102.00\\\"}}}}]}]}\",\n      \"paypal_express_checkout_token\": \"EC-9W5899822J563802S\",\n      \"paypal_express_checkout_redirect_required\": false,\n      \"paypal_express_checkout_payer_id\": \"CAQR5B2LGGB9S\"\n    }\n  }\n}",
      CURLOPT_HTTPHEADER => array(
        "authorization: Bearer 1fpiepedxeqm6fse81icfv8yx4hmwbi3",
        "cache-control: no-cache",
        "content-type: application/json",
        "postman-token: 85951c6b-ff29-b785-65c9-d10c39a34424"
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
    
    1 回复  |  直到 5 年前
        1
  •  2
  •   Jouby Wasim    6 年前

    cartId ,尝试使用 cart_id .

    webapi.xml ,我们有:

    <route url="/V1/carts/mine/payment-information" method="POST">
         <service class="Magento\Checkout\Api\PaymentInformationManagementInterface" method="savePaymentInformationAndPlaceOrder"/>
         <resources>
             <resource ref="self" />
         </resources>
         <data>
             <parameter name="cartId" force="true">%cart_id%</parameter>
         </data>
     </route>
    

    购物车id 卡蒂德 .