package ir.almahdi.sandogh_bsa_aza.zarinpal;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.zarinpal.ewallets.purchase.ZarinPal;

import ir.almahdi.sandogh_bsa_aza.Global_var;
import ir.almahdi.sandogh_bsa_aza.R;

public class zarinpal extends AppCompatActivity {
    private ImageView img_par,img_add_hozv_mab;
    private TextView textView,txtsum;
    private Button button;

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zarinpal);
        textView=findViewById(R.id.txtresult);
        txtsum=findViewById(R.id.mabl_sum);

         txtsum.setText(String.valueOf(Global_var.sum_pas_vam_list_select_ozv));


        @SuppressLint("WrongViewCast") ImageView btnPay = findViewById(R.id.btn_main_purchase);
        if (getIntent().getData() != null) {

            ZarinPal.getPurchase(this).verificationPayment(getIntent().getData(), (isPaymentSuccess, refID, paymentRequest) -> {

                Log.i("TAG", "onCallbackResultVerificationPayment: " + refID);
                if (refID!=null){
                    textView.setTextColor(Color.parseColor("#05ff00"));
                    textView.setText(" شماره پیگیری : " + refID);
                }else {
                    textView.setTextColor(Color.parseColor("#ff0000"));
                    textView.setText("' خطا در انجام پرداخت '  " + refID);
                }

            });
        }

        //Button btnPay =  findViewById(R.id.btn_main_purchase);
//        btnPay.setOnClickListener(view -> {
//            Toast.makeText(zarinpal.this, "clicked btn pardakht", Toast.LENGTH_LONG).show();
//            PaymentRequest payment = ZarinPal.getPaymentRequest();
//            payment.setMerchantID("29cefa9c-6ca5-404d-aaaf-5e72ef178995");
//          // payment.setAmount(Long.parseLong(txtsum.getText().toString().substring(0,txtsum.length()-1)));
//           payment.setAmount(1000);
//            payment.setDescription(Global_var.glastname_ozv+" "+Global_var.gname_ozv);
//            payment.setCallbackURL("return://app");
//            payment.setMobile("");
//            payment.setEmail("makkh1361@gmail.com");
//            //payment.isZarinGateEnable(false);
//
//
//            ZarinPal.getPurchase(getApplicationContext()).startPayment(payment, new OnCallbackRequestPaymentListener() {
//
//                @Override
//                public void onCallbackResultPaymentRequest(int status, String authority, Uri paymentGatewayUri, Intent intent) {
//                    if (status == 100) {
//                        startActivity(intent);
//                    } else {
//                        Toast.makeText(zarinpal.this, "خطا در ایجاد درخواست پرداخت", Toast.LENGTH_LONG).show();
//                    }
//                }
//            });
//
//
//        });

    }


}


