question

slicedev avatar image
slicedev asked nikki answered

Is OrderV31Connector.createLineItemsFrom() method usable for custom applications?

Hello everyone,

I'm getting the "java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.clover.common2.clover.Clover.getUserOrderTypes()' on a null object reference" exception on an attempt to use the connector.createLineItemsFrom() method.

My steps are next:

  1. Register an Activity to be aware of the clover.intent.action.MODIFY_ORDER intent.
  2. In the Register app create order with two or more items and tap Pay.
  3. On the Register's Payment activity tap the custom button to start the Activity.
  4. The Activity contains Split Order button that runs code like next:
  5. override suspend fun splitOrder(
        orderId: OrderId, // just a wrapper around the Order.id string
        lineItems: List<LineItem>,
    ): Order {
        val connector = connector.first() // provides OrderConnector instance
        return withContext(Dispatchers.IO) {
            try {
                val order = connector.createOrder(Order())
                val items = connector.createLineItemsFrom(orderId.value, order.id, lineItems.map { it.id })
                connector.getOrder(order.id)
            } catch (e: Exception) {
                throw e
            }
        }
    }

it fails on the connector.createLineItemsFrom() line, I tried to use the deprecated copyLineItems with exactly same result.

I'm trying to work around this issue with implementing a Split Order functionality through Inventory but it is hard to manage and update two orders.

I found similar topic here but unfortunately w/o a clear response https://community.clover.com/questions/30998/orderconnector-createlineitemsfrom-has-stopped-wor.html

This one could be similar as well https://community.clover.com/questions/23506/split-customer-amount-issue-with-adding-discount-u.html

Any help would be appreciated.

Thanks



OrdersClover Android SDK
1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

slicedev avatar image slicedev commented ·

Here is a related logcat: SPLIT_ORDER_logcat.txt

0 Likes 0 ·
digilax605 avatar image
digilax605 answered

Enjoy a family-friendly game of uno online with simplified rules and a kid-friendly interface.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

slicedev avatar image
slicedev answered

Hello Clover Support Team,

I tried to do the same using the IOrderServiceV3_1 instead of OrderConnector, but got the same result.

Here is how I tried to use the IOrderServiceV3_1 service:

1. Create a ServiceConnection and initialize IOrderServiceV3_1 instance:

private var orderService: IOrderServiceV3_1? = null
private val orderServiceConnection = object : ServiceConnection {
    override fun onServiceConnected(name: ComponentName, service: IBinder) {
        orderService = IOrderServiceV3_1.Stub.asInterface(service)
    }

    override fun onServiceDisconnected(name: ComponentName) {
        orderService = null
    }
}

2. Bind service in the onCreate method and unbind in the onDestroy:

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
val intent = Intent(OrderIntent.ACTION_ORDER_SERVICE_V3_1)
intent.putExtra(Intents.EXTRA_ACCOUNT, CloverAccount.getAccount(this))
intent.putExtra(Intents.EXTRA_VERSION, 3)
intent.setPackage("com.clover.engine")
bindService(intent, orderServiceConnection, Context.BIND_AUTO_CREATE)
...
}

override fun onDestroy() {
    super.onDestroy()
    unbindService(orderServiceConnection)
}

3. Call methods of the IOrderServiceV3_1:

var order = viewModel.order.value?.order ?: return@setPositiveButton // getting current order
val service = orderService ?: return@setPositiveButton


val getOrderStatus = ResultStatus()
order = service.getOrder(order.id, getOrderStatus).value // refresh current order

var newOrder = Order()

val createOrderStatus = ResultStatus()
newOrder = service.createOrder(OrderFdParcelable(newOrder), createOrderStatus).value

val createLineItemsFromStatus = ResultStatus()
service.createLineItemsFrom(order.id, newOrder.id, selectedLineItems.map { it.id }, createLineItemsFromStatus

println("createLineItemsFromStatus: $createLineItemsFromStatus")

but still getting Attempt to invoke virtual method 'java.util.List com.clover.common2.clover.Clover.getUserOrderTypes()' on a null object reference NPE:

2024-09-25 14:27:25.272  6738-6738  AndroidRuntime          dev.summerhammer.cloverxtestapp      E  FATAL EXCEPTION: main
                                                                                                    Process: dev.summerhammer.cloverxtestapp, PID: 6738
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.clover.common2.clover.Clover.getUserOrderTypes()' on a null object reference
                                                                                                    at android.os.Parcel.createException(Parcel.java:2078)
                                                                                                    at android.os.Parcel.readException(Parcel.java:2040)
                                                                                                    at android.os.Parcel.readException(Parcel.java:1988)
                                                                                                    at com.clover.sdk.v3.order.IOrderServiceV3_1$Stub$Proxy.createLineItemsFrom(IOrderServiceV3_1.java:3868)
                                                                                                    at dev.summerhammer.cloverxtestapp.app.modules.test.presentation.activity.TestMerchantActivity.onCreate$lambda$9$lambda$7(TestMerchantActivity.kt:148)
                                                                                                    at dev.summerhammer.cloverxtestapp.app.modules.test.presentation.activity.TestMerchantActivity.$r8$lambda$-aADvSK0OoM9JQ-la25_PmAVyg4(Unknown Source:0)
                                                                                                    at dev.summerhammer.cloverxtestapp.app.modules.test.presentation.activity.TestMerchantActivity$$ExternalSyntheticLambda1.onClick(D8$$SyntheticClass:0)
                                                                                                    at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
                                                                                                    at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                    at android.os.Looper.loop(Looper.java:214)
                                                                                                    at android.app.ActivityThread.main(ActivityThread.java:7415)
                                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497)
                                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)

Thanks

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

g58211702 avatar image
g58211702 answered g58211702 edited

The OrderV31Connector.createLineItemsFrom() method's usability for custom applications would typically depend on its documentation and any restrictions placed by the system or API it belongs to. If this method is part of a platform like SAP, Oracle, or another proprietary system, it may be limited to specific use cases within that platform's environment.

However, to determine whether it can be used for custom applications, you should:

  1. Check the API Documentation: Review the official documentation of OrderV31Connector to see if there are notes about restrictions, limitations, or special usage guidelines for custom applications.

  2. API Licensing & Access: Ensure that the API’s terms of service allow for its integration into custom projects or external apps. Some methods might only be available for internal or licensed users.

  3. Test the Integration: If you have access to the method and can test it within your development environment, try using it within a small custom app to verify its behavior and compatibility.

If you need further guidance, checking with the support team of the platform or system hosting this connector might also be a good step. More information on couples counselling Dublin

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

nikki avatar image
nikki answered

URL Your insights are always valuable. Keep them coming!

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community