D
D
ddddeity2020-05-02 13:23:41
PHP
ddddeity, 2020-05-02 13:23:41

The goods do not come to the post office after payment?

I connected the store to anypay, the payment goes through, but the goods don’t come to the buyer’s mail, only a receipt for payment from the payment system and that’s it ... I did it according to the documentation, I don’t understand where I messed up .. before that there was another payment, but the documentation is almost identical, everything norms worked.

here is the documentation itself: https://anypay.io/doc#signature_form

Here is the code for the purchase process

<?php
session_start();
if(!isset($_SESSION['redirect_link'])){
  header("location: ../index.php");
}
if(isset($_GET['email']) and isset($_GET['product'])){
  $email = $_GET['email'];
  $product = $_GET['product'];
  if($product == 1){
    $amount = 5;
  }
  else if($product == 2){
    $amount = 50;
  }
  else if($product == 3){
    $amount = 99;
  }
  else if($product == 4){
    $amount = 320;
  }
  else if($product == 5){
    $amount = 230;
  }
  else if($product == 6){
    $amount = 300;	
  }
  else if($product == 7){
    $amount = 99;	
  }
  $errors = array(
    'error' => False,
    'message' => ''
  );
  if($product != 1 && $product != 2 && $product != 3 && $product != 4 && $product != 5 && $product != 6 && $product != 7){
    header("location: ../index.php");
  }
  if(strlen($email) == 0){
    if($errors['error'] == False){
      $errors['error'] = True;
      $errors['message'] = 'Пожалуйста заполните поле вашего e-mail адреса';
    }
  }
  if(!preg_match('/^[a-zA-Z0-9]{1}[a-zA-Z0-9_.-]{3,}\@[a-zA-Z]+\.[a-z]{2,}$/', $email)){
    if($errors['error'] == False){
      $errors['error'] = True;
      $errors['message'] = 'Не валидный e-mail адрес';
    }
  }
  if(strlen($email) > 56){
    if($errors['error'] == False){
      $errors['error'] = True;
      $errors['message'] = 'e-mail адрес очень длинный';
    }
  }
  if($errors['error'] == False){
    $shop_id = 'ид магазина';
        $secret_key = 'секретный ключ';
        $amount = $amount;
        $pay_id = time();
        $currency = 'RUB';
           
        $sign = md5($currency.':'.$amount.':'.$secret_key.':'.$shop_id.':'.$pay_id);  //Генерация ключа
        header("location: https://anypay.io/merchant?merchant_id=".$shop_id."&amount=".$amount."&pay_id=".$pay_id."&currency=".'RUB'."&sign=".$sign."&email=".$email."");
  }
  else{
    $_SESSION['error'] = $errors['message'];
    header("location: ".$_SESSION['redirect_link']."");
  }
}
else{
  header("location: ".$_SESSION['redirect_link']."");
}
?>


Here is the payment verification code
<?php
include "includes/db.php";
include "includes/querys.php";
include "includes/setmailer.php";
$shop_id = 'ид магазина';
$secret_key = 'секретный ключ';
$ordered_email = $_REQUEST['custom_field'];
if($_REQUEST['amount'] == 5){
  $product = 1;
  $product_text = '1 продукт';
}
else if($_REQUEST['amount'] == 50){
  $product = 2;
  $product_text = '2 продукт';
}
else if($_REQUEST['amount'] == 99){
  $product = 3;
  $product_text = '3 продукт';
}
else if($_REQUEST['amount'] == 320){
  $product = 4;
  $product_text = '4 продукт';
}
else if($_REQUEST['amount'] == 230){
  $product = 5;
  $product_text = '5 продукт';
}
else if($_REQUEST['amount'] == 300){
  $product = 6;
  $product_text = '6 продукт';
}
else if($_REQUEST['amount'] == 99){
  $product = 7;
  $product_text = '7 продукт';
}

$signature = md5($shop_id.':'.$_REQUEST['amount'].':'.$_REQUEST['pay_id'].':'.$secret_key);

if ($signature != $_REQUEST['sign']) {
    die('bad sign!');
}

die('OK'); 
$request->setdb($conn,'products','game_type',$product,'used',0,1);
$key = $request->select();
if($key->num_rows > 0){
  $key_row = $key->fetch_array();
  $key_product = $key_row['key_product'];
  $emailed->set($ordered_email, 'Спасибо за покупку,ваш ключ ждёт вас!','Поздравляем: '.$product_text.', ваш - ключ: '.$key_product.'');
  $emailed->send();
  $request->setdb($conn,'products','used',1,'id',$key_row['id']);
  $request->update();
  $request->setdb($conn,'products','ordered_email',$ordered_email,'id',$key_row['id']);
  $request->update();
}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexalexes, 2020-05-02
@alexalexes

Include in a separate php file the include module "includes/setmailer.php";
and try sending something to yourself, separate from the payment business logic.
PS: You may have to fix the config of this module in terms of the smtp protocol.
PPS: The hosting from which you send the letter may have features with the work of smtp - check it out.

Q
qfake, 2020-05-03
@qfake

It's night and I'm inattentive, or do you finish the script before the database is written and everything else?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question