Shopify / mobile-buy-sdk-android

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using their credit card.
MIT License
215 stars 136 forks source link

mobile buy sdk how can I place order after payment done via payumoney #467

Closed obabujiApp closed 6 years ago

obabujiApp commented 6 years ago

hello, I have successful done create checkout . I want to receive payments directly through payUMoney and after successful payment how can I convert this checkout to an order.

obabujiApp commented 6 years ago

please reply

sav007 commented 6 years ago

Probably you are looking for com.shopify.buy3.Storefront.MutationQuery#checkoutCompleteFree mutation.

obabujiApp commented 6 years ago

Yes I am looking for com.shopify.buy3.Storefront.MutationQuery#checkoutCompleteFree mutation. But it give me error payment required for this checkout. I have done payment via External provider payUmoney India. My question is how can I associate this checkout to payment and generate order id ?

sav007 commented 6 years ago

In order to run mutation checkoutCompleteFree all line items added to checkout must have $0 price. Otherwise you can't just complete any checkout with outstanding payment.

obabujiApp commented 6 years ago

Leave checkoutCompleteFree .

Is it possible to make payment of checkout via external providers in Android Mobile Buy SDK?

Apart from web checkout or android pay . I want make payment of checkout via external provider payU Money in my android app . I have done payment gate way integration and able to get Payment ID but don't known how to associate checkout with payment.

Currently i am using below code .


public void makePayment(double amount) {
     String phone = "8817766123";;
     String productName = "prodecut name";
     String firstName = "satish";
     String txnId = "0nf7" + System.currentTimeMillis();
     String email="satish@gmail.com";
    String sUrl = "https://test.payumoney.com/mobileapp/payumoney/success.php";
    String fUrl = "https://test.payumoney.com/mobileapp/payumoney/failure.php";
    String udf1 = "";
    String udf2 = "";
    String udf3 = "";
    String udf4 = "";
    String udf5 = "";
    boolean isDebug = false;
    String key = "BxMVyv"; 
    String merchantId = "4938302";
    PayUmoneySdkInitilizer.PaymentParam.Builder builder = new PayUmoneySdkInitilizer.PaymentParam.Builder();

    builder.setAmount(amount)
            .setTnxId(txnId)
            .setPhone(phone)
            .setProductName(productName)
            .setFirstName(firstName)
            .setEmail(email)
            .setsUrl(sUrl)
            .setfUrl(fUrl)
            .setUdf1(udf1)
            .setUdf2(udf2)
            .setUdf3(udf3)
            .setUdf4(udf4)
            .setUdf5(udf5)
            .setIsDebug(isDebug)
            .setKey(key)
            .setMerchantId(merchantId);

    PayUmoneySdkInitilizer.PaymentParam paymentParam = builder.build();

    String salt = "BZpFsWdu";

    String serverCalculatedHash = hashCal(key+"|"+txnId+"|"+amount+"|"+productName+"|"
            +firstName+"|"+email+"|"+udf1+"|"+udf2+"|"+udf3+"|"+udf4+"|"+udf5+"|"+salt);

    paymentParam.setMerchantHash(serverCalculatedHash);

    Log.e("shopify","shopify serverCalculatedHash=> "+serverCalculatedHash);

    PayUmoneySdkInitilizer.startPaymentActivityForResult(CartActivity.this, paymentParam);

  }

  public static String hashCal(String str) {

    byte[] hashseq = str.getBytes();

    StringBuilder hexString = new StringBuilder();

    try {

      MessageDigest algorithm = MessageDigest.getInstance("SHA-512");
      algorithm.reset();
      algorithm.update(hashseq);
      byte messageDigest[] = algorithm.digest();

      for (byte aMessageDigest : messageDigest) {

        String hex = Integer.toHexString(0xFF & aMessageDigest);

        if (hex.length() == 1) {
          hexString.append("0");
        }

        hexString.append(hex);
      }

    } catch (NoSuchAlgorithmException ignored) {

    }

    return hexString.toString();
  }

@Override 
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PayUmoneySdkInitilizer.PAYU_SDK_PAYMENT_REQUEST_CODE) {

      if (resultCode == RESULT_OK) {
        Log.i(TAG, "Success - Payment ID : " + data.getStringExtra(SdkConstants.PAYMENT_ID));
        String **paymentId** = data.getStringExtra(SdkConstants.PAYMENT_ID);

      } else if (resultCode == RESULT_CANCELED) {
        Toast.makeText(this,"cancelled",Toast.LENGTH_SHORT).show();
      } else if (resultCode == PayUmoneySdkInitilizer.RESULT_FAILED) {
        Log.i("app_activity", "failure");

        if (data != null) {
          if (data.getStringExtra(SdkConstants.RESULT).equals("cancel")) {
            Toast.makeText(this,"cancel",Toast.LENGTH_SHORT).show();
          } else {
            Toast.makeText(this,"failure",Toast.LENGTH_SHORT).show();
          }
        }
        //Write your code if there's no result
      } else if (resultCode == PayUmoneySdkInitilizer.RESULT_BACK) {
        Log.i(TAG, "User returned without login");
        Toast.makeText(this,"User returned without login",Toast.LENGTH_SHORT).show();
      }
    }

  }
sav007 commented 6 years ago

No you can't complete checkout with some external payment gateway that not supported by Shopify.