Api Oppwa付款按钮,foreach问题

时间:2020-05-15 18:20:17

标签: php api

我正在将付款按钮与Oppwa API集成在一起, 但是有了带给我“ CheckoutId”的方法。 我必须发送所有参数会发生什么情况。

$total = 120;
$iva = 004012000000000012;
$totalTarifa12 = 053012000000000100;
$totalBase0 = 052012000000000200;
$email = "JonathanVeraMarin98@outlook.com";
$primer_nombre = "Jonathan";
$segundo_nombre = "Fernando";
$apellido = "Vera";
$cedula = "0952152525";
 $trx = 123456789;
    $ip_address = '05100817913101';
   $finger = 'https://test.oppwa.com/v1/checkouts';
 $merchterm= '1000000505_PD100406';
$telefono ='2172161';
$direccion_cliente = 11222;
  $pais_cliente = 121212;
 $direccion_entrega = '1600 Pennsylvania Ave NW';
 $pais_entrega = 121212;
  $checkoutId = prepareCheckout($items,$total,$iva,$totalTarifa12,$totalBase0,$email,$primer_nombre,$segundo_nombre,$apellido,$cedula,$trx,$ip_address,$finger,$merchterm,$telefono,$direccion_cliente,$pais_cliente,$direccion_entrega,$pais_entrega);

这些是我发送给函数的已刻录参数的值

       function prepareCheckout($items,$total,$iva,$totalTarifa12,$totalBase0,$email,$primer_nombre
    ,$segundo_nombre,$apellido,$cedula,$trx,$ip_address,$finger,$merchterm,
    $telefono,$direccion_cliente,$pais_cliente,$direccion_entrega,$pais_entrega){
         $finger = urlencode($finger);
$i =0;
$url = "https://test.oppwa.com/v1/checkouts";
$iva = str_replace('.', '', $iva);
$totalTarifa12 = str_replace('.', '', $totalTarifa12);
$totalBase0 = str_replace('.', '', $totalBase0);
$valueIva = str_pad($iva,12,'0'.STR_PAD_LEFT);
$valueTotalIva = str_pad($totalTarifa12,12,'0'.STR_PAD_LEFT);
$valueIvaTotalBase0 = str_pad($totalBase0,12,'0'.STR_PAD_LEFT);
 $data = "authentication.userId=8a8294184b4f2868014b4f86f767015d" .
    "&authentication.password=F8T7N4PD" .
    "&authentication.entityId=8a8294184b4f2868014b4f87bf160173" . 
   "&amount=".$total.
   "&currency=USD".
    "&paymentType=DB".
    "&customer.givenName=".$primer_nombre.
    "&customer.middleName=".$segundo_nombre.
    "&customer.surname=".$apellido.
    "&customer.ip=".$ip_address.
    "&customer.merchantCustomerId=00000000001".
    "&merchantTransactionId=transaction_".$trx.
    "&customer.email=".$email.
    "&customer.identificationDocType=IDCAD".
    "&customer.identificationDocId=".$cedula.
    "&customer.phone=".$telefono.
    "&billing.street1=".$direccion_cliente.
    "&billing.country=".$pais_cliente.
    "&shipping.street1=".$direccion_entrega.
    "&shipping.country=".$pais_entrega.
    "&risk.paramters[USER_DATA2]=MiComercio".
    "customParamters[".$merchterm."]=00810030070103910004012".$valueIva.
    "05100817913101052012".$valueIvaTotalBase0."053012".$valueTotalIva;
    foreach ($items["cart"] as $c )
    {
    $data.="&cart.items[".$i."].name =".$c["product_name"];
    $data.="&cart.items[".$i."].description ="."Descripcion: ".$c["product_name"];
    $data.="&cart.items[".$i."].price =".$c["product_price"];
    $data.="&cart.items[".$i."].quantity= ".$c["q"];


    }
    $data.= "&testMode=EXTERNAL";      
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization:Bearer OGE4Mjk0MTg1MzNjZjMxZDAxNTMzZDA2ZmQwNDA3NDh8WHQ3RjIyUUVOWA=='));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true inproduction
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $responseData = curl_exec($ch);

      if(curl_errno($ch)) {
       return curl_error($ch);
         }
      curl_close($ch);
        return $responseData;
         }

我生成checkoutId的函数。

我遇到的问题是在foreach中,我知道它正在通过一个数组,但是由于我不知道$ items ['cart']指的是什么条件而报错

foreach ($items["cart"] as $c )
    {
    $data.="&cart.items[".$i."].name =".$c["product_name"];
    $data.="&cart.items[".$i."].description ="."Descripcion: ".$c["product_name"];
    $data.="&cart.items[".$i."].price =".$c["product_price"];
    $data.="&cart.items[".$i."].quantity= ".$c["q"];


    }

我已经这样尝试过

$items  = array();


 $items['product_name'] = 'Software';
 $items['product_name'] = 'Hola';
   $items['product_price'] = '50';
     $items['q'] = '1';

我受伤了: 警告:第63行的C:\ xampp \ htdocs \ Datafast \ index.php中为foreach()提供了无效的参数

`

0 个答案:

没有答案